3 * Copyright 2007,2008,2009 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef INCLUDED_USRP2_ETH_PACKET_H
20 #define INCLUDED_USRP2_ETH_PACKET_H
22 #include "usrp2_cdefs.h"
23 #include "usrp2_bytesex.h"
24 #include "usrp2_mac_addr.h"
25 #include "usrp2_mimo_config.h"
29 #define U2_ETHERTYPE 0xBEEF // used in our frames
30 #define MAC_CTRL_ETHERTYPE 0x8808 // used in PAUSE frames
33 * All these data structures are BIG-ENDIAN on the wire
36 // FIXME gcc specific. Really ought to come from compiler.h
37 #define _AL4 __attribute__((aligned (4)))
40 * \brief The classic 14-byte ethernet header
46 } __attribute__((packed)) u2_eth_hdr_t;
49 * \brief USRP2 transport header
51 * This enables host->usrp2 flow control and dropped packet detection.
54 uint16_t flags; // MBZ, may be used for channel in future
55 uint16_t fifo_status; // free space in Rx fifo in 32-bit lines
56 uint8_t seqno; // sequence number of this packet
57 uint8_t ack; // sequence number of next packet expected
58 } __attribute__((packed)) u2_transport_hdr_t;
62 * The fixed payload header of a USRP2 ethernet packet...
64 * Basically there's 1 word of flags and routing info, and 1 word
65 * of timestamp that specifies when the data was received, or
66 * when it should be transmitted. The data samples follow immediately.
68 * Transmit packets (from host to U2)
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * | Chan | mbz |I|S|E|
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 * Received packets (from U2 to host)
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 uint32_t word0; // flags etc
90 uint32_t timestamp; // time of rx or tx (100 MHz)
94 #define U2P_CHAN_MASK 0x1f
95 #define U2P_CHAN_SHIFT 27
97 #define U2P_TX_IMMEDIATE 0x00000004 // send samples NOW, else at timestamp
98 #define U2P_TX_START_OF_BURST 0x00000002 // this frame is the start of a burst
99 #define U2P_TX_END_OF_BURST 0x00000001 // this frame is the end of a burst
101 #define U2P_ALL_FLAGS 0x00000007
103 #define CONTROL_CHAN 0x1f
106 u2p_chan(u2_fixed_hdr_t *p)
108 return (ntohl(p->word0) >> U2P_CHAN_SHIFT) & U2P_CHAN_MASK;
111 inline static uint32_t
112 u2p_word0(u2_fixed_hdr_t *p)
114 return ntohl(p->word0);
117 inline static uint32_t
118 u2p_timestamp(u2_fixed_hdr_t *p)
120 return ntohl(p->timestamp);
124 u2p_set_word0(u2_fixed_hdr_t *p, int flags, int chan)
126 p->word0 = htonl((flags & U2P_ALL_FLAGS)
127 | ((chan & U2P_CHAN_MASK) << U2P_CHAN_SHIFT));
131 u2p_set_timestamp(u2_fixed_hdr_t *p, uint32_t ts)
133 p->timestamp = htonl(ts);
137 * \brief consolidated packet: ethernet header + transport header + fixed header
141 u2_transport_hdr_t thdr;
142 u2_fixed_hdr_t fixed;
146 * full load of samples:
147 * ethernet header + transport header + fixed header + maximum number of samples.
148 * sizeof(u2_eth_samples_t) == 1512
149 * (payload is 1498 bytes, two bytes shorter than 1500 byte MTU)
152 #define U2_MAX_SAMPLES 371
155 u2_eth_packet_t hdrs;
156 uint32_t samples[U2_MAX_SAMPLES];
160 * Opcodes for control channel
162 * Reply opcodes are the same as the request opcode with the OP_REPLY_BIT set (0x80).
164 #define OP_REPLY_BIT 0x80
166 #define OP_EOP 0 // marks last subpacket in packet
169 #define OP_ID_REPLY (OP_ID | OP_REPLY_BIT)
170 #define OP_BURN_MAC_ADDR 2
171 #define OP_BURN_MAC_ADDR_REPLY (OP_BURN_MAC_ADDR | OP_REPLY_BIT)
172 #define OP_READ_TIME 3 // What time is it? (100 MHz counter)
173 #define OP_READ_TIME_REPLY (OP_READ_TIME | OP_REPLY_BIT)
174 #define OP_CONFIG_RX_V2 4
175 #define OP_CONFIG_RX_REPLY_V2 (OP_CONFIG_RX_V2 | OP_REPLY_BIT)
176 #define OP_CONFIG_TX_V2 5
177 #define OP_CONFIG_TX_REPLY_V2 (OP_CONFIG_TX_V2 | OP_REPLY_BIT)
178 #define OP_START_RX_STREAMING 6
179 #define OP_START_RX_STREAMING_REPLY (OP_START_RX_STREAMING | OP_REPLY_BIT)
181 #define OP_STOP_RX_REPLY (OP_STOP_RX | OP_REPLY_BIT)
182 #define OP_CONFIG_MIMO 8
183 #define OP_CONFIG_MIMO_REPLY (OP_CONFIG_MIMO | OP_REPLY_BIT)
184 #define OP_DBOARD_INFO 9
185 #define OP_DBOARD_INFO_REPLY (OP_DBOARD_INFO | OP_REPLY_BIT)
186 #define OP_SYNC_TO_PPS 10
187 #define OP_SYNC_TO_PPS_REPLY (OP_SYNC_TO_PPS | OP_REPLY_BIT)
189 #define OP_PEEK_REPLY (OP_PEEK | OP_REPLY_BIT)
191 #define OP_POKE_REPLY (OP_POKE | OP_REPLY_BIT)
192 #define OP_SET_TX_LO_OFFSET 13
193 #define OP_SET_TX_LO_OFFSET_REPLY (OP_SET_TX_LO_OFFSET | OP_REPLY_BIT)
194 #define OP_SET_RX_LO_OFFSET 14
195 #define OP_SET_RX_LO_OFFSET_REPLY (OP_SET_RX_LO_OFFSET | OP_REPLY_BIT)
196 #define OP_RESET_DB 15
197 #define OP_RESET_DB_REPLY (OP_RESET_DB | OP_REPLY_BIT)
198 #define OP_SYNC_EVERY_PPS 16
199 #define OP_SYNC_EVERY_PPS_REPLY (OP_SYNC_EVERY_PPS | OP_REPLY_BIT)
202 * All subpackets are a multiple of 4 bytes long.
203 * All subpackets start with an 8-bit opcode, an 8-bit len and an 8-bit rid.
205 #define MAX_SUBPKT_LEN 252
208 * \brief Generic request and reply packet
211 * OP_EOP, OP_BURN_MAC_ADDR_REPLY, OP_START_RX_STREAMING_REPLY,
212 * OP_STOP_RX_REPLY, OP_DBOARD_INFO, OP_SYNC_TO_PPS
222 * \brief Reply info from a USRP2
231 uint8_t fpga_md5sum[16];
232 uint8_t sw_md5sum[16];
233 } _AL4 op_id_reply_t;
240 uint32_t items_per_frame; // # of 32-bit data items; MTU=1500: [9,371]
241 } _AL4 op_start_rx_streaming_t;
248 } _AL4 op_burn_mac_addr_t;
256 } _AL4 op_read_time_reply_t;
260 * \brief Configure receiver
267 // bitmask indicating which of the following fields are valid
269 uint16_t gain; // fxpt_db (Q9.7)
270 uint32_t freq_hi; // high 32-bits of 64-bit fxpt_freq (Q44.20)
271 uint32_t freq_lo; // low 32-bits of 64-bit fxpt_freq (Q44.20)
272 uint32_t decim; // desired decimation factor (NOT -1)
273 uint32_t scale_iq; // (scale_i << 16) | scale_q [16.0 format]
274 } _AL4 op_config_rx_v2_t;
276 // bitmask for "valid" field. If the bit is set, there's
277 // meaningful data in the corresonding field.
279 #define CFGV_GAIN 0x0001 // gain field is valid
280 #define CFGV_FREQ 0x0002 // target_freq field is valid
281 #define CFGV_INTERP_DECIM 0x0004 // interp or decim is valid
282 #define CFGV_SCALE_IQ 0x0008 // scale_iq is valid
285 * \brief Reply to receiver configuration
293 uint16_t ok; // config was successful (bool)
294 uint16_t inverted; // spectrum is inverted (bool)
296 // RF frequency that corresponds to DC in the IF (fxpt_freq)
297 uint32_t baseband_freq_hi;
298 uint32_t baseband_freq_lo;
299 // DDC frequency (fxpt_freq)
300 uint32_t ddc_freq_hi;
301 uint32_t ddc_freq_lo;
302 // residual frequency (fxpt_freq)
303 uint32_t residual_freq_hi;
304 uint32_t residual_freq_lo;
306 } _AL4 op_config_rx_reply_v2_t;
309 * \brief Configure transmitter
317 // bitmask indicating which of the following fields are valid
319 uint16_t gain; // fxpt_db (Q9.7)
320 uint32_t freq_hi; // high 32-bits of 64-bit fxpt_freq (Q44.20)
321 uint32_t freq_lo; // low 32-bits of 64-bit fxpt_freq (Q44.20)
322 uint32_t interp; // desired interpolation factor (NOT -1)
323 uint32_t scale_iq; // (scale_i << 16) | scale_q [16.0 format]
324 } _AL4 op_config_tx_v2_t;
327 * \brief Reply to configure transmitter
335 uint16_t ok; // config was successful (bool)
336 uint16_t inverted; // spectrum is inverted (bool)
338 // RF frequency that corresponds to DC in the IF (fxpt_freq)
339 uint32_t baseband_freq_hi;
340 uint32_t baseband_freq_lo;
341 // DUC frequency (fxpt_freq)
342 uint32_t duc_freq_hi;
343 uint32_t duc_freq_lo;
344 // residual frequency (fxpt_freq)
345 uint32_t residual_freq_hi;
346 uint32_t residual_freq_lo;
348 } _AL4 op_config_tx_reply_v2_t;
351 * \brief Configure MIMO clocking, etc (uses generic reply)
357 uint8_t flags; // from usrp_mimo_config.h
362 * \brief High-level information about daughterboards
365 int32_t dbid; //< d'board ID (-1 none, -2 invalid eeprom)
366 uint32_t freq_min_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20)
367 uint32_t freq_min_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20)
368 uint32_t freq_max_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20)
369 uint32_t freq_max_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20)
370 uint16_t gain_min; //< min gain that can be set. fxpt_db (Q9.7)
371 uint16_t gain_max; //< max gain that can be set. fxpt_db (Q9.7)
372 uint16_t gain_step_size; //< fxpt_db (Q9.7)
377 * \brief Reply to d'board info request
383 uint8_t ok; // request was successful (bool)
385 u2_db_info_t tx_db_info;
386 u2_db_info_t rx_db_info;
387 } _AL4 op_dboard_info_reply_t;
390 * \brief Read from Wishbone memory
402 * \brief Write to Wishbone memory
414 * Common structure for commands with a single frequency param
415 * (e.g., set_*_lo_offset, set_*_bw)
422 uint32_t freq_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20)
423 uint32_t freq_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20)
427 * ================================================================
428 * union of all of subpacket types
429 * ================================================================
433 op_generic_t op_generic;
434 op_id_reply_t op_id_reply;
435 op_start_rx_streaming_t op_start_rx_streaming;
436 op_burn_mac_addr_t op_burn_mac_addr;
437 op_read_time_reply_t op_read_time_reply;
438 op_config_rx_v2_t op_config_rx_v2;
439 op_config_rx_reply_v2_t op_config_rx_reply_v2;
440 op_config_tx_v2_t op_config_tx_v2;
441 op_config_tx_reply_v2_t op_config_tx_reply_v2;
442 op_config_mimo_t op_config_mimo;
452 #endif /* INCLUDED_USRP2_ETH_PACKET_H */