summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c')
-rw-r--r--cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c255
1 files changed, 233 insertions, 22 deletions
diff --git a/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c b/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c
index 3fb731e0ff..22c9b6fa75 100644
--- a/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c
+++ b/cesar/hal/phy/test/bridgedma-proto/src/bridgedma-crc-test.c
@@ -34,16 +34,48 @@
#define START_OFFSET 128
+
cyg_thread my_test_thread;
cyg_handle_t my_test_thread_handle;
u8 my_test_thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
-phy_bridgedma_t *bridgedma_ctx;
+pb_t *my_pb_first;
+pb_t *my_pb_last;
+phy_bridgedma_job_t *job_current;
+
phy_bridgedma_job_t job1;
+phy_bridgedma_t *bridgedma_ctx;
+u8 frame_buffer [2048] __attribute__((aligned(2048)));
+crc_t crc_ctx;
+blk_t *pb_first, *pb_last, *pb_current;
+u32 mf_header;
+u32 enc_tab[256];
+uint ats;
/* WARNING: callback are not possible to test inside UNIT TEST */
-bool _bridgedma_cb(void *data, u32 status)
+bool _bridgedma_segmentation_cb(void *data, u32 status)
{
+ // If no more jobs to process by the bridgedma wake up the test thread to
+ // continue
+ if (!job_current)
+ {
+ cyg_thread_resume (my_test_thread_handle);
+ }
+
+ if (job_current)
+ {
+ diag_printf ("----- Bridge Cb ----\n");
+ diag_printf ("SSN : %d\n",
+ ((pb_t*)job_current->first_pb_desc)->header.ssn);
+ diag_printf ("offset : %d\n", job_current->first_pb_offset);
+ diag_printf ("length : %d\n", read_u16_from_word
+ (((pb_t *)job_current->first_pb_desc)->data +
+ job_current->first_pb_offset) >> 2);
+ diag_printf ("---- END Bridge Cb ----\n");
+ }
+
+ job_current = job_current->next;
+ return true;
}
/* WARNING: callback are not possible to test inside UNIT TEST */
@@ -60,14 +92,14 @@ void bridgedma_init_test_case(test_t t)
test_begin(t, "init")
{
bridgedma_ctx = NULL;
- bridgedma_ctx = phy_bridgedma_init(&user_data, _bridgedma_cb, _bridgedma_deffered_cb);
+ bridgedma_ctx = phy_bridgedma_init(&user_data, _bridgedma_segmentation_cb, _bridgedma_deffered_cb);
test_fail_unless(
(bridgedma_ctx != NULL)
&& (bridgedma_ctx->job_first == NULL)
&& (bridgedma_ctx->job_current == NULL)
&& (bridgedma_ctx->job_last == NULL)
&& (bridgedma_ctx->user_data == &user_data)
- && (bridgedma_ctx->bridgedma_cb == _bridgedma_cb)
+ && (bridgedma_ctx->bridgedma_cb == _bridgedma_segmentation_cb)
&& (bridgedma_ctx->deferred_cb == _bridgedma_deffered_cb)
&& !bridgedma_ctx->status.running
&& bridgedma_ctx->status.stop
@@ -76,27 +108,40 @@ void bridgedma_init_test_case(test_t t)
return;
}
-void
-bridgedma_crc_test_case (test_t test)
+void bridgedma_segmentation_test_case(test_t t)
{
- crc_t crc_ctx;
- unsigned long crc_current;
+ uint i;
+ pb_t *my_current;
+ dbg_assert (bridgedma_ctx);
+ test_case_begin(t, "segmentation");
- crc_ctx.width = 32;
- crc_ctx.generator = HPAV_CRC32_GENERATOR;
- crc_ctx.init = HPAV_CRC32_INIT;
- crc_ctx.refin = true;
- crc_ctx.refout = true;
- crc_ctx.xorout = 0xffffffff;
- crc_ctx.reg_init = 0;
- crc_ctx.table.t32 = enc_tab;
- crc_init(&crc_ctx);
+ pb_first = blk_alloc_desc_range(4, &pb_last);
+ pb_last->next = NULL;
+
+ my_pb_first = (pb_t *) pb_first;
+ my_pb_last = (pb_t *)pb_last;
+
+ my_current = my_pb_first;
+ for (i = 0; i < 4; i++)
+ {
+ my_current->header.ssn = i;
+ my_current = my_current->next;
+ }
+
+ ats = 0x12345678;
+ /************************************************************************
+ * simple segmentation with 3 mac frames into 5 PBs
+ * 1st mac frame: len=1518, offset=128, ATS, ICV into 1st to 4th PB
+ * 2nd mac frame: len=64, ATS, ICV into 4th PB
+ * 3nd mac frame: len=466, ATS, ICV, padding into 4th to 5th PB
+ ***********************************************************************/
+
memset(&job1, '\0', sizeof(job1));
job1.next = NULL;
job1.data_addr = frame_buffer;
job1.header_len = 6;
- job1.data_len = MAC_FRAME_MAX_LEN;
+ job1.data_len = ETH_PACKET_MAX_SIZE;
job1.first_pb_desc = pb_first;
job1.first_pb_offset = START_OFFSET;
job1.segment_len = 512;
@@ -105,11 +150,166 @@ bridgedma_crc_test_case (test_t test)
job1.crc_store = 1;
job1.job_it = 1;
job1.eth_buffer_mask = 0x1fffff0; /* 2048 bytes mask */
- job1.mf_header1 = (((job1.data_len + 4 - 1) << 2) | 0x02);
- job1.mf_header2 = 0x0;
+ job1.mf_header1 = (((job1.data_len + 4 - 1) << 2) | 0x02) | (ats << 16); /* Payload + ATS */
+ job1.mf_header2 = (ats >> 16);
+
+ job_current = &job1;
+ phy_bridgedma_start (bridgedma_ctx, &job1, &job1);
+ return;
+}
- phy_bridgedma_start(bridgedma_ctx, &job1, &job1);
+void
+bridgedma_segmentation_crc_verify_test_case (test_t test)
+{
+ uint payload_cnt;
+ uint crc_current;
+ pb_t *my_pb_current;
+
+ uint i;
+ uint length;
+ uint pb_offset;
+ uint qte_pb;
+ uint frame_offset;
+ bool cont;
+
+ crc_ctx.width = 32;
+ crc_ctx.generator = HPAV_CRC32_GENERATOR;
+ crc_ctx.init = HPAV_CRC32_INIT;
+ crc_ctx.refin = true;
+ crc_ctx.refout = true;
+ crc_ctx.xorout = 0xffffffff;
+ crc_ctx.reg_init = 0;
+ crc_ctx.table.t32 = enc_tab;
+ crc_init(&crc_ctx);
+
+ test_begin(test, "segmentation of 1 frames")
+ {
+ for (i = 0, my_pb_current = my_pb_first; my_pb_current; my_pb_current =
+ my_pb_current->next, i++)
+ {
+ test_fail_if (my_pb_current->header.ssn != i, "Wong sequence");
+ }
+
+ /* check pb content */
+ /* check 1st mac frame into PB */
+ payload_cnt = 0;
+
+ pb_offset = START_OFFSET;
+ job_current = &job1;
+ frame_offset = 0;
+ pb_current = pb_first;
+
+ cont = true;
+ length = 1 + (read_u16_from_word (pb_current->data + pb_offset) >> 2);
+
+ // To get the payload length, the frame length is 10
+ // bytes greater.
+ length -= 4;
+
+ diag_printf ("Length read in pb : %d\n", length);
+ diag_printf ("pb ssn : %d\n", ((pb_t *)pb_current)->header.ssn);
+ diag_printf ("pb offset : %d\n", pb_offset);
+ test_fail_unless (length == job_current->data_len,
+ "Data length is wrong.");
+
+ // Copy the data of the current pb.
+
+ // Jump directly to the start of the payload.
+ pb_offset += 6;
+ crc_current = crc_compute_begin(&crc_ctx);
+ if (length + pb_offset > BLK_SIZE)
+ {
+ test_fail_unless (
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data + pb_offset,
+ BLK_SIZE - pb_offset),
+ "data corrupted");
+ frame_offset += BLK_SIZE - pb_offset;
+ length -= BLK_SIZE - pb_offset;
+ }
+ else
+ {
+ test_fail_unless (
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data + pb_offset,
+ length),
+ "data corrupted");
+ frame_offset += length;
+ cont = false;
+ }
+
+
+ if (cont)
+ {
+ // Add 10 to the length to use the complete MF length
+ // (ATS + MFH + ICV), the ATS and MFH are already include in the
+ // pb_offset.
+ for (qte_pb = (pb_offset + length + 4) / BLK_SIZE + 1;
+ qte_pb;
+ qte_pb --)
+ {
+ pb_current = pb_current->next;
+
+ if (length > BLK_SIZE)
+ {
+ test_fail_unless(
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data ,
+ BLK_SIZE),
+ "data corrupted");
+ length -= BLK_SIZE;
+ frame_offset += BLK_SIZE;
+ }
+ else
+ {
+ test_fail_unless(
+ bitstream_memcmp (frame_buffer + frame_offset,
+ pb_current->data ,
+ length),
+ "data corrupted");
+ frame_offset += length;
+ }
+ }
+ }
+
+ // The future offset is length + 4 cause of the ICV of the MF.
+ // The ATS and the MFH has already been jumped above in the
+ // pb_offset.
+ pb_offset = (pb_offset + job_current->data_len + 4) % BLK_SIZE;
+ } test_end;
+
+ test_begin (test, "Verify CRC")
+ {
+ uint mf_length;
+ uint offset;
+ uint crc_pb;
+ uint i;
+ u8 buffer_reconstitute [2048] __attribute__((aligned(2048)));
+
+ mf_length = (read_u16_from_word((u8 *) &job1.mf_header1)>> 2) + 3;
+ offset = (job1.first_pb_offset + mf_length) % BLK_SIZE;
+
+ crc_pb = read_u32_from_word (my_pb_last->data + offset);
+
+ for (i = 0; i < 6; i++)
+ buffer_reconstitute [i] = my_pb_first->data[130+i];
+ bitstream_memcpy (buffer_reconstitute + 4, frame_buffer,
+ ETH_PACKET_MAX_SIZE);
+
+ crc_current = bridgedma_crc_compute_block (&crc_ctx, buffer_reconstitute,
+ ETH_PACKET_MAX_SIZE + 4);
+
+ diag_printf ("Data length = %d\n", mf_length);
+ diag_printf ("ICV pos = %d\n", offset);
+
+ diag_printf ("CRC pb = %x\n", crc_pb);
+ diag_printf ("CRC frame = %x\n", crc_current);
+ test_fail_if (crc_current != crc_pb, "Wrong CRC computed");
+ }
+ test_end;
+
+ blk_release_desc_range((blk_t *)my_pb_first, (blk_t *) my_pb_last);
}
void
@@ -120,7 +320,8 @@ test_thread_process (cyg_addrword_t data)
test = (test_t *) data;
bridgedma_init_test_case (*test);
- bridgedma_crc_test_case (*test);
+ bridgedma_segmentation_test_case (*test);
+ bridgedma_segmentation_crc_verify_test_case (*test);
phy_bridgedma_uninit (bridgedma_ctx);
@@ -135,9 +336,19 @@ int
main (void)
{
test_t test;
+ uint i;
test_init (test, 0, NULL);
+ pb_first = NULL;
+ pb_last = NULL;
+
+ my_pb_first = NULL;
+ my_pb_last = NULL;
+
+ for (i = 0; i < 2048; i++)
+ frame_buffer[i] = i;
+
// Create the thread.
cyg_thread_create( 9,
&test_thread_process,