spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
scamp-nn.c File Reference

NN packet handling for SC&MP. More...

#include <stdlib.h>
#include "spinnaker.h"
#include "sark.h"
#include "scamp.h"

Data Structures

struct  nn_desc_t
 Nearest neighbour protocol state. More...
 

Macros

#define BC_TABLE_SIZE   16
 Number of packets to allocate for the nearest neighbour protocols.
 
#define PART_ID   (CHIP_ID_CODE & 0xfff00000)
 Device identifier (0x591 << 28, for SpiNNaker)
 
#define P2PB_STOP_BIT   0x400
 Set to stop propagation.
 

Enumerations

enum  ff_states { FF_ST_IDLE = 0 , FF_ST_EXBLK = 1 , FF_ST_INBLK = 2 }
 Flood fill states. More...
 
enum  sig0_operations {
  SIG0_FWD_RTRY , SIG0_LEDS , SIG0_GTP , SIG0_ID ,
  SIG0_LEVEL , SIG0_APP , SIG0_TP , SIG0_RST ,
  SIG0_DOWN , SIG0_UP
}
 Operation codes for nn_cmd_sig0() More...
 
enum  sig1_operations { SIG1_WRITE }
 Operation codes for nn_cmd_sig1() More...
 

Functions

void send_nn_links (uint)
 
void nn_init (void)
 Initialise the nearest-neighbour data structures.
 
void compute_eth (void)
 Computes where our board's ethernet chip is.
 
void peek_ack_pkt (uint link, uint data, uint key)
 Initialises peek_pkt to contain the given arguments (presumably an acknowledge)
 
void poke_ack_pkt (uint link, uint data, uint key)
 Initialises poke_pkt to contain the given arguments (presumably an acknowledge)
 
uint link_read_word (uint addr, uint link, uint *buf, uint timeout)
 Read a word from the chip (or device) over a link.
 
uint link_write_word (uint addr, uint link, uint *buf, uint timeout)
 Write a word to the chip (or device) over a link.
 
pkt_buf_tpkt_buf_get (void)
 Allocate a packet (getting one from the free list, pkt_buf_list).
 
void pkt_buf_free (pkt_buf_t *pkt)
 Add packet to free list (pkt_buf_list), "freeing" it.
 
void nn_mark (uint key)
 Mark an ID as discovered.
 
static void nn_cmd_rtrc (uint data)
 Write the Router Control Register.
 
uint nn_cmd_sig0 (uint data)
 SIG0 does simple commands whose data fits into 28 bits.
 
static void nn_cmd_mem (uint data, uint key)
 Memory write operations.
 
void nn_cmd_sig1 (uint data, uint key)
 SIG1 does simple commands with a payload whose control fits in 20 bits.
 
static uint nn_cmd_p2pb (uint id, uint data, uint link)
 P2P Broadcast, used to propagate P2P addresses and maintain the P2P routing table.
 
static void proc_pkt_bc (uint i_pkt, uint count)
 Nearest neighbour packet broadcast handler.
 
void nn_rcv_pkt (uint link, uint data, uint key)
 Nearest-neighbour packet received handler.
 
Flood fill
uint next_id (void)
 Get the next flood-fill identifier we should use.
 
void ff_nn_send (uint key, uint data, uint fwd_rty, uint add_id)
 Flood fill NN packet sender.
 
static void nn_cmd_ffs (uint data, uint key)
 Flood fill start.
 
static uint nn_cmd_ffcs (uint data, uint key)
 Flood fill core select.
 
static uint nn_cmd_fbs (uint id, uint data, uint key)
 Flood fill block start.
 
static uint nn_cmd_fbd (uint id, uint data, uint key)
 Flood fill block data.
 
static uint nn_cmd_fbe (uint id, uint data, uint key)
 Flood fill block end.
 
static uint nn_cmd_ffe (uint id, uint data, uint key)
 Flood fill end.
 
Board information flood fill
uint next_biff_id (void)
 Get the next board info flood-fill identifier we should use.
 
void biff_nn_send (uint data)
 Board information flood fill packet sender.
 
void nn_cmd_biff (uint x, uint y, uint data)
 Board information flood fill command handler.
 
void nn_rcv_biff_pct (uint link, uint data, uint key)
 
void send_nn_netinit (uint netinit_level)
 
P2PC
void p2pc_addr_nn_send (uint arg1, uint arg2)
 Transmit our current best guess of coordinates to all neighbouring chips.
 
void p2pc_new_nn_send (uint x, uint y)
 Broadcast the existence of a new P2P coordinate having been discovered.
 
void p2pc_dims_nn_send (uint arg1, uint arg2)
 Transmit our current best guess of coordinates to all neighbouring chips.
 
void p2pc_reth_nn_send (uint eth, uint arg2)
 Transmit our address back to an Ethernet.
 
void p2pb_nn_send (uint arg1, uint arg2)
 Transmit "P2PB" table generating packets.
 
static void nn_rcv_p2pc_addr_pct (uint link, uint data, uint key)
 Update our current best guess of our coordinates based on a packet from a neighbour.
 
static void nn_rcv_p2pc_new_pct (uint link, uint data, uint key)
 A new P2P coordinate has been broadcast to us.
 
static void nn_rcv_p2pc_dims_pct (uint link, uint data, uint key)
 A neighbour has reported their P2P coordinates to us.
 
static void nn_rcv_p2pc_reth_pct (uint link, uint data, uint key)
 A P2P address to link back to Ethernet has been sent.
 
void nn_rcv_p2pc_pct (uint link, uint data, uint key)
 Handle P2PC packet.
 

Variables

pkt_buf_t pkt_buf_table [BC_TABLE_SIZE]
 Storage for packets used in pkt_buf_list.
 
pkt_buf_tpkt_buf_list
 Free list of packets.
 
uint pkt_buf_count
 Number of packets (in pkt_buf_table) not on free list (pkt_buf_list)
 
uint pkt_buf_max
 Statistics: maximum value of pkt_buf_count.
 
uinthop_table
 Table "hop_table" has entries of type (id << 24, hops) for each possible P2P address.
 
uchar core_app [MAX_CPUS]
 What application (or at least AppID) is running on each core.
 
uint app_mask [256]
 Unused?
 
static nn_desc_t nn_desc
 Nearest neighbour protocol state.
 
pkt_buf_t peek_pkt
 Packet reserved for performing P2P peeks.
 
pkt_buf_t poke_pkt
 Packet reserved for performing P2P pokes.
 
uint mon_del = 0
 delegate blacklisted monitor
 
volatile uint neighbour_netinit_level [NUM_LINKS]
 neighbour over link netinit level
 
volatile uint neighbour_links_enabled [NUM_LINKS]
 neighbour over link links enabled
 
uint pp_ping_count [NUM_LINKS]
 
uint mc_ping_count [NUM_LINKS]
 Reserved for performing MC and P2P pings.
 
char eth_map [12][12]
 Local ethernet chip locator map.
 
Level deltas

Given a packet arriving from a given direction which is labelled with an X and Y coordinate, gives the dx, dy to get the current chip's coordinate.

const signed char lx [6] = {-1, -1, 0, +1, +1, 0}
 X deltas, by link ID.
 
const signed char ly [6] = { 0, -1, -1, 0, +1, +1}
 Y deltas, by link ID.
 

Detailed Description

NN packet handling for SC&MP.

Author
Steve Temple, APT Group, School of Computer Science

Data Structure Documentation

◆ nn_desc_t

struct nn_desc_t

Nearest neighbour protocol state.

Data Fields
uchar state FF state (see ff_states enum)
uchar error Error flag.
uchar forward Rebroadcast code.
uchar retry Rebroadcast retry.
uchar id ID of current FF.
uchar block_len Block length.
uchar block_count Block count.
uchar block_num Block number.
uchar app_id AppID.
uchar load Whether to load locally.
ushort srce_addr P2P of sender.
ushort word_len Number of words in block.
ushort word_count Count of received words.
uint gidr_id GIDR ID.
uint sum Checksum.
uint cores Selected cores to load.
uint * aplx_addr APLX block addr.
uint load_addr Block load base.
uint id_set[4] ID bitmap (128 bits)
uint biff_id_set[4] Board-level flood-fill ID bitmap (128 bits)
uint fbs_set[8] Block bitmap for FBS (must be >= 8 words)
uint fbd_set[8] Word bitmap for FBD (must be >= 8 words)
uint fbe_set[8] Block bitmap for FBE (must be >= 8 words)
uint stats[16] Counters for each packet type.
uint errors Counter for bad checksums.
uint buf[SDP_BUF_SIZE/4] Holding buffer.
uint64 last_ffcs Index of the last FFCS packet.

Enumeration Type Documentation

◆ ff_states

enum ff_states

Flood fill states.

Enumerator
FF_ST_IDLE 

Doing nothing.

FF_ST_EXBLK 

Rcvd FFS or FBE, awaiting FBS, FFE.

FF_ST_INBLK 

Rcvd FBS, awaiting FBD, FBE.

◆ sig0_operations

Operation codes for nn_cmd_sig0()

Enumerator
SIG0_FWD_RTRY 

Set forward and retry.

SIG0_LEDS 

Set LEDs (call sark_led_set())

SIG0_GTP 

Global Time Phase.

SIG0_ID 

ID set/reset.

SIG0_LEVEL 

Trigger level_config() _(unimplemented)_.

SIG0_APP 

Signal application (call signal_app())

SIG0_TP 

Router time phase period _(unimplemented)_.

SIG0_RST 

Shut down APs _(unimplemented)_.

SIG0_DOWN 

Minimum power mode _(unimplemented)_.

SIG0_UP 

Operational mode _(unimplemented)_.

◆ sig1_operations

Operation codes for nn_cmd_sig1()

Enumerator
SIG1_WRITE 

Memory write.

Function Documentation

◆ peek_ack_pkt()

void peek_ack_pkt ( uint  link,
uint  data,
uint  key 
)

Initialises peek_pkt to contain the given arguments (presumably an acknowledge)

Parameters
[in]linkWhich link to send the packet on
[in]dataThe payload of the packet
[in]keyThe key of the packet

◆ poke_ack_pkt()

void poke_ack_pkt ( uint  link,
uint  data,
uint  key 
)

Initialises poke_pkt to contain the given arguments (presumably an acknowledge)

Parameters
[in]linkWhich link to send the packet on
[in]dataThe payload of the packet
[in]keyThe key of the packet

◆ link_read_word()

uint link_read_word ( uint  addr,
uint  link,
uint buf,
uint  timeout 
)

Read a word from the chip (or device) over a link.

Parameters
[in]addrThe address to read from
[in]linkThe link to use
[out]bufThe data that has been read (4 byte buffer)
[in]timeoutHow long to wait for the other side to respond
Returns
result code

◆ link_write_word()

uint link_write_word ( uint  addr,
uint  link,
uint buf,
uint  timeout 
)

Write a word to the chip (or device) over a link.

Parameters
[in]addrThe address to write to
[in]linkThe link to use
[in]bufThe data that is to be written (buffer containing 4 bytes)
[in]timeoutHow long to wait for the other side to respond
Returns
result code

◆ pkt_buf_get()

pkt_buf_t * pkt_buf_get ( void  )

Allocate a packet (getting one from the free list, pkt_buf_list).

Returns
The allocated packet, or NULL if none available

◆ pkt_buf_free()

void pkt_buf_free ( pkt_buf_t pkt)

Add packet to free list (pkt_buf_list), "freeing" it.

Parameters
[in]pktPacket to free.

◆ next_id()

uint next_id ( void  )

Get the next flood-fill identifier we should use.

Returns
A new flood fill ID (range: 2–254)

◆ next_biff_id()

uint next_biff_id ( void  )

Get the next board info flood-fill identifier we should use.

Returns
A new flood fill ID (range: 2–254)

◆ nn_mark()

void nn_mark ( uint  key)

Mark an ID as discovered.

Parameters
[in]keyThe key from the NN packet

◆ ff_nn_send()

void ff_nn_send ( uint  key,
uint  data,
uint  fwd_rty,
uint  add_id 
)

Flood fill NN packet sender.

Parameters
[in]keyThe key to use
[in]dataThe data to use
[in]fwd_rtyForward/delay/retry configuration
[in]add_idWhether to merge the next_id() result into the key

◆ biff_nn_send()

void biff_nn_send ( uint  data)

Board information flood fill packet sender.

Note
Should only be called on chips which are at position (0, 0) on their board.
Parameters
[in]dataThe payload of the packet to send.

◆ p2pc_addr_nn_send()

void p2pc_addr_nn_send ( uint  arg1,
uint  arg2 
)

Transmit our current best guess of coordinates to all neighbouring chips.

Parameters
arg1unused
arg2unused

◆ p2pc_new_nn_send()

void p2pc_new_nn_send ( uint  x,
uint  y 
)

Broadcast the existence of a new P2P coordinate having been discovered.

Parameters
[in]xX coordinate
[in]yY coordinate

◆ p2pc_dims_nn_send()

void p2pc_dims_nn_send ( uint  arg1,
uint  arg2 
)

Transmit our current best guess of coordinates to all neighbouring chips.

Parameters
arg1unused
arg2unused

◆ p2pc_reth_nn_send()

void p2pc_reth_nn_send ( uint  eth,
uint  arg2 
)

Transmit our address back to an Ethernet.

Parameters
ethThe Ethernet address to send to
arg2unused

◆ p2pb_nn_send()

void p2pb_nn_send ( uint  arg1,
uint  arg2 
)

Transmit "P2PB" table generating packets.

Parameters
arg1unused
arg2unused

◆ nn_rcv_p2pc_addr_pct()

static void nn_rcv_p2pc_addr_pct ( uint  link,
uint  data,
uint  key 
)
static

Update our current best guess of our coordinates based on a packet from a neighbour.

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_rcv_p2pc_new_pct()

static void nn_rcv_p2pc_new_pct ( uint  link,
uint  data,
uint  key 
)
static

A new P2P coordinate has been broadcast to us.

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_rcv_p2pc_dims_pct()

static void nn_rcv_p2pc_dims_pct ( uint  link,
uint  data,
uint  key 
)
static

A neighbour has reported their P2P coordinates to us.

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_rcv_p2pc_reth_pct()

static void nn_rcv_p2pc_reth_pct ( uint  link,
uint  data,
uint  key 
)
static

A P2P address to link back to Ethernet has been sent.

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_rcv_p2pc_pct()

void nn_rcv_p2pc_pct ( uint  link,
uint  data,
uint  key 
)

Handle P2PC packet.

Delegates to:

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_cmd_rtrc()

static void nn_cmd_rtrc ( uint  data)
static

Write the Router Control Register.

Parameters
[in]datapayload from the NN packet. Various fields may be selected using 'spare' bits in the word. The field is updated if the bit is set.
bit 5 — Wait2
bit 4 — Wait1
bit 3 — W bit
bit 2 — MP field
bit 1 — TP field

◆ nn_cmd_sig0()

uint nn_cmd_sig0 ( uint  data)

SIG0 does simple commands whose data fits into 28 bits.

Delegates to:

  • sark_led_set()
  • level_config()
  • signal_app()
    Parameters
    [in]dataThe message payload
    Returns
    0 if packet should not be propagated, 1 otherwise.

◆ nn_cmd_mem()

static void nn_cmd_mem ( uint  data,
uint  key 
)
static

Memory write operations.

Parameters
[in]dataThe data to write
[in]keyThe key from the NN packet. Encodes where to write relative to (sv, sysram, sc, or sv_t::mem_ptr), what the offset should be, and how much to write (1, 2 or 4 bytes).

◆ nn_cmd_sig1()

void nn_cmd_sig1 ( uint  data,
uint  key 
)

SIG1 does simple commands with a payload whose control fits in 20 bits.

Delegates to:

  • nn_cmd_mem()
    Parameters
    [in]dataThe payload from the NN packet
    [in]keyThe key from the NN packet

◆ nn_cmd_p2pb()

static uint nn_cmd_p2pb ( uint  id,
uint  data,
uint  link 
)
static

P2P Broadcast, used to propagate P2P addresses and maintain the P2P routing table.

Table "hop_table" has entries of type (id << 24, hops) for each possible P2P address. Field "hops" contains the number of hops to the address (initialised to 65535) and "id" contains the ID of the last packet used to update the table (initialised to 128).

An update occurs when a packet with a lower hop count than the current one arrives via an enabled link. The link on which the packet arrived is used to update the P2P routing table.

Parameters
[in]idThe ID from the key of the packet
[in]dataThe payload of the packet
[in]linkWhat route the packet came from
Returns
data, with P2P_STOP_BIT set if the packet should not be propagated

◆ nn_cmd_ffs()

static void nn_cmd_ffs ( uint  data,
uint  key 
)
static

Flood fill start.

Parameters
[in]dataThe payload of the packet
[in]keyThe key of the packet

◆ nn_cmd_ffcs()

static uint nn_cmd_ffcs ( uint  data,
uint  key 
)
static

Flood fill core select.

Parameters
[in]dataThe payload of the packet
[in]keyThe key of the packet
Returns
1 if the packet should not be propagated further

◆ nn_cmd_fbs()

static uint nn_cmd_fbs ( uint  id,
uint  data,
uint  key 
)
static

Flood fill block start.

Parameters
[in]idThe ID from the key of the packet
[in]dataThe payload of the packet
[in]keyThe key of the packet
Returns
1 if the packet should not be propagated further

◆ nn_cmd_fbd()

static uint nn_cmd_fbd ( uint  id,
uint  data,
uint  key 
)
static

Flood fill block data.

Parameters
[in]idThe ID from the key of the packet
[in]dataThe payload of the packet
[in]keyThe key of the packet
Returns
1 if the packet should not be propagated further

◆ nn_cmd_fbe()

static uint nn_cmd_fbe ( uint  id,
uint  data,
uint  key 
)
static

Flood fill block end.

Parameters
[in]idThe ID from the key of the packet
[in]dataThe payload of the packet
[in]keyThe key of the packet
Returns
1 if the packet should not be propagated further

◆ nn_cmd_ffe()

static uint nn_cmd_ffe ( uint  id,
uint  data,
uint  key 
)
static

Flood fill end.

Parameters
[in]idThe ID from the key of the packet
[in]dataThe payload of the packet
[in]keyThe key of the packet
Returns
1 if the packet should not be propagated further

◆ proc_pkt_bc()

static void proc_pkt_bc ( uint  i_pkt,
uint  count 
)
static

Nearest neighbour packet broadcast handler.

Parameters
[in]i_pkt(Type-punned) pkt_buf_t pointer
[in]countNumber of times to try; should be at least 1

◆ nn_cmd_biff()

void nn_cmd_biff ( uint  x,
uint  y,
uint  data 
)

Board information flood fill command handler.

Can be invoked directly during setup, or in response to a BIFF message.

Parameters
[in]xThe believed X coordinate
[in]yThe believed Y coordinate
[in]dataThe payload word from the message

◆ nn_rcv_biff_pct()

void nn_rcv_biff_pct ( uint  link,
uint  data,
uint  key 
)

Board info flood fill packet receiver

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

◆ nn_rcv_pkt()

void nn_rcv_pkt ( uint  link,
uint  data,
uint  key 
)

Nearest-neighbour packet received handler.

Parameters
[in]linkWhat link was the packet received on
[in]dataThe payload from the packet
[in]keyThe key from the packet

Variable Documentation

◆ hop_table

uint* hop_table

Table "hop_table" has entries of type (id << 24, hops) for each possible P2P address.

Field "hops" contains the number of hops to the address (initialised to 65535) and "id" contains the ID of the last packet used to update the table (initialised to 128). These are packed into a word.

Stored in SYSRAM so visible to all cores. Should only be updated by SCAMP

◆ eth_map

char eth_map[12][12]
Initial value:
= {
{0x00, 0x10, 0x20, 0x30, 0x40, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74},
{0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75},
{0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x36, 0x46, 0x56, 0x66, 0x76},
{0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, 0x47, 0x57, 0x67, 0x77},
{0x40, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, 0x00, 0x10, 0x20, 0x30},
{0x41, 0x51, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, 0x01, 0x11, 0x21, 0x31},
{0x42, 0x52, 0x62, 0x36, 0x46, 0x56, 0x66, 0x76, 0x02, 0x12, 0x22, 0x32},
{0x43, 0x53, 0x63, 0x73, 0x47, 0x57, 0x67, 0x77, 0x03, 0x13, 0x23, 0x33},
{0x44, 0x54, 0x64, 0x74, 0x00, 0x10, 0x20, 0x30, 0x40, 0x14, 0x24, 0x34},
{0x45, 0x55, 0x65, 0x75, 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x25, 0x35},
{0x46, 0x56, 0x66, 0x76, 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x36},
{0x47, 0x57, 0x67, 0x77, 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73}
}

Local ethernet chip locator map.

Given a P2P address, compute P2P address of chip with Ethernet interface on same PCB. Table is for standard 48-chip boards only. Will work with 4-chip boards - may not work for more exotic combinations! Also computes the position of the chip on the PCB as offset from (0,0)

Each byte in this table is a pair of X,Y values which are subtracted from a P2P address to give the address of the Ethernet-attached chip on the same 48-chip PCB.