summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/maximus
diff options
context:
space:
mode:
authorlaranjeiro2009-12-14 10:05:03 +0000
committerlaranjeiro2009-12-14 10:05:03 +0000
commit8297b0919aab51e07d35a46f8feda481c74502fa (patch)
tree98efbf72c2ca5659d911b990af3ba864bd797a0c /cesar/hal/phy/maximus
parent4a99648b17caa0012eb187b9681d596b9e246be2 (diff)
cesar/{hal/phy,mac/sar}: merge all bridgedma simulation code, closes #855
* remove bridgedma_soft, maximus_bridgedma. * add hal/phy/soft/bridge to use in unit test and maximus. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6543 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/hal/phy/maximus')
-rw-r--r--cesar/hal/phy/maximus/Module2
-rw-r--r--cesar/hal/phy/maximus/inc/maximus_bridgedma_ctx.h64
-rw-r--r--cesar/hal/phy/maximus/src/maximus_bridgedma.c411
3 files changed, 1 insertions, 476 deletions
diff --git a/cesar/hal/phy/maximus/Module b/cesar/hal/phy/maximus/Module
index e5f1fc8ab9..af1ef0cdb4 100644
--- a/cesar/hal/phy/maximus/Module
+++ b/cesar/hal/phy/maximus/Module
@@ -1,4 +1,4 @@
-SOURCES := maximus_phy_access.c maximus_bridgedma.c maximus_phy_ctrl.c \
+SOURCES := maximus_phy_access.c maximus_phy_ctrl.c \
maximus_phy_ctrl_cb.c maximus_pbdma.c maximus_tmdma.c \
maximus_aes.c maximus_spoc.c
MODULES := hal/phy/maximus/dur
diff --git a/cesar/hal/phy/maximus/inc/maximus_bridgedma_ctx.h b/cesar/hal/phy/maximus/inc/maximus_bridgedma_ctx.h
deleted file mode 100644
index 16cbc8b595..0000000000
--- a/cesar/hal/phy/maximus/inc/maximus_bridgedma_ctx.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef MAXIMUS_BRIDGEDMA_CTX_H_
-#define MAXIMUS_BRIDGEDMA_CTX_H_
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/phy/maximus/inc/maximus_bridgedma_ctx.h
- * \brief HAL Bridge DMA context for Maximus.
- * \ingroup hal_phy_maximus
- */
-
-#include "lib/crc.h"
-#include "hal/phy/bridgedma.h"
-#ifdef ECOS
-#include <cyg/hal/drv_api.h>
-#endif /* ECOS */
-#include "host/station/station.h"
-
-/** 1 byte is processed into 5ns, so 8 bytes per tick (40ns) */
-#define BRIDGEDMA_BYTE_PER_TICK 8
-/** max additionnal processing time is 10us, so 250 ticks */
-#define BRIDGEDMA_ADD_MAX_TICK 250
-
-#define HPAV_CRC32_GENERATOR 0x04c11db7
-#define HPAV_CRC32_INIT 0xffffffff
-#define HPAV_CRC32_MAGIC 0x2144df1c
-
-typedef enum
-{
- PB_TO_MACFRAME,
- MACFRAME_TO_PB
-} bridgedma_copy_dir_t;
-
-struct phy_bridgedma_t
-{
- phy_bridgedma_status_t status;
- //phy_bridgedma_ctrl_t control;
- phy_bridgedma_job_t *job_first;
- phy_bridgedma_job_t *job_current;
- phy_bridgedma_job_t *job_last;
- uint32_t icv_substitution;
- uint32_t icv_current;
- crc_t crc_ctx;
- void *user_data;
- phy_bridgedma_cb_t bridgedma_cb;
- phy_deferred_cb_t deferred_cb;
- station_ctx_t *station;
- netclock_callback_t netclock_cb;
-#ifdef ECOS
- cyg_interrupt interrupt;
- cyg_handle_t interrupt_handle;
-#endif /* ECOS */
-};
-
-#ifndef ECOS
-int _pb_data_add(blk_t **pb_current, unsigned char **pb_data_ptr, unsigned int pb_size,
- unsigned char *mac_ptr, unsigned int mac_len, bridgedma_copy_dir_t direction);
-#endif /* ECOS */
-
-#endif /*MAXIMUS_BRIDGEDMA_CTX_H_*/
diff --git a/cesar/hal/phy/maximus/src/maximus_bridgedma.c b/cesar/hal/phy/maximus/src/maximus_bridgedma.c
deleted file mode 100644
index 74123326f5..0000000000
--- a/cesar/hal/phy/maximus/src/maximus_bridgedma.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/phy/maximus/src/maximus_bridgedma.c
- * \brief HAL Phy Bridge DMA functions for Maximus.
- * \ingroup hal_phy_maximus
- */
-
-#include "common/std.h"
-#include "common/defs/ethernet.h"
-#include "ecos/packages/hal/maximus/arch/current/include/hal_host_intr.h"
-#include "hal/phy/maximus/inc/maximus_interrupts.h"
-#include "hal/phy/maximus/inc/maximus_phy_ctx.h"
-#include "hal/phy/maximus/inc/maximus_bridgedma_ctx.h"
-#include <stdlib.h>
-#include <errno.h>
-
-#define ETH_BUFFER_MASK(job) (~((job)->eth_buffer_mask << 7))
-#define ETH_BUFFER_SIZE(job) (ETH_BUFFER_MASK(job) + 1)
-#define ETH_BUFFER_ADDR(job) (unsigned char *)((unsigned long)job->data_addr & ~ETH_BUFFER_MASK(job))
-
-/*struct job_cb_data
-{
- phy_bridgedma_t *ctx;
- int is_it;
-};*/
-
-#ifdef ECOS
-static cyg_uint32 _bridgedma_ecos_isr(cyg_vector_t vector, cyg_addrword_t data)
-{
- /* nothing to do except calling the bridgedma callback */
- phy_bridgedma_t *bridgedma_ctx;
- bridgedma_ctx = (phy_bridgedma_t *)data;
- cyg_drv_interrupt_mask(PHY_HAL_INTERRUPT_BRIDGEDMA);
- cyg_drv_interrupt_acknowledge(PHY_HAL_INTERRUPT_BRIDGEDMA);
- if((*bridgedma_ctx->bridgedma_cb)(bridgedma_ctx->user_data, *((u32 *)((void *)&bridgedma_ctx->status))))
- return CYG_ISR_CALL_DSR; // Cause DSR to be run
- else
- {
- cyg_drv_interrupt_unmask(PHY_HAL_INTERRUPT_BRIDGEDMA);
- return CYG_ISR_HANDLED;
- }
-}
-
-static void _bridgedma_ecos_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
-{
- /* nothing to do except calling the phy dsr */
- phy_bridgedma_t *bridgedma_ctx;
- bridgedma_ctx = (phy_bridgedma_t *)data;
- (*bridgedma_ctx->deferred_cb)(bridgedma_ctx->user_data);
- cyg_drv_interrupt_unmask(PHY_HAL_INTERRUPT_BRIDGEDMA);
- return;
-}
-#endif /* ECOS */
-
-static void _job_process_cb(void *data);
-
-/**
- * Initialise the Bridge DMA.
- * \param user_data User data passed to any callback
- * \param bridgedma_cb Bridge DMA interrupt callback
- * \param deferred_cb DSR callback
- * \return the newly created context
- */
-phy_bridgedma_t *
-phy_bridgedma_init (void *user_data, phy_bridgedma_cb_t bridgedma_cb,
- phy_deferred_cb_t deferred_cb)
-{
- static phy_bridgedma_t bridgedma_ctx;
- static u32 enc_tab[256];
-
- memset(&bridgedma_ctx, '\0', sizeof(bridgedma_ctx));
- bridgedma_ctx.user_data = user_data;
- bridgedma_ctx.bridgedma_cb = bridgedma_cb;
- bridgedma_ctx.deferred_cb = deferred_cb;
- bridgedma_ctx.status.stop = 1;
- bridgedma_ctx.station = &my_station;
-
- /* init the crc context */
- bridgedma_ctx.crc_ctx.width = 32;
- bridgedma_ctx.crc_ctx.generator = HPAV_CRC32_GENERATOR;
- bridgedma_ctx.crc_ctx.init = HPAV_CRC32_INIT;
- bridgedma_ctx.crc_ctx.refin = true;
- bridgedma_ctx.crc_ctx.refout = true;
- bridgedma_ctx.crc_ctx.xorout = 0xffffffff;
- bridgedma_ctx.crc_ctx.reg_init = 0;
- bridgedma_ctx.crc_ctx.table.t32 = enc_tab;
- crc_init(&bridgedma_ctx.crc_ctx);
-
-#ifdef ECOS
- /* register ISR et DSR to eCos */
- cyg_drv_interrupt_create(PHY_HAL_INTERRUPT_BRIDGEDMA,
- PHY_HAL_INTERRUPT_PRIORITY,
- (cyg_addrword_t)&bridgedma_ctx,
- _bridgedma_ecos_isr,
- _bridgedma_ecos_dsr,
- &bridgedma_ctx.interrupt_handle,
- &bridgedma_ctx.interrupt);
- cyg_drv_interrupt_attach(bridgedma_ctx.interrupt_handle);
- cyg_drv_interrupt_unmask(PHY_HAL_INTERRUPT_BRIDGEDMA);
-#endif /* ECOS */
- return &bridgedma_ctx;
-}
-
-
-/**
- * Reset and uninitialise the Bridge DMA.
- * \param ctx Bridge DMA context
- */
-void
-phy_bridgedma_uninit (phy_bridgedma_t *ctx)
-{
-
-}
-
-/**
- * Fragment a mac_frame data into one or several PBs.
- * Mac frame data MUST NOT cross the mac frame buffer boundary (going at beginning of circular buffer)
- * ie: we must have mac_ptr + mac_len <= end_of_mac_buffer
- * \param pb_current pointer of pointer to first pb to store data
- * \param pb_data_ptr pointer of pointer to data beginning into first pb
- * \param pb_size size of pb data (128 or 512)
- * \param mac_ptr pointer to mac_frame data
- * \param mac_len length of mac frame data
- * \param direction data copy direction: MACFRAME_TO_PB or PB_TO_MACFRAME
- * \return 0
- */
-
-#ifndef UNIT_TEST
-static int
-#else /* UNIT_TEST */
-int
-#endif /* UNIT_TEST */
-_pb_data_add(
- blk_t **pb_current,
- unsigned char **pb_data_ptr,
- unsigned int pb_size,
- unsigned char *mac_ptr,
- unsigned int mac_len,
- bridgedma_copy_dir_t direction)
-{
- unsigned int mac_cnt;
-
- mac_cnt = 0;
-
- while((mac_len - mac_cnt) > pb_size - (*pb_data_ptr - (*pb_current)->data))
- {
- if(direction == MACFRAME_TO_PB)
- memcpy(*pb_data_ptr, mac_ptr + mac_cnt, pb_size - (*pb_data_ptr - (*pb_current)->data));
- else
- memcpy(mac_ptr + mac_cnt, *pb_data_ptr, pb_size - (*pb_data_ptr - (*pb_current)->data));
- mac_cnt += pb_size - (*pb_data_ptr - (*pb_current)->data);
- *pb_current = (*pb_current)->next;
- dbg_assert(*pb_current);
- *pb_data_ptr = (*pb_current)->data;
- }
-
- if(direction == MACFRAME_TO_PB)
- memcpy(*pb_data_ptr, mac_ptr + mac_cnt, mac_len - mac_cnt);
- else
- memcpy(mac_ptr + mac_cnt, *pb_data_ptr, mac_len - mac_cnt);
- *pb_data_ptr += mac_len - mac_cnt;
- return 0;
-}
-
-/**
- * Process 1 job for fragmentation or reassembly
- * \param ctx Bridge DMA context
- * \param job job to process
- * \return 0
- * */
-static int
-_job_process(phy_bridgedma_t *ctx, phy_bridgedma_job_t *job)
-{
- unsigned char * mac_ptr, *data_ptr;
- blk_t *pb_current;
- unsigned long icv_final, icv_compare;
-
- ctx->job_current = job;
-
- dbg_assert(job->data_addr);
- dbg_assert((job->header_len == 0) || (job->header_len == 2) || (job->header_len == 6));
- dbg_assert(job->data_len <= ETH_PACKET_MAX_SIZE);
- dbg_assert(job->first_pb_desc);
- dbg_assert(job->first_pb_offset < job->segment_len);
- dbg_assert((job->segment_len == 128) || (job->segment_len == 512));
-
- /* check icv reset */
- if(job->crc_reset)
- ctx->icv_current = crc_compute_begin(&ctx->crc_ctx);
-
- pb_current = job->first_pb_desc;
- data_ptr = pb_current->data + job->first_pb_offset;
- mac_ptr = job->data_addr;
-
- if(job->direction == 0)
- {
- /* segmentation processing */
-
- if(job->header_len > 0)
- {
- /* add header */
- _pb_data_add(&pb_current,
- &data_ptr,
- job->segment_len,
- (unsigned char *)&job->mf_header1, /* little endian !!! */
- 2,
- MACFRAME_TO_PB); /* we are in little endian for simulator... */
- if(job->header_len == 6)
- {
- /* add ATS */
- _pb_data_add(&pb_current,
- &data_ptr,
- job->segment_len,
- ((unsigned char *)&job->mf_header1) + 2, /* little endian !!! */
- 4,
- MACFRAME_TO_PB); /* we are in little endian for simulator... */
- if(!job->crc_error)
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, ((unsigned char *)&job->mf_header1) + 2, 4);
- }
- }
-
- /* check if mac data must be separated into 2 parts (circular buffer rollover) */
- if((job->eth_buffer_mask != 0)
- && (job->data_addr + job->data_len >= ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job)))
- {
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, job->data_addr, ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job) - job->data_addr, MACFRAME_TO_PB);
- if(!job->crc_error)
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, job->data_addr, ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job) - job->data_addr);
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, job->data_addr, ((unsigned long)(job->data_addr) + job->data_len) & ETH_BUFFER_MASK(job), MACFRAME_TO_PB);
- if(!job->crc_error)
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, job->data_addr, ((unsigned long)(job->data_addr) + job->data_len) & ETH_BUFFER_MASK(job));
- }
- else
- {
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, job->data_addr, job->data_len, MACFRAME_TO_PB);
- if(!job->crc_error)
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, job->data_addr, job->data_len);
- }
- if(job->crc_store)
- {
- /* add crc */
- if(!job->crc_error)
- icv_final = crc_compute_end(&ctx->crc_ctx, ctx->icv_current);
- else
- icv_final = ctx->icv_substitution;
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, (unsigned char *)&icv_final, 4, MACFRAME_TO_PB); /* we are in little endian for simulator... */
- }
- if(job->append_zero)
- {
- /* add zeroed padding */
- memset(data_ptr, '\0', job->segment_len - (data_ptr - pb_current->data));
- }
- }
- else /* job->direction != 0 */
- {
- /* reassembly processing */
- if(job->header_len > 0)
- {
- /* get the mac frame header */
- _pb_data_add(&pb_current,
- &data_ptr,
- job->segment_len,
- (unsigned char *)&job->mf_header1, /* little endian !!! */
- 2,
- PB_TO_MACFRAME); /* we are in little endian for simulator... */
- if(job->header_len == 6)
- {
- /* add ATS */
- _pb_data_add(&pb_current,
- &data_ptr,
- job->segment_len,
- ((unsigned char *)&job->mf_header1) + 2, /* little endian */
- 4,
- PB_TO_MACFRAME); /* we are in little endian for simulator... */
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, ((unsigned char *)&job->mf_header1) + 2, 4);
- }
- }
-
- /* check if mac data must be separated into 2 parts (circular buffer rollover) */
- if((job->eth_buffer_mask != 0)
- && (job->data_addr + job->data_len >= ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job)))
- {
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, job->data_addr, ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job) - job->data_addr, PB_TO_MACFRAME);
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, job->data_addr, ETH_BUFFER_ADDR(job) + ETH_BUFFER_SIZE(job) - job->data_addr);
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, (unsigned char *)((unsigned long)job->data_addr & ~ETH_BUFFER_MASK(job)), ((unsigned long)(job->data_addr) + job->data_len) & ETH_BUFFER_MASK(job), PB_TO_MACFRAME);
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, (unsigned char *)((unsigned long)job->data_addr & ~ETH_BUFFER_MASK(job)), ((unsigned long)(job->data_addr) + job->data_len) & ETH_BUFFER_MASK(job));
- }
- else
- {
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, job->data_addr, job->data_len, PB_TO_MACFRAME);
- ctx->icv_current = crc_compute_continue_block(&ctx->crc_ctx, ctx->icv_current, job->data_addr, job->data_len);
- }
- if(job->crc_store)
- {
- /* check crc */
- icv_final = crc_compute_end(&ctx->crc_ctx, ctx->icv_current);
- _pb_data_add(&pb_current, &data_ptr, job->segment_len, (unsigned char *)&icv_compare, 4, PB_TO_MACFRAME); /* we are in little endian for simulator... */
- job->crc_error = (icv_compare != icv_final);
- }
- }
-
- /* job is processed without any delay (because real hardware is
- very fast */
- _job_process_cb (ctx);
-
- return 0;
-}
-
-static void _job_process_cb(void *data)
-{
- struct phy_bridgedma_t *bridgedma_ctx;
-
- dbg_assert(data);
- bridgedma_ctx = (struct phy_bridgedma_t *)data;
-
- /* set interrupt raising */
- if(bridgedma_ctx->job_current->job_it)
- maximus_pending_isrs |= (1 << PHY_HAL_INTERRUPT_BRIDGEDMA);
-
- /* check if we are the last job */
- if(bridgedma_ctx->job_current == bridgedma_ctx->job_last)
- {
- /* last job: stop the process */
- bridgedma_ctx->job_first = NULL;
- bridgedma_ctx->job_current = NULL;
- bridgedma_ctx->job_last = NULL;
-
- /* refresh bridge dma status */
- bridgedma_ctx->status.running = 0;
- bridgedma_ctx->status.stop = 1;
- }
- else
- {
- /* not the last job: process next */
- dbg_assert(bridgedma_ctx->job_current->next);
- bridgedma_ctx->job_current = bridgedma_ctx->job_current->next;
- _job_process(bridgedma_ctx, bridgedma_ctx->job_current);
- }
-
- return;
-}
-
-/**
- * Enqueue and start a list of jobs.
- * \param ctx Bridge DMA context
- * \param job_first first job to enqueue
- * \param job_last last job to enqueue
- *
- * The new jobs are added to the Bridge DMA queue and the Bridge DMA is
- * restarted if it was stopped. The \c last flag must be set in the last
- * enqueued job.
- */
-void
-phy_bridgedma_start (phy_bridgedma_t *ctx, phy_bridgedma_job_t *job_first,
- phy_bridgedma_job_t *job_last)
-{
- dbg_assert(ctx);
- dbg_assert(job_first);
- dbg_assert(job_last);
-
- /* check current job processing */
- if(ctx->job_first == NULL)
- {
- /* no more job in queue */
- ctx->job_first = job_first;
- ctx->job_current = job_first;
- ctx->job_last = job_last;
- memset(&ctx->status, '\0', sizeof(phy_bridgedma_status_t));
- ctx->status.running = 1;
- _job_process(ctx, ctx->job_current);
- }
- else
- {
- /* there are still job inside */
- dbg_assert(ctx->job_last);
- ctx->job_last->next = job_first;
- ctx->job_last = job_last;
- }
-
- return;
-}
-
-/**
- * Get the current job descriptor from the bridgedma.
- * \param ctx the Bridge DMA context.
- * \return the address of the current job descriptor beeing processed by the
- * bridge DMA.
- *
- * It corresponds to the current job which is being processed by the
- * bridgedma when the Interruption arrived.
- */
-phy_bridgedma_job_t *
-phy_bridgedma_current_job (phy_bridgedma_t *ctx)
-{
- dbg_assert (ctx);
-
- return ctx->job_current;
-}
-
-bool
-phy_bridgedma_status (phy_bridgedma_t *ctx)
-{
- dbg_assert (ctx);
- return ctx->status.running;
-}