diff options
Diffstat (limited to 'firmware/microblaze/lib')
-rw-r--r-- | firmware/microblaze/lib/Makefile.inc | 1 | ||||
-rw-r--r-- | firmware/microblaze/lib/net_common.c | 30 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.c | 54 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.h | 47 |
4 files changed, 107 insertions, 25 deletions
diff --git a/firmware/microblaze/lib/Makefile.inc b/firmware/microblaze/lib/Makefile.inc index 1ca375861..471a244e0 100644 --- a/firmware/microblaze/lib/Makefile.inc +++ b/firmware/microblaze/lib/Makefile.inc @@ -36,6 +36,7 @@ COMMON_SRCS = \ $(top_srcdir)/lib/memset_wa.c \ $(top_srcdir)/lib/nonstdio.c \ $(top_srcdir)/lib/pic.c \ + $(top_srcdir)/lib/pkt_ctrl.c \ $(top_srcdir)/lib/print_addrs.c \ $(top_srcdir)/lib/print_rmon_regs.c \ $(top_srcdir)/lib/print_buffer.c \ diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 1ff7ebde7..cc08997a0 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -35,6 +35,7 @@ #include "if_arp.h" #include <ethertype.h> #include <string.h> +#include "pkt_ctrl.h" static inline bool ip_addr_eq(const struct ip_addr a, const struct ip_addr b) @@ -119,13 +120,6 @@ send_pkt(eth_mac_addr_t dst, int ethertype, const void *buf1, size_t len1, const void *buf2, size_t len2) { - // Wait for buffer to become idle - // FIXME can this ever not be ready? - - //hal_set_leds(LED_BUF_BUSY, LED_BUF_BUSY); - //FIXME while((buffer_pool_status->status & BPS_IDLE(CPU_TX_BUF)) == 0) - //FIXME ; - //hal_set_leds(0, LED_BUF_BUSY); // Assemble the header padded_eth_hdr_t ehdr; @@ -134,9 +128,10 @@ send_pkt(eth_mac_addr_t dst, int ethertype, ehdr.src = _local_mac_addr; ehdr.ethertype = ethertype; - uint32_t *p = 0;//FIXME buffer_ram(CPU_TX_BUF); + uint32_t *buff = (uint32_t *)claim_outgoing_buffer(); // Copy the pieces into the buffer + uint32_t *p = buff; *p++ = 0x0; // slow path memcpy_wa(p, &ehdr, sizeof(ehdr)); // 4 lines p += sizeof(ehdr)/sizeof(uint32_t); @@ -166,26 +161,11 @@ send_pkt(eth_mac_addr_t dst, int ethertype, p += len2/sizeof(uint32_t); } - size_t total_len = 0;//FIXME (p - buffer_ram(CPU_TX_BUF)) * sizeof(uint32_t); + size_t total_len = (p - buff) * sizeof(uint32_t); if (total_len < 60) // ensure that we don't try to send a short packet total_len = 60; - - // wait until nobody else is sending to the ethernet - //FIXME if (ac_could_be_sending_to_eth){ - //hal_set_leds(LED_ETH_BUSY, LED_ETH_BUSY); - //FIXME dbsm_wait_for_opening(ac_could_be_sending_to_eth); - //hal_set_leds(0x0, LED_ETH_BUSY); - //FIXME } - - - // fire it off - //FIXME bp_send_from_buf(CPU_TX_BUF, cpu_tx_buf_dest_port, 1, 0, total_len/4); - - // wait for it to complete (not long, it's a small pkt) - //FIXME while((buffer_pool_status->status & (BPS_DONE(CPU_TX_BUF) | BPS_ERROR(CPU_TX_BUF))) == 0) - //FIXME ; - //FIXME bp_clear_buf(CPU_TX_BUF); + commit_outgoing_buffer(total_len/4); } unsigned int diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c new file mode 100644 index 000000000..235a09459 --- /dev/null +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -0,0 +1,54 @@ +/* + * Copyright 2010 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "pkt_ctrl.h" +#include "memory_map.h" +#include <stdint.h> +#include <stdbool.h> +#include <nonstdio.h> + +static void set_control(uint32_t value, uint32_t mask){ + static uint32_t ctrl_shadow = 0; + + ctrl_shadow &= ~mask; + ctrl_shadow |= value & mask; + + buffer_pool_ctrl->ctrl = ctrl_shadow; +} + +void *claim_incoming_buffer(size_t *num_lines){ + if ((buffer_pool_status->status & 0x1) != 1) return NULL; + *num_lines = (buffer_pool_status->status >> 16) & 0xffff; + set_control(0x1, 0x1); + return buffer_ram(0); +} + +void release_incoming_buffer(void){ + set_control(0x0, 0x1); + while ((buffer_pool_status->status & 0x1) != 0){} +} + +void *claim_outgoing_buffer(void){ + while ((buffer_pool_status->status & 0x2) != 0x2){} + return buffer_ram(1); +} + +void commit_outgoing_buffer(size_t num_lines){ + set_control(0x2 | (num_lines << 16), 0x2 | (0xffff << 16)); + while ((buffer_pool_status->status & 0x2) != 0x0){} + set_control(0x0, 0x2); +} diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h new file mode 100644 index 000000000..156fc06dc --- /dev/null +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -0,0 +1,47 @@ +/* + * Copyright 2010 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef INCLUDED_PKT_CTRL_H +#define INCLUDED_PKT_CTRL_H + +#include <stddef.h> + +/*! + * Try to claim an incomming buffer. + * \param num_lines filled with the buffer size + * \return a pointer to the buffer memory or NULL + */ +void *claim_incoming_buffer(size_t *num_lines); + +/*! + * Release the incoming buffer. Call when done. + */ +void release_incoming_buffer(void); + +/*! + * Claim an outgoing buffer. + * \return a pointer to the buffer + */ +void *claim_outgoing_buffer(void); + +/*! + * Commit the outgoing buffer. + * \param num_lines how many lines written. + */ +void commit_outgoing_buffer(size_t num_lines); + +#endif /* INCLUDED_PKT_CTRL_H */ |