Lines Matching refs:v_iter
142 static inline void inc_buf_pos(struct pcmtst_buf_iter *v_iter, size_t by, size_t bytes)
144 v_iter->total_bytes += by;
145 v_iter->buf_pos += by;
146 if (v_iter->buf_pos >= bytes)
147 v_iter->buf_pos %= bytes;
155 static inline size_t buf_pos_n(struct pcmtst_buf_iter *v_iter, unsigned int channels,
158 return v_iter->buf_pos / channels + v_iter->chan_block * chan_num;
171 static void check_buf_block_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
177 for (i = 0; i < v_iter->b_rw; i++) {
178 current_byte = runtime->dma_area[v_iter->buf_pos];
181 ch_num = (v_iter->total_bytes / v_iter->sample_bytes) % runtime->channels;
182 if (current_byte != patt_bufs[ch_num].buf[ch_pos_i(v_iter->total_bytes,
184 v_iter->sample_bytes)
186 v_iter->is_buf_corrupted = true;
189 inc_buf_pos(v_iter, 1, runtime->dma_bytes);
192 inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes);
195 static void check_buf_block_ni(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
202 for (i = 0; i < v_iter->b_rw; i++) {
204 current_byte = runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)];
207 if (current_byte != patt_bufs[ch_num].buf[(v_iter->total_bytes / channels)
209 v_iter->is_buf_corrupted = true;
212 inc_buf_pos(v_iter, 1, runtime->dma_bytes);
214 inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes);
222 static void check_buf_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
224 if (v_iter->interleaved)
225 check_buf_block_i(v_iter, runtime);
227 check_buf_block_ni(v_iter, runtime);
238 static void fill_block_pattern_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
244 for (i = 0; i < v_iter->b_rw; i++) {
246 runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)] =
247 patt_bufs[ch_num].buf[(v_iter->total_bytes / channels)
249 inc_buf_pos(v_iter, 1, runtime->dma_bytes);
254 static void fill_block_pattern_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
260 pos_in_ch = ch_pos_i(v_iter->total_bytes, runtime->channels, v_iter->sample_bytes);
262 for (sample = 0; sample < v_iter->s_rw_ch; sample++) {
264 for (pos_sample = 0; pos_sample < v_iter->sample_bytes; pos_sample++) {
265 pos_pattern = (pos_in_ch + sample * v_iter->sample_bytes
267 runtime->dma_area[v_iter->buf_pos] = patt_bufs[ch].buf[pos_pattern];
268 inc_buf_pos(v_iter, 1, runtime->dma_bytes);
274 static void fill_block_pattern(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
276 if (v_iter->interleaved)
277 fill_block_pattern_i(v_iter, runtime);
279 fill_block_pattern_n(v_iter, runtime);
282 static void fill_block_rand_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
286 size_t bytes_remain = runtime->dma_bytes - v_iter->buf_pos;
290 if (v_iter->b_rw <= bytes_remain) {
292 get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i),
293 v_iter->b_rw / channels);
296 get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i),
298 get_random_bytes(runtime->dma_area + v_iter->chan_block * i,
299 (v_iter->b_rw - bytes_remain) / channels);
302 inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes);
305 static void fill_block_rand_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
307 size_t in_cur_block = runtime->dma_bytes - v_iter->buf_pos;
309 if (v_iter->b_rw <= in_cur_block) {
310 get_random_bytes(&runtime->dma_area[v_iter->buf_pos], v_iter->b_rw);
312 get_random_bytes(&runtime->dma_area[v_iter->buf_pos], in_cur_block);
313 get_random_bytes(runtime->dma_area, v_iter->b_rw - in_cur_block);
315 inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes);
318 static void fill_block_random(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
320 if (v_iter->interleaved)
321 fill_block_rand_i(v_iter, runtime);
323 fill_block_rand_n(v_iter, runtime);
326 static void fill_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime)
330 fill_block_random(v_iter, runtime);
333 fill_block_pattern(v_iter, runtime);
345 struct pcmtst_buf_iter *v_iter;
348 v_iter = from_timer(v_iter, data, timer_instance);
349 substream = v_iter->substream;
351 if (v_iter->suspend)
354 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !v_iter->is_buf_corrupted)
355 check_buf_block(v_iter, substream->runtime);
357 fill_block(v_iter, substream->runtime);
359 inc_buf_pos(v_iter, v_iter->b_rw, substream->runtime->dma_bytes);
361 v_iter->period_pos += v_iter->b_rw;
362 if (v_iter->period_pos >= v_iter->period_bytes) {
363 v_iter->period_pos %= v_iter->period_bytes;
367 if (!v_iter->suspend)
368 mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL + inject_delay);
374 struct pcmtst_buf_iter *v_iter;
379 v_iter = kzalloc(sizeof(*v_iter), GFP_KERNEL);
380 if (!v_iter)
383 v_iter->substream = substream;
385 runtime->private_data = v_iter;
390 timer_setup(&v_iter->timer_instance, timer_timeout, 0);
397 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
399 timer_shutdown_sync(&v_iter->timer_instance);
400 playback_capture_test = !v_iter->is_buf_corrupted;
401 kfree(v_iter);
405 static inline void reset_buf_iterator(struct pcmtst_buf_iter *v_iter)
407 v_iter->buf_pos = 0;
408 v_iter->is_buf_corrupted = false;
409 v_iter->period_pos = 0;
410 v_iter->total_bytes = 0;
413 static inline void start_pcmtest_timer(struct pcmtst_buf_iter *v_iter)
415 v_iter->suspend = false;
416 mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL);
421 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
427 reset_buf_iterator(v_iter);
428 start_pcmtest_timer(v_iter);
431 start_pcmtest_timer(v_iter);
436 v_iter->suspend = true;
437 timer_delete(&v_iter->timer_instance);
446 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
448 return bytes_to_frames(substream->runtime, v_iter->buf_pos);
472 struct pcmtst_buf_iter *v_iter = runtime->private_data;
477 v_iter->sample_bytes = samples_to_bytes(runtime, 1);
478 v_iter->period_bytes = snd_pcm_lib_period_bytes(substream);
479 v_iter->interleaved = true;
482 v_iter->chan_block = snd_pcm_lib_buffer_bytes(substream) / runtime->channels;
483 v_iter->interleaved = false;
486 v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC;
487 v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels;
517 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
519 timer_delete_sync(&v_iter->timer_instance);