// SPDX-License-Identifier: GPL-2.0-only/* * Audio and Music Data Transmission Protocol (IEC 61883-6) streams * with Common Isochronous Packet (IEC 61883-1) headers * * Copyright (c) Clemens Ladisch <clemens@ladisch.de> */#include<linux/device.h>#include<linux/err.h>#include<linux/firewire.h>#include<linux/firewire-constants.h>#include<linux/module.h>#include<linux/slab.h>#include<sound/pcm.h>#include<sound/pcm_params.h>#include"amdtp-stream.h"#define TICKS_PER_CYCLE 3072#define CYCLES_PER_SECOND 8000#define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND)/* Always support Linux tracing subsystem. */#define CREATE_TRACE_POINTS#include"amdtp-stream-trace.h"#define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 microseconds *//* isochronous header parameters */#define ISO_DATA_LENGTH_SHIFT 16#define TAG_NO_CIP_HEADER 0#define TAG_CIP 1/* common isochronous packet header parameters */#define CIP_EOH_SHIFT 31#define CIP_EOH (1u << CIP_EOH_SHIFT)#define CIP_EOH_MASK 0x80000000#define CIP_SID_SHIFT 24#define CIP_SID_MASK 0x3f000000#define CIP_DBS_MASK 0x00ff0000#define CIP_DBS_SHIFT 16#define CIP_SPH_MASK 0x00000400#define CIP_SPH_SHIFT 10#define CIP_DBC_MASK 0x000000ff#define CIP_FMT_SHIFT 24#define CIP_FMT_MASK 0x3f000000#define CIP_FDF_MASK 0x00ff0000#define CIP_FDF_SHIFT 16#define CIP_SYT_MASK 0x0000ffff#define CIP_SYT_NO_INFO 0xffff/* Audio and Music transfer protocol specific parameters */#define CIP_FMT_AM 0x10#define AMDTP_FDF_NO_DATA 0xff// For iso header, tstamp and 2 CIP header.#define IR_CTX_HEADER_SIZE_CIP 16// For iso header and tstamp.#define IR_CTX_HEADER_SIZE_NO_CIP 8#define HEADER_TSTAMP_MASK 0x0000ffff#define IT_PKT_HEADER_SIZE_CIP 8 // For 2 CIP header.#define IT_PKT_HEADER_SIZE_NO_CIP 0 // Nothing.staticvoidpcm_period_tasklet(unsignedlongdata);/** * amdtp_stream_init - initialize an AMDTP stream structure * @s: the AMDTP stream to initialize * @unit: the target of the stream * @dir: the direction of stream * @flags: the packet transmission method to use * @fmt: the value of fmt field in CIP header * @process_ctx_payloads: callback handler to process payloads of isoc context * @protocol_size: the size to allocate newly for protocol */intamdtp_stream_init(structamdtp_stream*s,structfw_unit*unit,enumamdtp_stream_directiondir,enumcip_flagsflags