From 5d9cf99cad000faee61ddecb6990b414661eb49b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 15 Nov 2010 10:53:24 -0800 Subject: usrp2: implemented packet ctrl to read and write slow path packets from the new interface --- firmware/microblaze/lib/pkt_ctrl.h | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 firmware/microblaze/lib/pkt_ctrl.h (limited to 'firmware/microblaze/lib/pkt_ctrl.h') 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 . + */ + +#ifndef INCLUDED_PKT_CTRL_H +#define INCLUDED_PKT_CTRL_H + +#include + +/*! + * 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 */ -- cgit v1.2.3 From 68af2b9ccf556f42d7697c73406abdcc31093d1b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 17 Nov 2010 17:12:01 -0800 Subject: usrp2: implement routing mode calls, and prefix pkt ctrl calls --- firmware/microblaze/apps/txrx_uhd.c | 18 ++++++++++++------ firmware/microblaze/lib/net_common.c | 4 ++-- firmware/microblaze/lib/pkt_ctrl.c | 19 +++++++++++++++---- firmware/microblaze/lib/pkt_ctrl.h | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 16 deletions(-) (limited to 'firmware/microblaze/lib/pkt_ctrl.h') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 4adccfed9..938491b0e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -279,10 +279,16 @@ static void handle_inp_packet(uint32_t *buff, size_t num_lines){ * Called when eth phy state changes (w/ interrupts disabled) */ void link_changed_callback(int speed){ - bool link_is_up = speed != 0; - hal_set_leds(link_is_up ? LED_RJ45 : 0x0, LED_RJ45); - printf("\neth link changed: speed = %d\n", speed); - if (link_is_up) send_gratuitous_arp(); + printf("\neth link changed: speed = %d\n", speed); + if (speed != 0){ + hal_set_leds(LED_RJ45, LED_RJ45); + pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_MASTER); + send_gratuitous_arp(); //garp after setting the routing mode + } + else{ + hal_set_leds(0x0, LED_RJ45); + pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); + } } static void setup_network(void){ @@ -357,10 +363,10 @@ main(void) while(true){ size_t num_lines; - void *buff = claim_incoming_buffer(&num_lines); + void *buff = pkt_ctrl_claim_incoming_buffer(&num_lines); if (buff != NULL){ handle_inp_packet((uint32_t *)buff, num_lines); - release_incoming_buffer(); + pkt_ctrl_release_incoming_buffer(); } int pending = pic_regs->pending; // poll for under or overrun diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index cc08997a0..486a34252 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -128,7 +128,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, ehdr.src = _local_mac_addr; ehdr.ethertype = ethertype; - uint32_t *buff = (uint32_t *)claim_outgoing_buffer(); + uint32_t *buff = (uint32_t *)pkt_ctrl_claim_outgoing_buffer(); // Copy the pieces into the buffer uint32_t *p = buff; @@ -165,7 +165,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, if (total_len < 60) // ensure that we don't try to send a short packet total_len = 60; - commit_outgoing_buffer(total_len/4); + pkt_ctrl_commit_outgoing_buffer(total_len/4); } unsigned int diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 235a09459..f7f808cfc 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -30,24 +30,35 @@ static void set_control(uint32_t value, uint32_t mask){ buffer_pool_ctrl->ctrl = ctrl_shadow; } -void *claim_incoming_buffer(size_t *num_lines){ +void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ + switch(mode){ + case PKT_CTRL_ROUTING_MODE_SLAVE: + set_control(0x0, 0x4); + break; + case PKT_CTRL_ROUTING_MODE_MASTER: + set_control(0x4, 0x4); + break; + } +} + +void *pkt_ctrl_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){ +void pkt_ctrl_release_incoming_buffer(void){ set_control(0x0, 0x1); while ((buffer_pool_status->status & 0x1) != 0){} } -void *claim_outgoing_buffer(void){ +void *pkt_ctrl_claim_outgoing_buffer(void){ while ((buffer_pool_status->status & 0x2) != 0x2){} return buffer_ram(1); } -void commit_outgoing_buffer(size_t num_lines){ +void pkt_ctrl_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 index 156fc06dc..86fb46d32 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -20,28 +20,36 @@ #include +typedef enum { + PKT_CTRL_ROUTING_MODE_SLAVE, + PKT_CTRL_ROUTING_MODE_MASTER, +} pkt_ctrl_routing_mode_t; + +//! Set the routing mode for this device +void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); + /*! * 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); +void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines); /*! * Release the incoming buffer. Call when done. */ -void release_incoming_buffer(void); +void pkt_ctrl_release_incoming_buffer(void); /*! * Claim an outgoing buffer. * \return a pointer to the buffer */ -void *claim_outgoing_buffer(void); +void *pkt_ctrl_claim_outgoing_buffer(void); /*! * Commit the outgoing buffer. * \param num_lines how many lines written. */ -void commit_outgoing_buffer(size_t num_lines); +void pkt_ctrl_commit_outgoing_buffer(size_t num_lines); #endif /* INCLUDED_PKT_CTRL_H */ -- cgit v1.2.3 From 6004410a7b73a52d95b8f5f0cf0fa969bef4e910 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 21 Nov 2010 13:36:25 -0800 Subject: packet_router: implemented code to program the addresses into the router --- firmware/microblaze/apps/txrx_uhd.c | 6 +++--- firmware/microblaze/lib/net_common.c | 15 +++------------ firmware/microblaze/lib/net_common.h | 4 +--- firmware/microblaze/lib/pkt_ctrl.c | 24 ++++++++++++++++++++++++ firmware/microblaze/lib/pkt_ctrl.h | 7 +++++++ 5 files changed, 38 insertions(+), 18 deletions(-) (limited to 'firmware/microblaze/lib/pkt_ctrl.h') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index f922ce4af..741167c0e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -348,9 +348,9 @@ main(void) printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM); //1) register the addresses into the network stack - register_mac_addr(ethernet_mac_addr()); - register_ip_addr(get_ip_addr()); - + register_addrs(ethernet_mac_addr(), get_ip_addr()); + pkt_ctrl_register_addrs(ethernet_mac_addr(), get_ip_addr()); + //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 48aa460f9..e9b633b13 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -39,21 +39,12 @@ static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static inline bool -ip_addr_eq(const struct ip_addr a, const struct ip_addr b) -{ - return a.addr == b.addr; -} - // ------------------------------------------------------------------------ static eth_mac_addr_t _local_mac_addr; -void register_mac_addr(const eth_mac_addr_t *mac_addr){ - _local_mac_addr = *mac_addr; -} - static struct ip_addr _local_ip_addr; -void register_ip_addr(const struct ip_addr *ip_addr){ +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr){ + _local_mac_addr = *mac_addr; _local_ip_addr = *ip_addr; } @@ -382,7 +373,7 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) sip.addr = get_int32(p->ar_sip); tip.addr = get_int32(p->ar_tip); - if (ip_addr_eq(tip, _local_ip_addr)){ // They're looking for us... + if (memcmp(&tip, &_local_ip_addr, sizeof(_local_ip_addr)) == 0){ // They're looking for us... send_arp_reply(p, _local_mac_addr); } } diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 9d6a3e345..5e364adeb 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -26,9 +26,7 @@ typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); -void register_mac_addr(const eth_mac_addr_t *mac_addr); - -void register_ip_addr(const struct ip_addr *ip_addr); +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr); void register_udp_listener(int port, udp_receiver_t rcvr); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 9f662122d..52ba80e3a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -47,6 +47,30 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +){ + //program in the ip addr + set_control(0x1 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); + set_control(0x2 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); + + //program in the mac addr + set_control(0x3 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16); + set_control(0x4 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16); + set_control(0x5 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16); + + //clear cmd + set_control(0x0, 0x7 << 4); +} + void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ switch(mode){ case PKT_CTRL_ROUTING_MODE_SLAVE: diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 86fb46d32..761209530 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -19,12 +19,19 @@ #define INCLUDED_PKT_CTRL_H #include +#include +#include typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; +//! Register this devices addresses into the router +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +); + //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); -- cgit v1.2.3 From 95499e2e132b1c619704b6fbc452e661633b3233 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 22 Nov 2010 13:54:48 -0800 Subject: packet_router: dont register mac, also reorganized some tidbits --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/banal.h | 18 ------------------ firmware/microblaze/lib/net_common.c | 11 +++++++++-- firmware/microblaze/lib/net_common.h | 7 +++++++ firmware/microblaze/lib/pkt_ctrl.c | 23 ++++------------------- firmware/microblaze/lib/pkt_ctrl.h | 7 ++----- firmware/microblaze/lib/u2_init.c | 10 ---------- 7 files changed, 23 insertions(+), 55 deletions(-) (limited to 'firmware/microblaze/lib/pkt_ctrl.h') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 741167c0e..6f852bb18 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_register_addrs(ethernet_mac_addr(), get_ip_addr()); + pkt_ctrl_register_ip_addr(get_ip_addr()); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/banal.h b/firmware/microblaze/lib/banal.h index 634234350..eb7ed509a 100644 --- a/firmware/microblaze/lib/banal.h +++ b/firmware/microblaze/lib/banal.h @@ -19,27 +19,9 @@ #define INCLUDED_BANAL_H #include -#include #define dimof(x) (sizeof(x)/sizeof(x[0])) -/* - * 1's complement sum for IP and UDP headers - * - * init chksum to zero to start. - */ -static inline unsigned int -CHKSUM(unsigned int x, unsigned int *chksum) -{ - *chksum += x; - *chksum = (*chksum & 0xffff) + (*chksum>>16); - *chksum = (*chksum & 0xffff) + (*chksum>>16); - return x; -} - -unsigned int -chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum); - //-------------- unsigned get_int 8, 16, 32, 64 --------------// static inline uint8_t diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index e9b633b13..9804ae4c5 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -162,7 +162,15 @@ send_pkt(eth_mac_addr_t dst, int ethertype, //printf("sent %d bytes\n", total_len); } -unsigned int +unsigned int CHKSUM(unsigned int x, unsigned int *chksum) +{ + *chksum += x; + *chksum = (*chksum & 0xffff) + (*chksum>>16); + *chksum = (*chksum & 0xffff) + (*chksum>>16); + return x; +} + +static unsigned int chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum) { unsigned int chksum = initial_chksum; @@ -172,7 +180,6 @@ chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum) return chksum; } - void send_ip_pkt(struct ip_addr dst, int protocol, const void *buf0, size_t len0, diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 5e364adeb..4004ca6e6 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -23,6 +23,13 @@ #include #include +/* + * 1's complement sum for IP and UDP headers + * + * init chksum to zero to start. + */ +unsigned int CHKSUM(unsigned int x, unsigned int *chksum); + typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 52ba80e3a..9870a1f8a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -47,28 +47,15 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 -void pkt_ctrl_register_addrs( - const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr -){ +void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr){ //program in the ip addr - set_control(0x1 << 4, 0x7 << 4); + set_control(0x1 << 4, 0x3 << 4); set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); - set_control(0x2 << 4, 0x7 << 4); + set_control(0x2 << 4, 0x3 << 4); set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); - //program in the mac addr - set_control(0x3 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16); - set_control(0x4 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16); - set_control(0x5 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16); - //clear cmd - set_control(0x0, 0x7 << 4); + set_control(0x0, 0x3 << 4); } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ @@ -80,8 +67,6 @@ void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ set_control_bit(MODE_BIT); break; } - set_control_bit(CLR_BIT); //clear after mode change - clr_control_bit(CLR_BIT); //unset the clear signal } void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 761209530..2e175bca0 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -20,17 +20,14 @@ #include #include -#include typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; -//! Register this devices addresses into the router -void pkt_ctrl_register_addrs( - const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr -); +//! Register the IP address into the router +void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr); //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 9302c90b2..191a0e816 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -27,16 +27,6 @@ #include "usrp2/fw_common.h" #include "nonstdio.h" -unsigned char u2_hw_rev_major; -unsigned char u2_hw_rev_minor; - -static inline void -get_hw_rev(void) -{ - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, &u2_hw_rev_minor, 1); - ok &= eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV+1, &u2_hw_rev_major, 1); -} - /* * We ought to arrange for this to be called before main, but for now, * we require that the user's main call u2_init as the first thing... -- cgit v1.2.3 From 07de916b7646c78d4ad5ba9104d52343e993d198 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 23 Nov 2010 18:09:51 -0800 Subject: packet_router: added sregs for ip addr and ports the pkt control now programs the inspector with port and ip addr set the eth mac to pass all unicast added easy debug flag to net common --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/eth_mac.c | 4 +++- firmware/microblaze/lib/net_common.c | 10 ++++++---- firmware/microblaze/lib/pkt_ctrl.c | 16 +++++----------- firmware/microblaze/lib/pkt_ctrl.h | 8 ++++++-- firmware/microblaze/usrp2/memory_map.h | 2 ++ firmware/microblaze/usrp2p/memory_map.h | 2 ++ 7 files changed, 25 insertions(+), 19 deletions(-) (limited to 'firmware/microblaze/lib/pkt_ctrl.h') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 6f852bb18..8ee53ac3e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_register_ip_addr(get_ip_addr()); + pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DATA_PORT); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/eth_mac.c b/firmware/microblaze/lib/eth_mac.c index 034a4d494..581a5c69f 100644 --- a/firmware/microblaze/lib/eth_mac.c +++ b/firmware/microblaze/lib/eth_mac.c @@ -28,6 +28,7 @@ void eth_mac_set_addr(const eth_mac_addr_t *src) { + /* disable because MAC_SET_PASS_ALL is set below eth_mac->ucast_hi = (((unsigned int)src->addr[0])<<8) + ((unsigned int)src->addr[1]); @@ -36,6 +37,7 @@ eth_mac_set_addr(const eth_mac_addr_t *src) (((unsigned int)src->addr[3])<<16) + (((unsigned int)src->addr[4])<<8) + (((unsigned int)src->addr[5])); +*/ } @@ -45,7 +47,7 @@ eth_mac_init(const eth_mac_addr_t *src) eth_mac->miimoder = 25; // divider from CPU clock (50MHz/25 = 2MHz) eth_mac_set_addr(src); - eth_mac->settings = MAC_SET_PAUSE_EN | MAC_SET_PASS_BCAST | MAC_SET_PASS_UCAST | MAC_SET_PAUSE_SEND_EN; + eth_mac->settings = MAC_SET_PAUSE_EN | MAC_SET_PASS_BCAST | MAC_SET_PASS_UCAST | MAC_SET_PAUSE_SEND_EN | MAC_SET_PASS_ALL; eth_mac->pause_time = 38; eth_mac->pause_thresh = 1200; diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 9804ae4c5..947f41dae 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -37,6 +37,8 @@ #include #include "pkt_ctrl.h" +static const bool debug = false; + static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; // ------------------------------------------------------------------------ @@ -159,7 +161,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, total_len = 60; pkt_ctrl_commit_outgoing_buffer(total_len/4); - //printf("sent %d bytes\n", total_len); + if (debug) printf("sent %d bytes\n", (int)total_len); } unsigned int CHKSUM(unsigned int x, unsigned int *chksum) @@ -388,9 +390,9 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) void handle_eth_packet(uint32_t *p, size_t nlines) { - //static size_t bcount = 0; - //printf("===> %d\n", bcount++); - //print_buffer(p, nlines); + static size_t bcount = 0; + if (debug) printf("===> %d\n", (int)bcount++); + if (debug) print_buffer(p, nlines); padded_eth_hdr_t *eth_hdr = (padded_eth_hdr_t *)p; diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 9870a1f8a..f4b4b7825 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -17,8 +17,6 @@ #include "pkt_ctrl.h" #include "memory_map.h" -#include -#include #include static void set_control(uint32_t value, uint32_t mask){ @@ -47,15 +45,11 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 -void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr){ - //program in the ip addr - set_control(0x1 << 4, 0x3 << 4); - set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); - set_control(0x2 << 4, 0x3 << 4); - set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); - - //clear cmd - set_control(0x0, 0x3 << 4); +void pkt_ctrl_program_inspector( + const struct ip_addr *ip_addr, uint16_t dsp_udp_port +){ + buffer_pool_ctrl->ip_addr = ip_addr->addr; + buffer_pool_ctrl->udp_ports = dsp_udp_port; } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 2e175bca0..927d1fc7a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -19,6 +19,8 @@ #define INCLUDED_PKT_CTRL_H #include +#include +#include #include typedef enum { @@ -26,8 +28,10 @@ typedef enum { PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; -//! Register the IP address into the router -void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr); +//! Program the decision values into the packet inspector +void pkt_ctrl_program_inspector( + const struct ip_addr *ip_addr, uint16_t dsp_udp_port +); //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); diff --git a/firmware/microblaze/usrp2/memory_map.h b/firmware/microblaze/usrp2/memory_map.h index 2b07ff148..25c800893 100644 --- a/firmware/microblaze/usrp2/memory_map.h +++ b/firmware/microblaze/usrp2/memory_map.h @@ -247,6 +247,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t ctrl; + volatile uint32_t ip_addr; + volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) } buffer_pool_ctrl_t; #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE) diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index 431dc19e7..dedfdac8b 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -274,6 +274,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t ctrl; + volatile uint32_t ip_addr; + volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) } buffer_pool_ctrl_t; #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE) -- cgit v1.2.3 From 096405b9291d1d3b3ac37d9768232cca43a37db6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 10 Dec 2010 18:57:17 -0800 Subject: packet_router: added control register to set the udp control port --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/pkt_ctrl.c | 5 +++-- firmware/microblaze/lib/pkt_ctrl.h | 2 +- firmware/microblaze/usrp2/memory_map.h | 3 ++- firmware/microblaze/usrp2p/memory_map.h | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) (limited to 'firmware/microblaze/lib/pkt_ctrl.h') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 8ee53ac3e..dc41e56c4 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DATA_PORT); + pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_CTRL_PORT, USRP2_UDP_DATA_PORT); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index d2bfc339d..7e095ec00 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -20,10 +20,11 @@ #include void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t dsp_udp_port + const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port ){ buffer_pool_ctrl->ip_addr = ip_addr->addr; - buffer_pool_ctrl->udp_ports = dsp_udp_port; + buffer_pool_ctrl->ctrl_ports = ctrl_port; + buffer_pool_ctrl->data_ports = data_port; } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 927d1fc7a..346e22094 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -30,7 +30,7 @@ typedef enum { //! Program the decision values into the packet inspector void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t dsp_udp_port + const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port ); //! Set the routing mode for this device diff --git a/firmware/microblaze/usrp2/memory_map.h b/firmware/microblaze/usrp2/memory_map.h index 09aef643e..23d96389f 100644 --- a/firmware/microblaze/usrp2/memory_map.h +++ b/firmware/microblaze/usrp2/memory_map.h @@ -248,7 +248,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t misc_ctrl; volatile uint32_t ip_addr; - volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) + volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) + volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; } buffer_pool_ctrl_t; diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index 277f433c5..5edb3b313 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -275,7 +275,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t misc_ctrl; volatile uint32_t ip_addr; - volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) + volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) + volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; } buffer_pool_ctrl_t; -- cgit v1.2.3