@@ -98,20 +98,6 @@ enum dmatest_error_type {
9898 DMATEST_ET_DMA_ERROR ,
9999 DMATEST_ET_DMA_IN_PROGRESS ,
100100 DMATEST_ET_VERIFY ,
101- DMATEST_ET_VERIFY_BUF ,
102- };
103-
104- struct dmatest_verify_buffer {
105- unsigned int index ;
106- u8 expected ;
107- u8 actual ;
108- };
109-
110- struct dmatest_verify_result {
111- unsigned int error_count ;
112- struct dmatest_verify_buffer data [MAX_ERROR_COUNT ];
113- u8 pattern ;
114- bool is_srcbuf ;
115101};
116102
117103struct dmatest_thread_result {
@@ -122,11 +108,10 @@ struct dmatest_thread_result {
122108 unsigned int len ;
123109 enum dmatest_error_type type ;
124110 union {
125- unsigned long data ;
126- dma_cookie_t cookie ;
127- enum dma_status status ;
128- int error ;
129- struct dmatest_verify_result * vr ;
111+ unsigned long data ;
112+ dma_cookie_t cookie ;
113+ enum dma_status status ;
114+ int error ;
130115 };
131116};
132117
@@ -262,38 +247,56 @@ static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len,
262247 }
263248}
264249
265- static unsigned int dmatest_verify (struct dmatest_verify_result * vr , u8 * * bufs ,
266- unsigned int start , unsigned int end , unsigned int counter ,
267- u8 pattern , bool is_srcbuf )
250+ static void dmatest_mismatch (u8 actual , u8 pattern , unsigned int index ,
251+ unsigned int counter , bool is_srcbuf )
252+ {
253+ u8 diff = actual ^ pattern ;
254+ u8 expected = pattern | (~counter & PATTERN_COUNT_MASK );
255+ const char * thread_name = current -> comm ;
256+
257+ if (is_srcbuf )
258+ pr_warn ("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n" ,
259+ thread_name , index , expected , actual );
260+ else if ((pattern & PATTERN_COPY )
261+ && (diff & (PATTERN_COPY | PATTERN_OVERWRITE )))
262+ pr_warn ("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n" ,
263+ thread_name , index , expected , actual );
264+ else if (diff & PATTERN_SRC )
265+ pr_warn ("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n" ,
266+ thread_name , index , expected , actual );
267+ else
268+ pr_warn ("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n" ,
269+ thread_name , index , expected , actual );
270+ }
271+
272+ static unsigned int dmatest_verify (u8 * * bufs , unsigned int start ,
273+ unsigned int end , unsigned int counter , u8 pattern ,
274+ bool is_srcbuf )
268275{
269276 unsigned int i ;
270277 unsigned int error_count = 0 ;
271278 u8 actual ;
272279 u8 expected ;
273280 u8 * buf ;
274281 unsigned int counter_orig = counter ;
275- struct dmatest_verify_buffer * vb ;
276282
277283 for (; (buf = * bufs ); bufs ++ ) {
278284 counter = counter_orig ;
279285 for (i = start ; i < end ; i ++ ) {
280286 actual = buf [i ];
281287 expected = pattern | (~counter & PATTERN_COUNT_MASK );
282288 if (actual != expected ) {
283- if (error_count < MAX_ERROR_COUNT && vr ) {
284- vb = & vr -> data [error_count ];
285- vb -> index = i ;
286- vb -> expected = expected ;
287- vb -> actual = actual ;
288- }
289+ if (error_count < MAX_ERROR_COUNT )
290+ dmatest_mismatch (actual , pattern , i ,
291+ counter , is_srcbuf );
289292 error_count ++ ;
290293 }
291294 counter ++ ;
292295 }
293296 }
294297
295298 if (error_count > MAX_ERROR_COUNT )
296- pr_warning ("%s: %u errors suppressed\n" ,
299+ pr_warn ("%s: %u errors suppressed\n" ,
297300 current -> comm , error_count - MAX_ERROR_COUNT );
298301
299302 return error_count ;
@@ -334,30 +337,6 @@ static unsigned int min_odd(unsigned int x, unsigned int y)
334337 return val % 2 ? val : val - 1 ;
335338}
336339
337- static char * verify_result_get_one (struct dmatest_verify_result * vr ,
338- unsigned int i )
339- {
340- struct dmatest_verify_buffer * vb = & vr -> data [i ];
341- u8 diff = vb -> actual ^ vr -> pattern ;
342- static char buf [512 ];
343- char * msg ;
344-
345- if (vr -> is_srcbuf )
346- msg = "srcbuf overwritten!" ;
347- else if ((vr -> pattern & PATTERN_COPY )
348- && (diff & (PATTERN_COPY | PATTERN_OVERWRITE )))
349- msg = "dstbuf not copied!" ;
350- else if (diff & PATTERN_SRC )
351- msg = "dstbuf was copied!" ;
352- else
353- msg = "dstbuf mismatch!" ;
354-
355- snprintf (buf , sizeof (buf ) - 1 , "%s [0x%x] Expected %02x, got %02x" , msg ,
356- vb -> index , vb -> expected , vb -> actual );
357-
358- return buf ;
359- }
360-
361340static char * thread_result_get (const char * name ,
362341 struct dmatest_thread_result * tr )
363342{
@@ -373,7 +352,6 @@ static char *thread_result_get(const char *name,
373352 [DMATEST_ET_DMA_IN_PROGRESS ] =
374353 "got completion callback (DMA_IN_PROGRESS)" ,
375354 [DMATEST_ET_VERIFY ] = "errors" ,
376- [DMATEST_ET_VERIFY_BUF ] = "verify errors" ,
377355 };
378356 static char buf [512 ];
379357
@@ -415,51 +393,6 @@ static int thread_result_add(struct dmatest_info *info,
415393 return 0 ;
416394}
417395
418- static unsigned int verify_result_add (struct dmatest_info * info ,
419- struct dmatest_result * r , unsigned int n ,
420- unsigned int src_off , unsigned int dst_off , unsigned int len ,
421- u8 * * bufs , int whence , unsigned int counter , u8 pattern ,
422- bool is_srcbuf )
423- {
424- struct dmatest_verify_result * vr ;
425- unsigned int error_count ;
426- unsigned int buf_off = is_srcbuf ? src_off : dst_off ;
427- unsigned int start , end ;
428-
429- if (whence < 0 ) {
430- start = 0 ;
431- end = buf_off ;
432- } else if (whence > 0 ) {
433- start = buf_off + len ;
434- end = info -> params .buf_size ;
435- } else {
436- start = buf_off ;
437- end = buf_off + len ;
438- }
439-
440- vr = kmalloc (sizeof (* vr ), GFP_KERNEL );
441- if (!vr ) {
442- pr_warn ("dmatest: No memory to store verify result\n" );
443- return dmatest_verify (NULL , bufs , start , end , counter , pattern ,
444- is_srcbuf );
445- }
446-
447- vr -> pattern = pattern ;
448- vr -> is_srcbuf = is_srcbuf ;
449-
450- error_count = dmatest_verify (vr , bufs , start , end , counter , pattern ,
451- is_srcbuf );
452- if (error_count ) {
453- vr -> error_count = error_count ;
454- thread_result_add (info , r , DMATEST_ET_VERIFY_BUF , n , src_off ,
455- dst_off , len , (unsigned long )vr );
456- return error_count ;
457- }
458-
459- kfree (vr );
460- return 0 ;
461- }
462-
463396static void result_free (struct dmatest_info * info , const char * name )
464397{
465398 struct dmatest_result * r , * _r ;
@@ -472,8 +405,6 @@ static void result_free(struct dmatest_info *info, const char *name)
472405 continue ;
473406
474407 list_for_each_entry_safe (tr , _tr , & r -> results , node ) {
475- if (tr -> type == DMATEST_ET_VERIFY_BUF )
476- kfree (tr -> vr );
477408 list_del (& tr -> node );
478409 kfree (tr );
479410 }
@@ -755,26 +686,25 @@ static int dmatest_func(void *data)
755686 error_count = 0 ;
756687
757688 pr_debug ("%s: verifying source buffer...\n" , thread_name );
758- error_count += verify_result_add (info , result , total_tests ,
759- src_off , dst_off , len , thread -> srcs , -1 ,
689+ error_count += dmatest_verify (thread -> srcs , 0 , src_off ,
760690 0 , PATTERN_SRC , true);
761- error_count += verify_result_add ( info , result , total_tests ,
762- src_off , dst_off , len , thread -> srcs , 0 ,
763- src_off , PATTERN_SRC | PATTERN_COPY , true);
764- error_count += verify_result_add ( info , result , total_tests ,
765- src_off , dst_off , len , thread -> srcs , 1 ,
766- src_off + len , PATTERN_SRC , true);
767-
768- pr_debug ("%s: verifying dest buffer...\n" , thread_name );
769- error_count += verify_result_add ( info , result , total_tests ,
770- src_off , dst_off , len , thread -> dsts , -1 ,
691+ error_count += dmatest_verify ( thread -> srcs , src_off ,
692+ src_off + len , src_off ,
693+ PATTERN_SRC | PATTERN_COPY , true);
694+ error_count += dmatest_verify ( thread -> srcs , src_off + len ,
695+ params -> buf_size , src_off + len ,
696+ PATTERN_SRC , true);
697+
698+ pr_debug ("%s: verifying dest buffer...\n" ,
699+ thread -> task -> comm );
700+ error_count += dmatest_verify ( thread -> dsts , 0 , dst_off ,
771701 0 , PATTERN_DST , false);
772- error_count += verify_result_add ( info , result , total_tests ,
773- src_off , dst_off , len , thread -> dsts , 0 ,
774- src_off , PATTERN_SRC | PATTERN_COPY , false);
775- error_count += verify_result_add ( info , result , total_tests ,
776- src_off , dst_off , len , thread -> dsts , 1 ,
777- dst_off + len , PATTERN_DST , false);
702+ error_count += dmatest_verify ( thread -> dsts , dst_off ,
703+ dst_off + len , src_off ,
704+ PATTERN_SRC | PATTERN_COPY , false);
705+ error_count += dmatest_verify ( thread -> dsts , dst_off + len ,
706+ params -> buf_size , dst_off + len ,
707+ PATTERN_DST , false);
778708
779709 if (error_count ) {
780710 thread_result_add (info , result , DMATEST_ET_VERIFY ,
@@ -1099,20 +1029,12 @@ static int dtf_results_show(struct seq_file *sf, void *data)
10991029 struct dmatest_info * info = sf -> private ;
11001030 struct dmatest_result * result ;
11011031 struct dmatest_thread_result * tr ;
1102- unsigned int i ;
11031032
11041033 mutex_lock (& info -> results_lock );
11051034 list_for_each_entry (result , & info -> results , node ) {
1106- list_for_each_entry (tr , & result -> results , node ) {
1035+ list_for_each_entry (tr , & result -> results , node )
11071036 seq_printf (sf , "%s\n" ,
11081037 thread_result_get (result -> name , tr ));
1109- if (tr -> type == DMATEST_ET_VERIFY_BUF ) {
1110- for (i = 0 ; i < tr -> vr -> error_count ; i ++ ) {
1111- seq_printf (sf , "\t%s\n" ,
1112- verify_result_get_one (tr -> vr , i ));
1113- }
1114- }
1115- }
11161038 }
11171039
11181040 mutex_unlock (& info -> results_lock );
0 commit comments