From 04aaf88f01e49082f41e2a811c370138a1364307 Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:21:46 +1000
Subject: [PATCH 01/23] Remove stacking source files
---
ZodiacFX/src/command.c | 1 -
ZodiacFX/src/main.c | 1 -
ZodiacFX/src/openflow/openflow.c | 1 -
ZodiacFX/src/stacking.c | 642 -------------------------------
ZodiacFX/src/stacking.h | 94 -----
ZodiacFX/src/switch.c | 1 -
6 files changed, 740 deletions(-)
delete mode 100644 ZodiacFX/src/stacking.c
delete mode 100644 ZodiacFX/src/stacking.h
diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index b267f17..3afb6b8 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -38,7 +38,6 @@
#include "eeprom.h"
#include "switch.h"
#include "flash.h"
-#include "stacking.h"
#include "openflow/openflow.h"
#include "openflow/of_helper.h"
#include "lwip/def.h"
diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c
index 07ffcb9..7b1e664 100644
--- a/ZodiacFX/src/main.c
+++ b/ZodiacFX/src/main.c
@@ -42,7 +42,6 @@
#include "command.h"
#include "eeprom.h"
#include "switch.h"
-#include "stacking.h"
#include "http.h"
#include "flash.h"
#include "openflow/openflow.h"
diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c
index 89d320c..c2aed17 100644
--- a/ZodiacFX/src/openflow/openflow.c
+++ b/ZodiacFX/src/openflow/openflow.c
@@ -39,7 +39,6 @@
#include "lwip/tcp.h"
#include "lwip/err.h"
#include "timers.h"
-#include "stacking.h"
// Global variables
extern struct zodiac_config Zodiac_Config;
diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c
deleted file mode 100644
index 6d4fb9f..0000000
--- a/ZodiacFX/src/stacking.c
+++ /dev/null
@@ -1,642 +0,0 @@
-/**
- * @file
- * stacking.c
- *
- * This file contains the stacking functions
- *
- */
-
-/*
- * This file is part of the Zodiac FX firmware.
- * Copyright (c) 2017 Northbound Networks.
- *
- * 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 .
- *
- * Authors: Paul Zanna
- * & Kristopher Chen
- *
- */
-
-#include
-#include
-#include "stacking.h"
-#include "trace.h"
-#include "switch.h"
-#include "lwip/def.h"
-#include "openflow/openflow.h"
-#include "timers.h"
-
-/* SPI clock setting (Hz). */
-static uint32_t gs_ul_spi_clock = 10000000;
-
-/* Chip select. */
-#define SPI_CHIP_SEL 0
-#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL)
-/* Clock polarity. */
-#define SPI_CLK_POLARITY 0
-/* Clock phase. */
-#define SPI_CLK_PHASE 0
-/* Delay before SPCK. */
-#define SPI_DLYBS 0x30
-/* Delay between consecutive transfers. */
-#define SPI_DLYBCT 0x06
-
-// Global variables
-extern uint8_t last_port_status[8];
-extern uint8_t port_status[8];
-extern uint8_t shared_buffer[SHARED_BUFFER_LEN];
-extern uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
-extern int OF_Version;
-extern struct ofp10_port_stats phys10_port_stats[8];
-extern struct ofp13_port_stats phys13_port_stats[8];
-
-// Local variables
-uint16_t spi_slave_send_size;
-int32_t spi_slave_send_count;
-uint8_t timer_alt;
-uint8_t pending_spi_command = SPI_SEND_READY;
-bool master_ready;
-bool slave_ready;
-uint8_t spi_dummy_bytes = 0;
-struct spi_port_stats spi_p_stats;
-uint8_t spi_stats_rr = 0;
-struct spi_packet *spi_packet;
-bool end_check;
-uint8_t spi_receive_port = 0;
-uint16_t spi_receive_count;
-uint32_t rcv_time;
-
-void spi_master_initialize(void);
-void spi_slave_initialize(void);
-void spi_port_stats(void);
-void spi_port_status(void);
-
-struct spi_debug_stats spi_debug;
-
-/*
-* Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper
-*
-*/
-void stacking_init(bool master)
-{
- if (master)
- {
- spi_slave_initialize();
- ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT);
- } else {
- spi_master_initialize();
- ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT);
- }
- return;
-}
-
-/*
-* Initialize the SPI interface as a SLAVE
-*
-*/
-void spi_slave_initialize(void)
-{
- NVIC_DisableIRQ(SPI_IRQn);
- NVIC_ClearPendingIRQ(SPI_IRQn);
- NVIC_SetPriority(SPI_IRQn, 0);
- NVIC_EnableIRQ(SPI_IRQn);
-
- /* Configure an SPI peripheral. */
- spi_enable_clock(SPI_SLAVE_BASE);
- spi_disable(SPI_SLAVE_BASE);
- spi_reset(SPI_SLAVE_BASE);
- spi_set_slave_mode(SPI_SLAVE_BASE);
- spi_disable_mode_fault_detect(SPI_SLAVE_BASE);
- spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL);
- spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
- spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
- spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT);
- spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF);
- spi_enable(SPI_SLAVE_BASE);
- ioport_set_pin_level(SPI_IRQ1, false);
-}
-
-/*
-* Initialize the SPI interface as a MASTER
-*
-*/
-void spi_master_initialize(void)
-{
- uint32_t ul_sysclk_div = sysclk_get_cpu_hz() / gs_ul_spi_clock;
- /* Configure an SPI peripheral. */
- spi_enable_clock(SPI_MASTER_BASE);
- spi_disable(SPI_MASTER_BASE);
- spi_reset(SPI_MASTER_BASE);
- spi_set_lastxfer(SPI_MASTER_BASE);
- spi_set_master_mode(SPI_MASTER_BASE);
- spi_disable_mode_fault_detect(SPI_MASTER_BASE);
- spi_disable_loopback(SPI_MASTER_BASE);
- spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL);
- spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT);
- spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT);
- spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div));
- spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
- spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
-
- spi_enable(SPI_MASTER_BASE);
-}
-
-void Slave_timer(void)
-{
- if (timer_alt == 0)
- {
- spi_port_stats();
- timer_alt = 1;
- return;
- } else if (timer_alt == 1)
- {
- spi_port_status();
- timer_alt = 2;
- return;
- } else if (timer_alt == 2)
- {
- // Send SLAVE port stats if SLAVE is in the clear state
- if (slave_ready == true && pending_spi_command == SPI_SEND_READY)
- {
- spi_p_stats.preamble = SPI_STATS_PREAMBLE;
- spi_p_stats.spi_size = sizeof(struct spi_port_stats);
- memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats));
- ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something
- pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats
- spi_slave_send_size = sizeof(struct spi_port_stats);
- spi_slave_send_count = spi_slave_send_size;
- timer_alt = 0;
- }
- return;
- }
-}
-
-void spi_port_stats(void)
-{
- spi_p_stats.tx_bytes[spi_stats_rr] += readtxbytes(spi_stats_rr+1);
- spi_p_stats.rx_bytes[spi_stats_rr] += readrxbytes(spi_stats_rr+1);
- spi_stats_rr++;
- if (spi_stats_rr == 4) spi_stats_rr = 0;
- return;
-}
-
-void spi_port_status(void)
-{
- // Copy out the old status so we know if it has changed
- spi_p_stats.last_port_status[0] = spi_p_stats.port_status[0];
- spi_p_stats.last_port_status[1] = spi_p_stats.port_status[1];
- spi_p_stats.last_port_status[2] = spi_p_stats.port_status[2];
- spi_p_stats.last_port_status[3] = spi_p_stats.port_status[3];
- // Update port status
- spi_p_stats.port_status[0] = (switch_read(30) & 32) >> 5;
- spi_p_stats.port_status[1] = (switch_read(46) & 32) >> 5;
- spi_p_stats.port_status[2] = (switch_read(62) & 32) >> 5;
- spi_p_stats.port_status[3] = (switch_read(78) & 32) >> 5;
- return;
-}
-
-/*
-* Master ready function
-*
-*/
-void MasterReady(void)
-{
- spi_write(SPI_MASTER_BASE, 0xaa, 0, 0);
- master_ready = true;
- return;
-}
-
-// ##################### SPI MASTER Send and Receive Functions #####################
-
-/*
-* Master send function
-*
-*/
-void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port)
-{
- uint8_t uc_pcs;
- static uint16_t data;
- uint8_t *p_buffer;
- uint8_t outport;
-
- uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0};
-
- if (port < 255)
- {
- outport = port;
- phys10_port_stats[port-1].tx_packets++;
- phys13_port_stats[port-1].tx_packets++;
- } else {
- port = 255;
- if (port_status[4] == 1) phys10_port_stats[4].tx_packets++;
- if (port_status[4] == 1) phys13_port_stats[4].tx_packets++;
- if (port_status[5] == 1) phys10_port_stats[5].tx_packets++;
- if (port_status[5] == 1) phys13_port_stats[5].tx_packets++;
- if (port_status[6] == 1) phys10_port_stats[6].tx_packets++;
- if (port_status[6] == 1) phys13_port_stats[6].tx_packets++;
- if (port_status[7] == 1) phys10_port_stats[7].tx_packets++;
- if (port_status[7] == 1) phys13_port_stats[7].tx_packets++;
- }
- // Prepare header (shared_buffer already contains the packet data)
- spi_packet = &spi_head_buffer;
- spi_packet->preamble = SPI_PACKET_PREAMBLE;
- spi_packet->ul_rcv_size = ul_size;
- spi_packet->spi_crc = 0;
- // Calculate CRC value
- for(int x = 0;xspi_crc += p_uc_data[x];
- }
- spi_packet->tag = port;
- spi_packet->spi_size = SPI_HEADER_SIZE + ul_size;
-
- TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port);
-
- // Send the SPI packet header
- for(uint16_t ct=0; ct>8); // upper 8 bits
-
- spi_write(SPI_MASTER_BASE, 0xbb, 0, 0);
- // MAY CAUSE TIMING PROBLEMS
- if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE)
- {
- if(spi_count == 4)
- {
- spi_read_size = shared_buffer[2] + (shared_buffer[3]*256);
- if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE)
- {
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- }
- }
- }
- spi_count+=2;
- while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0);
- }
- ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time);
-
- TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]);
- if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC)))
- {
- TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE");
- spi_debug.master_rx_error_bad_preamble++;
- return;
- }
-
- if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC)
- {
- /* Process Received SPI Packet */
- spi_crc_rcv = 0;
- spi_packet = &shared_buffer;
- if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX)
- {
- TRACE("stacking.c: ERROR - BAD PACKET SIZE");
- spi_debug.master_rx_error_bad_size++;
- return; // Packet size is corrupt
- }
- for(int x = 0;xul_rcv_size;x++)
- {
- spi_crc_rcv += spi_packet->pkt_buffer[x];
- }
- // Make sure we received the entire packet
- if (spi_packet->spi_crc != spi_crc_rcv)
- {
- TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv);
- spi_debug.master_rx_error_bad_crc++;
- return;
- }
- TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size);
- // Copy packet into Ethernet buffer
- memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX);
- // Update port stats
- phys10_port_stats[spi_packet->tag-1].rx_packets++;
- phys13_port_stats[spi_packet->tag-1].rx_packets++;
- // Send packet to OpenFlow table lookup function for processing
- nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag);
- ////printf("stacking.c: ------- ------- response ok\r\n");
- spi_debug.master_rx_count++;
- return;
- }
- else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB)
- {
- /* Process Received Port Stats */
- TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count);
- memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats));
- port_status[4] = spi_p_stats.port_status[0];
- port_status[5] = spi_p_stats.port_status[1];
- port_status[6] = spi_p_stats.port_status[2];
- port_status[7] = spi_p_stats.port_status[3];
-
- if (OF_Version == 1)
- {
- phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0];
- phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0];
- phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1];
- phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1];
- phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2];
- phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2];
- phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3];
- phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3];
- }
- else if (OF_Version == 4)
- {
- phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0];
- phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0];
- phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1];
- phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1];
- phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2];
- phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2];
- phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3];
- phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3];
- }
- }
- return;
-}
-
-// ##################### SPI SLAVE Send and Receive Functions #####################
-
-/*
-* SPI interface IRQ handler
-* Used to receive data from the stacking interface
-*
-*/
-void SPI_Handler(void)
-{
- static uint16_t data;
- static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE)
- uint8_t uc_pcs;
-
- if (slave_ready == false) // Is this the first data we have received?
- {
- if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
- {
- spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
- if (data == 0xaa)
- {
- ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ
- slave_ready = true;
- }
- return;
- }
- }
-
- if(pending_spi_command == SPI_SEND_PKT || pending_spi_command == SPI_SEND_STATS) // Send data to master
- {
- if (spi_slave_send_count <= 0)
- {
- // Flush out last two bytes
- if (spi_dummy_bytes < 2)
- {
- spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // *****
- spi_dummy_bytes++;
- return;
- }
- pending_spi_command = SPI_SEND_READY; // Clear the pending command
- ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done
- spi_dummy_bytes = 0;
- }
- else
- {
- while(spi_slave_send_count > 0)
- {
- spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0);
- spi_slave_send_count-=2;
- // Wait for master to send the next byte
- uint16_t timeout = 0;
- while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0)
- {
- if(timeout > 100)
- {
- pending_spi_command = SPI_SEND_READY; // Clear the pending command
- ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done
-
- spi_debug.slave_tx_error_timeout++;
- return;
- }
- else
- {
- timeout++;
- }
- }
- spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
- }
- spi_debug.slave_tx_count++;
- }
- return;
- }
-
- if(pending_spi_command == SPI_SEND_READY)
- {
- spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
- if (data == 0xBCBC)
- {
- pending_spi_command = SPI_RECEIVE;
- }
- return;
- }
-
- if(pending_spi_command == SPI_RECEIVE)
- {
- // ***** Modified MASTER -> SLAVE receiver *****
- static uint16_t spi_count = 2;
- static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
-
- // Write preamble to SPI packet header
- shared_buffer[0] = 0xBC;
- shared_buffer[1] = 0xBC;
-
- /***** Receive the rest of the packet *****/
-
- while(spi_count < (spi_read_size-1))
- {
- spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0);
- uint16_t timeout = 0;
- while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0)
- {
- if(timeout > 100)
- {
- pending_spi_command = SPI_SEND_READY; // Clear the pending command
- spi_count = 2;
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- spi_debug.slave_rx_error_timeout++;
- return;
- }
- else
- {
- timeout++;
- }
- }
- spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
-
- shared_buffer[spi_count] = data; // lower 8 bits
- shared_buffer[spi_count+1] = (data>>8); // upper 8 bits
-
- if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4)
- {
- spi_read_size = shared_buffer[2] + (shared_buffer[3]*256);
- if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE)
- {
- // ERROR: over-sized packet data
- // Clean up and return
- pending_spi_command = SPI_SEND_READY;
- spi_count = 2;
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- spi_debug.slave_rx_error_bad_size++;
- return;
- }
- }
-
- // Increment the counter
- spi_count+=2;
- }
-
- /***** Process the received packet *****/
-
- uint32_t spi_crc_rcv = 0;
- spi_packet = &shared_buffer;
-
- // Check against maximum packet size
- if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX)
- {
- // ERROR: payload data too large
- // Clean up and return
- pending_spi_command = SPI_SEND_READY;
- spi_count = 2;
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- spi_debug.slave_rx_error_bad_size++;
- return;
- }
-
- // Calculated CRC of the received data
- for(uint16_t ct=0; ctul_rcv_size; ct++)
- {
- spi_crc_rcv += spi_packet->pkt_buffer[ct];
- }
-
- // Check calculated CRC against received CRC
- if (spi_packet->spi_crc != spi_crc_rcv)
- {
- // ERROR: corrupt packet
- // Clean up and return
- pending_spi_command = SPI_SEND_READY;
- spi_count = 2;
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- spi_debug.slave_rx_error_bad_crc++;
- return;
- }
-
- if (spi_packet->tag == 255)
- {
- gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0);
- }
- else if (spi_packet->tag <= 8)
- {
- gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0);
- }
- // Packet receive complete
- // Clean up and return
- pending_spi_command = SPI_SEND_READY;
- spi_count = 2;
- spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE;
- ////slavemaster_test();
- spi_debug.slave_rx_count++;
- return;
- }
-
-}
-
-// ##################### SPI Test Functions #####################
-
-uint8_t masterslave_test(void)
-{
- uint8_t pattern = 0;
- for(uint16_t i=0;i<1400;i++)
- {
- shared_buffer[i] = pattern++;
- }
- rcv_time = sys_get_ms();
- MasterStackSend(&shared_buffer, 1400, 8);
- return;
-}
-
-uint8_t slavemaster_test(void)
-{
- // Note: the pending check may need to be moved outside of the function call
- if (slave_ready == true && pending_spi_command == SPI_SEND_READY)
- {
- // PREPARE TEST PACKET from SLAVE to MASTER
- spi_packet = &shared_buffer;
- spi_packet->preamble = SPI_PACKET_PREAMBLE;
- spi_packet->ul_rcv_size = 1400;
- spi_packet->spi_crc = 0;
- uint8_t*ind_ptr = &spi_packet->pkt_buffer;
- uint8_t walk = 0;
- for(uint16_t x = 0;x<1400;x++)
- {
- ind_ptr[x] = walk;
- spi_packet->spi_crc += walk;
- walk++;
- }
- spi_packet->tag = 2 + 4;
- spi_packet->spi_size = SPI_HEADER_SIZE + 1400;
- pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet
- spi_slave_send_size = spi_packet->spi_size;
- spi_slave_send_count = spi_slave_send_size;
- ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something
- }
- return;
-}
\ No newline at end of file
diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h
deleted file mode 100644
index 36e0243..0000000
--- a/ZodiacFX/src/stacking.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * @file
- * command.c
- *
- * This file contains the command line functions
- *
- */
-
-/*
- * This file is part of the Zodiac FX firmware.
- * Copyright (c) 2016 Northbound Networks.
- *
- * 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 .
- *
- * Author: Paul Zanna
- *
- *
- */
-
-
-#ifndef STACKING_H_
-#define STACKING_H_
-
-#define SPI_Handler SPI_Handler
-#define SPI_IRQn SPI_IRQn
-
-#define SPI_SEND_READY 0
-#define SPI_SEND_STATS 1
-#define SPI_SEND_PKT 2
-#define SPI_RECEIVE 3
-#define SPI_RCV_PREAMBLE 4
-#define SPI_STATS_PREAMBLE 0xABAB
-#define SPI_PACKET_PREAMBLE 0xBCBC
-#define SPI_SEND_WAIT 0
-#define SPI_HEADER_SIZE 14
-
-struct spi_port_stats {
- uint16_t preamble;
- uint16_t spi_size;
- uint8_t port_status[4];
- uint8_t last_port_status[4];
- uint64_t rx_bytes[4];
- uint64_t tx_bytes[4];
- uint64_t rx_dropped[4];
- uint64_t tx_dropped[4];
-};
-
-struct spi_packet {
- uint16_t preamble; // Transmission preamble
- uint16_t spi_size; // SPI transmission size
- uint32_t ul_rcv_size; // Actual packet size
- uint32_t spi_crc; // Calculated CRC of packet
- uint8_t tag; // Port number (1-8, or 255)
- uint8_t pad; // Pad to 14 bytes
- uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX];
-};
-
-struct spi_debug_stats {
- uint32_t master_tx_count;
- uint32_t master_rx_count;
- uint32_t master_rx_error_bad_preamble;
- uint32_t master_rx_error_bad_size;
- uint32_t master_rx_error_bad_crc;
- uint32_t slave_tx_count;
- uint32_t slave_rx_count;
- uint32_t slave_tx_error_timeout;
- uint32_t slave_rx_error_bad_preamble;
- uint32_t slave_rx_error_bad_size;
- uint32_t slave_rx_error_bad_crc;
- uint32_t slave_rx_error_timeout;
-};
-
-void stacking_init(bool master);
-void MasterReady(void);
-void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port);
-void MasterStackRcv(void);
-void Slave_timer(void);
-
-// ***** Stacking Test Functions *****
-uint8_t masterslave_test(void); // Send pattern from master -> slave
-uint8_t slavemaster_test(void); // Send pattern from slave -> master
-
-#endif /* STACKING_H_ */
\ No newline at end of file
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index fdb8f0a..d323cdd 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -33,7 +33,6 @@
#include "trace.h"
#include "openflow/openflow.h"
#include "switch.h"
-#include "stacking.h"
#include "conf_eth.h"
#include "command.h"
#include "timers.h"
From c7913f511e6784e2b4af13a37a528cf75c0f6210 Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:24:27 +1000
Subject: [PATCH 02/23] Remove CLI SPI debug stats
---
ZodiacFX/src/command.c | 35 -----------------------------------
1 file changed, 35 deletions(-)
diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index 3afb6b8..386b4a7 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -84,9 +84,6 @@ uint8_t uCLIContext = 0;
struct arp_header arp_test;
uint8_t esc_char = 0;
-// ####### SPI debug output #######
-extern struct spi_debug_stats spi_debug;
-
// Internal Functions
void saveConfig(void);
void command_root(char *command, char *param1, char *param2, char *param3);
@@ -1641,12 +1638,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3)
return;
}
- if (strcmp(command, "spi")==0)
- {
- //stack_write(atoi(param1));
- return;
- }
-
if (strcmp(command, "mem")==0)
{
printf("mem total: %d\r\n", membag_get_total());
@@ -1663,32 +1654,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3)
return;
}
- if (strcmp(command, "spi_stats")==0)
- {
- printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\
- spi_debug.master_tx_count,\
- spi_debug.master_rx_count,\
- spi_debug.master_rx_error_bad_size,\
- spi_debug.master_rx_error_bad_preamble,\
- spi_debug.master_rx_error_bad_crc
- );
- return;
- }
-
- if (strcmp(command, "spi_stats_slave")==0)
- {
- printf("slave tx packets: %d\r\nslave rx packets: %d\r\nslave tx timeout errors: %d\r\nslave rx timeout errors: %d\r\nslave rx bad size: %d\r\nslave rx bad preamble: %d\r\nslave rx bad crc: %d\r\n",\
- spi_debug.slave_tx_count,\
- spi_debug.slave_rx_count,\
- spi_debug.slave_tx_error_timeout,\
- spi_debug.slave_rx_error_timeout,\
- spi_debug.slave_rx_error_bad_size,\
- spi_debug.slave_rx_error_bad_preamble,\
- spi_debug.slave_rx_error_bad_crc
- );
- return;
- }
-
// Unknown Command response
printf("Unknown command\r\n");
return;
From 531fc4c1551a2ab81ebd369fc8cae5077953ae12 Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:30:19 +1000
Subject: [PATCH 03/23] Remove stacking tasks
---
ZodiacFX/src/switch.c | 91 +++++++++----------------------------------
ZodiacFX/src/switch.h | 2 -
2 files changed, 18 insertions(+), 75 deletions(-)
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index d323cdd..3fc7978 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -51,8 +51,6 @@ extern uint8_t pending_spi_command;
extern struct spi_packet *spi_packet;
extern bool slave_ready;
extern uint8_t shared_buffer[SHARED_BUFFER_LEN];
-extern uint16_t spi_slave_send_size;
-extern uint16_t spi_slave_send_count;
// Local variables
gmac_device_t gs_gmac_dev;
@@ -62,7 +60,6 @@ struct ofp13_port_stats phys13_port_stats[8];
uint8_t port_status[8];
uint8_t last_port_status[8];
uint8_t total_ports = 4;
-int slave_timer = 0;
uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
uint8_t stats_rr = 0;
@@ -507,32 +504,6 @@ void task_switch(struct netif *netif)
uint8_t tag = 0;
int8_t in_port = 0;
- // Check if the slave device has a packet to send us
- if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true)
- {
- MasterStackRcv();
- }
-
- // Check if the slave device is connected and enable stacking
- if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false)
- {
- MasterReady(); // Let the slave know the master is ready
- stackenabled = true;
- total_ports = 8;
- }
-
- // Slave house keeping timer
- if(masterselect == true)
- {
- if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs)
- {
- slave_timer = sys_get_ms();
- Slave_timer(); // Slave timer
- }
-
- }
-
-
/* Main packet processing loop */
uint32_t dev_read = gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_rcv_size);
if (dev_read == GMAC_OK)
@@ -550,55 +521,29 @@ void task_switch(struct netif *netif)
}
}
- if(masterselect == false) // Only process packets if board is set to MASTER
- {
- if (ul_rcv_size > 0)
- {
- uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1);
- uint8_t tag = *tail_tag + 1;
- if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1)
- {
- phys10_port_stats[tag-1].rx_packets++;
- phys13_port_stats[tag-1].rx_packets++;
- ul_rcv_size--; // remove the tail first
- nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag);
- return;
- } else {
- TRACE("switch.c: %d byte received from controller", ul_rcv_size);
- struct pbuf *p;
- p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL);
- memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1));
- p->len = ul_rcv_size-1;
- p->tot_len = ul_rcv_size-1;
- netif->input(p, netif);
- pbuf_free(p);
- return;
- }
- }
- } else
+ // Process packet
+ if (ul_rcv_size > 0)
{
- if (slave_ready == true && pending_spi_command == SPI_SEND_READY)
+ uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1);
+ uint8_t tag = *tail_tag + 1;
+ if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1)
{
- uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1);
- uint8_t tag = *tail_tag + 1;
phys10_port_stats[tag-1].rx_packets++;
phys13_port_stats[tag-1].rx_packets++;
ul_rcv_size--; // remove the tail first
- spi_packet = &shared_buffer;
- spi_packet->preamble = SPI_PACKET_PREAMBLE;
- spi_packet->ul_rcv_size = ul_rcv_size;
- spi_packet->spi_crc = 0;
- for(int x = 0;xspi_crc += gs_uc_eth_buffer[x];
- }
- spi_packet->tag = tag + 4;
- spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size;
- memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size);
- pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet
- spi_slave_send_size = spi_packet->spi_size;
- spi_slave_send_count = spi_slave_send_size;
- ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something
+ nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag);
+ return;
+ }
+ else
+ {
+ TRACE("switch.c: %d byte received from controller", ul_rcv_size);
+ struct pbuf *p;
+ p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL);
+ memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1));
+ p->len = ul_rcv_size-1;
+ p->tot_len = ul_rcv_size-1;
+ netif->input(p, netif);
+ pbuf_free(p);
return;
}
}
diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h
index f51edb6..33c72aa 100644
--- a/ZodiacFX/src/switch.h
+++ b/ZodiacFX/src/switch.h
@@ -44,8 +44,6 @@ void update_port_stats(void);
void update_port_status(void);
void disableOF(void);
void enableOF(void);
-void stacking_init(bool master);
-void MasterStackRcv(void);
int readtxbytes(int port);
int readrxbytes(int port);
From 734cd2eb8ccdcfcb7cf3bac0145f2837d76e0dbb Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:35:23 +1000
Subject: [PATCH 04/23] Remove stacking initialisations
---
ZodiacFX/src/main.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c
index 7b1e664..bf6d49f 100644
--- a/ZodiacFX/src/main.c
+++ b/ZodiacFX/src/main.c
@@ -130,13 +130,6 @@ int main (void)
board_init();
get_serial(&uid_buf);
- // Set up the GPIO pin for the Mater Select jumper
- ioport_init();
- ioport_set_pin_dir(MASTER_SEL, IOPORT_DIR_INPUT);
-
- masterselect = ioport_get_pin_level(MASTER_SEL); // true = slave
- stacking_init(masterselect); // Initialise the stacking connector as either master or slave
-
irq_initialize_vectors(); // Initialize interrupt vector table support.
cpu_irq_enable(); // Enable interrupts
From 43b1231c2563bdff7fd264fb979e585963279c63 Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:41:20 +1000
Subject: [PATCH 05/23] Revert gmac_write function to dev_80 version
---
ZodiacFX/src/switch.c | 50 +++++++------------------------------------
1 file changed, 8 insertions(+), 42 deletions(-)
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index 3fc7978..63f9e2d 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -314,52 +314,14 @@ void update_port_status(void)
* @param port - the port to send the data out from.
*
*/
-void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport)
+void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port)
{
- TRACE("switch.c: gmac_write to port 0x%X (%d bytes)", port, ul_size);
- // Convert OpenFlow port to physical port number
- if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on
- {
- TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size);
- if(masterselect == false)
- {
- MasterStackSend(p_buffer, ul_size, port); // Send it slave
- if (inport < 5)
- {
- port = (15 - NativePortMatrix) - (1<<(inport-1));
- } else {
- port = 15 - NativePortMatrix;
- }
- } else {
- inport -= 4;
- port = (15 - (1<<(inport-1)));
- }
- } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on
- {
- port = inport;
- TRACE("switch.c: Output to in_port %d (%d bytes)", port, ul_size);
- } else if (port < 5) // Send it out the specified port
- {
- port = 1 << (port-1);
- } else if (port > 4 && port < 128)
- {
- if(masterselect == false) // If we are the master then send to the slave
- {
- TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size);
- MasterStackSend(p_buffer, ul_size, port); // Send it slave
- return;
- }
- // If slave then write to port
- port -= 4;
- port = 1 << (port-1);
- }
-
- TRACE("switch.c: Writing data to switch port matrix %d (%d bytes)", port, ul_size);
if (ul_size > GMAC_FRAME_LENTGH_MAX)
{
return;
}
-
+
+ // Update port stats
if (port & 1) phys10_port_stats[0].tx_packets++;
if (port & 2) phys10_port_stats[1].tx_packets++;
if (port & 4) phys10_port_stats[2].tx_packets++;
@@ -368,6 +330,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport)
if (port & 2) phys13_port_stats[1].tx_packets++;
if (port & 4) phys13_port_stats[2].tx_packets++;
if (port & 8) phys13_port_stats[3].tx_packets++;
+
// Add padding
if (ul_size < 60)
{
@@ -377,7 +340,9 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport)
last_byte = gmacbuffer + 60;
*last_byte = port;
gmac_dev_write(&gs_gmac_dev, &gmacbuffer, 61, NULL);
- } else {
+ }
+ else
+ {
memcpy(&gmacbuffer,p_buffer, ul_size);
uint8_t *last_byte;
last_byte = gmacbuffer + ul_size;
@@ -385,6 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport)
ul_size++; // Increase packet size by 1 to allow for the tail tag.
uint32_t write_size = gmac_dev_write(&gs_gmac_dev, &gmacbuffer, ul_size, NULL);
}
+
return;
}
From 20fe76ec1e2f7e8154f8697be7e762a708e8899d Mon Sep 17 00:00:00 2001
From: Kristopher Chen
Date: Tue, 23 May 2017 10:43:50 +1000
Subject: [PATCH 06/23] Remove stackenabled variable
---
ZodiacFX/src/command.c | 3 ---
ZodiacFX/src/http.c | 15 +--------------
ZodiacFX/src/main.c | 1 -
ZodiacFX/src/openflow/openflow.c | 2 --
ZodiacFX/src/openflow/openflow_10.c | 5 -----
ZodiacFX/src/openflow/openflow_13.c | 5 -----
ZodiacFX/src/switch.c | 1 -
7 files changed, 1 insertion(+), 31 deletions(-)
diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index 386b4a7..f4428c4 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -67,7 +67,6 @@ extern struct table_counter table_counters[MAX_TABLES];
extern struct meter_entry13 *meter_entry[MAX_METER_13];
extern struct meter_band_stats_array band_stats_array[MAX_METER_13];
extern bool masterselect;
-extern bool stackenabled = false;
extern bool trace = false;
extern struct tcp_pcb *tcp_pcb;
extern uint8_t port_status[8];
@@ -558,8 +557,6 @@ void command_config(char *command, char *param1, char *param2, char *param3)
} else {
printf(" Force OpenFlow version: Disabled\r\n");
}
- if (stackenabled == true) printf(" Stacking Status: Enabled\r\n");
- if (stackenabled == false) printf(" Stacking Status: Disabled\r\n");
if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n");
if (Zodiac_Config.ethtype_filter != 1) printf(" EtherType Filtering: Disabled\r\n");
printf("\r\n-------------------------------------------------------------------------\r\n\n");
diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 3e0a9f6..7cef6b4 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -91,8 +91,6 @@ static bool restart_required = false; // Track if any configuration changes are
static bool file_upload = false; // Multi-part firmware file upload flag
static bool post_pending = false;
-extern bool stackenabled;
-
static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err);
void http_send(char *buffer, struct tcp_pcb *pcb, bool out);
@@ -2109,18 +2107,7 @@ static uint8_t interfaceCreate_Home(void)
"CPU Temp: %d C
"\
"Uptime: %02d:%02d
"\
);
- if(stackenabled == true)
- {
- snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\
- "Stacking: enabled"
- );
- }
- else
- {
- snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\
- "Stacking: disabled"
- );
- }
+
if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\
"
"\
""\
"