#ifndef hal_phy_bridgedma_h #define hal_phy_bridgedma_h /* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file hal/phy/bridgedma.h * \brief HAL Phy Bridge DMA public interface. * \ingroup hal_phy */ #include "lib/blk.h" #include "hal/phy/phy.h" /** * Wait N ms for bridge DMA, if this delay is expired, we must * consider the bridge DMA freezed. * see #1962. */ #define PHY_BRG_POLLING_WAIT_MS 30 /** BRIDGE DMA job structure */ struct phy_bridgedma_job_t { /** Pointer to the next job descriptor. */ struct phy_bridgedma_job_t *next; /** Address of data in ethernet buffer (not word aligned). */ u8 *data_addr; BITFIELDS_WORD( /** Mac frame header length */ u32 header_len:16;, /** Length of data in ethernet buffer. max 1518 */ u32 data_len:16;) /** Pointer to the pb descriptor list head */ blk_t *first_pb_desc; BITFIELDS_WORD( /** Start offset in first pb descriptor */ u32 first_pb_offset:16;, /** length of segmentation block default = 512 */ u32 segment_len:16; ) BITFIELDS_WORD( /** indication of last job. If set, bridge will stop after this one */ u32 last:1;, /** transfer direction: 0 for Segmentation (TX), 1 for Reassembly(RX) */ u32 direction:1;, /** crc_error: * Reassembly : set by HW. 0 for crc ok, 1 for crc ko. * Segmentation : set by SW. 0 to compute crc, 1 to copy crc from bridgedma * icv substitution register. */ u32 crc_error:1;, /** Reset crc computation before transfer */ u32 crc_reset:1;, /** presence of crc : set by SW. * Reassembly : 0 for no crc, 1 for crc after data. * Segmentation : 0 to not add crc after data, 1 else. */ u32 crc_store:1;, /** append zero after data+crc */ u32 append_zero:1;, /** interrupt mask : if 0, HW will not throw interruption at the end of * job. */ u32 job_it:1;, /** defines a rollover mask for ethernet buffer. * Used for circular buffer, this is the MSB of 32 bit mask which defines * which address bits are constant and which should be incremented on each * word */ u32 eth_buffer_mask:25; ) /** mac frame header part 1 */ u32 mf_header1; /** mac frame header part 2 */ u32 mf_header2; /** mac frame header part 3 (NOT used but declared in the bridgeDMA). */ u32 mf_header3; }; typedef struct phy_bridgedma_job_t phy_bridgedma_job_t; /** BRIDGE DMA status given back after a interrupt. */ struct phy_bridgedma_status_t { BITFIELDS_WORD( /** AHB response error */ u32 ahb_response_error:1;, u32 :15;, /** Debug : ctrl fsm */ u32 ctrl_fsm:2;, /** running bit sets when bridge dma works */ u32 running:1;, /** Correspond to the stop bit in job descriptor. It means that dma will or has stop */ u32 stop:1;, u32 :12;) }; typedef struct phy_bridgedma_status_t phy_bridgedma_status_t; /** * Bridge DMA callback called when an interrupt occurs. * \param user user data * \param status_word status read from PB DMA * \return true if a DSR is requested */ typedef bool (*phy_bridgedma_cb_t) (void *user, u32 status_word); /** Cast a u32 word to the \c phy_bridgedma_status_t structure. The reason * behind this macro is that the callback receive the status as a u32 in order * to use a register, not a pointer, to pass the parameter. */ #define PHY_BRIDGEDMA_STATUS(w) (*(phy_bridgedma_status_t *) (void *) &(w)) BEGIN_DECLS /** * 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); /** * Reset and uninitialise the Bridge DMA. * \param ctx Bridge DMA context */ void phy_bridgedma_uninit (phy_bridgedma_t *ctx); /** * 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); /** * Bridge DMA status. * \param ctx the Bridge DMA context. * \return true if running. */ bool phy_bridgedma_status (phy_bridgedma_t *ctx); /** * Get the job list of ended jobs from the bridge DMA. * \param ctx the Bridge DMA context. * \return the first job of the list. * * This function will return the list of ended jobs in the bridge DMA, the * list can be parsed using the next pointer in the job structure the last one * will have the next pointer set to NULL. */ phy_bridgedma_job_t * phy_bridgedma_jobs_get_ended (phy_bridgedma_t *ctx); /** * Wait until the bridgedma is stopped. * \param ctx the Bridge DMA context. */ void phy_bridgedma_stopped (phy_bridgedma_t *ctx); END_DECLS #endif /* hal_phy_bridgedma_h */