Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ethernet memory handling issues on CM3DS #11843

Merged
merged 3 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Arm Limited
* Copyright (c) 2019 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -76,6 +76,7 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input()
{
emac_mem_buf_t *p = NULL;
uint32_t message_length = 0;
uint32_t received_bytes = 0;

message_length = smsc9220_peek_next_packet_size(dev);
if (message_length == 0) {
Expand All @@ -87,12 +88,20 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input()
message_length -= CRC_LENGTH_BYTES;
}

p = _memory_manager->alloc_heap(message_length, SMSC9220_BUFF_ALIGNMENT);
p = _memory_manager->alloc_heap(SMSC9220_ETH_MAX_FRAME_SIZE,
SMSC9220_BUFF_ALIGNMENT);

if (p != NULL) {
_RXLockMutex.lock();
smsc9220_receive_by_chunks(dev, (char*)_memory_manager->get_ptr(p),
_memory_manager->get_len(p));
received_bytes = smsc9220_receive_by_chunks(dev,
(char*)_memory_manager->get_ptr(p),
_memory_manager->get_len(p));
if(received_bytes == 0){
_memory_manager->free(p);
kjbracey marked this conversation as resolved.
Show resolved Hide resolved
p = nullptr;
} else {
_memory_manager->set_len(p, received_bytes);
}
_RXLockMutex.unlock();
}

Expand Down Expand Up @@ -169,12 +178,8 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf)
(const char*)_memory_manager->get_ptr(buf),
_memory_manager->get_len(buf));
_memory_manager->free(buf);
if (error != SMSC9220_ERROR_NONE) {
_TXLockMutex.unlock();
return false;
}
_TXLockMutex.unlock();
return true;
return (error == SMSC9220_ERROR_NONE)
kjbracey marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -190,7 +195,7 @@ void SMSC9220_EMAC::link_status_task()
current_link_status_up = (bool)(phy_basic_status_reg_value &
(1ul << (PHY_REG_BSTATUS_LINK_STATUS_INDEX)));

/* Compare with previous state */
/* Compare with the previous state */
if (current_link_status_up != _prev_link_status_up) {
_emac_link_state_cb(current_link_status_up);
_prev_link_status_up = current_link_status_up;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Arm Limited
* Copyright (c) 2019 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,11 +29,12 @@
*/
#define SMSC9220_ETH_MTU_SIZE 1500U
#define SMSC9220_ETH_IF_NAME "smsc9220"
#define SMSC9220_ETH_MAX_FRAME_SIZE 1522U

/** \brief Defines for receiver thread */
#define FLAG_RX 1U
#define LINK_STATUS_THREAD_PRIORITY (osPriorityNormal)
#define LINK_STATUS_THREAD_STACKSIZE 2048U
#define LINK_STATUS_THREAD_STACKSIZE 512U
#define LINK_STATUS_TASK_PERIOD_MS 200U
#define PHY_STATE_LINK_DOWN false
#define PHY_STATE_LINK_UP true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 ARM Limited
* Copyright (c) 2016-2019 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -166,7 +166,6 @@ enum phy_reg_bctrl_reg_bits_t{
* \brief TX Command A bit definitions
*
*/

#define TX_CMD_DATA_START_OFFSET_BYTES_POS 16U
#define TX_CMD_DATA_START_OFFSET_BYTES_MASK 0x1FU

Expand All @@ -186,7 +185,19 @@ enum tx_command_a_bits_t{
*
*/
enum rx_fifo_status_bits_t{
RX_FIFO_STATUS_ERROR_INDEX = 15U
RX_FIFO_STATUS_CRC_ERROR_INDEX = 1U,
RX_FIFO_STATUS_DRIBBLING_BIT_INDEX = 2U,
RX_FIFO_STATUS_MII_ERROR_INDEX = 3U,
RX_FIFO_STATUS_REC_WD_TIMEOUT_INDEX = 4U,
RX_FIFO_STATUS_FRAME_TYPE_INDEX = 5U,
RX_FIFO_STATUS_COLLISION_SEEN_INDEX = 6U,
RX_FIFO_STATUS_FRAME_TOO_LONG_INDEX = 7U,
RX_FIFO_STATUS_MULTICAST_INDEX = 10U,
RX_FIFO_STATUS_RUNT_FRAME_INDEX = 11U,
RX_FIFO_STATUS_LENGTH_ERROR_INDEX = 12U,
RX_FIFO_STATUS_BROADCAST_FRAME_INDEX = 13U,
RX_FIFO_STATUS_ERROR_INDEX = 15U,
RX_FIFO_STATUS_FILTERING_FAIL_INDEX = 30U,
};
#define RX_FIFO_STATUS_PKT_LENGTH_POS 16U
#define RX_FIFO_STATUS_PKT_LENGTH_MASK 0x3FFFU
Expand Down Expand Up @@ -299,7 +310,7 @@ static void fill_tx_fifo(const struct smsc9220_eth_dev_t* dev,
data += remainder_bytes;

while (size_bytes > 0) {
/* Keep the same endianness in data than in the temp variable */
/* Keep the same endianness in data as in the temp variable */
tx_data_port_tmp_ptr[0] = data[0];
tx_data_port_tmp_ptr[1] = data[1];
tx_data_port_tmp_ptr[2] = data[2];
Expand All @@ -323,7 +334,7 @@ static void empty_rx_fifo(const struct smsc9220_eth_dev_t* dev,
size_bytes -= remainder_bytes;

while (size_bytes > 0) {
/* Keep the same endianness in data than in the temp variable */
/* Keep the same endianness in data as in the temp variable */
rx_data_port_tmp = register_map->rx_data_port;
data[0] = rx_data_port_tmp_ptr[0];
data[1] = rx_data_port_tmp_ptr[1];
Expand Down Expand Up @@ -740,7 +751,6 @@ int smsc9220_check_id(const struct smsc9220_eth_dev_t* dev)
return ((GET_BIT_FIELD(id, CHIP_ID_MASK, CHIP_ID_POS) == CHIP_ID) ? 0 : 1);
}


void smsc9220_enable_interrupt(const struct smsc9220_eth_dev_t* dev,
enum smsc9220_interrupt_source source)
{
Expand Down Expand Up @@ -817,7 +827,6 @@ enum smsc9220_error_t smsc9220_read_mac_address(
return SMSC9220_ERROR_PARAM;
}

/* Read current mac address. */
if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_ADDRH, &mac_high)) {
return SMSC9220_ERROR_INTERNAL;
}
Expand Down Expand Up @@ -947,10 +956,7 @@ enum smsc9220_error_t smsc9220_send_by_chunks(
{
struct smsc9220_eth_reg_map_t* register_map =
(struct smsc9220_eth_reg_map_t*)dev->cfg->base;

/* signing this is the first segment of the packet to be sent */
bool is_first_segment = false;
/* signing this is the last segment of the packet to be sent */
bool is_last_segment = false;
uint32_t txcmd_a, txcmd_b = 0;
uint32_t tx_buffer_free_space = 0;
Expand Down Expand Up @@ -1029,7 +1035,6 @@ uint32_t smsc9220_get_rxfifo_data_used_space(const struct
uint32_t smsc9220_receive_by_chunks(const struct smsc9220_eth_dev_t* dev,
char *data, uint32_t dlen)
{

uint32_t rxfifo_inf = 0;
uint32_t rxfifo_stat = 0;
uint32_t packet_length_byte = 0;
Expand Down
Loading