Skip to content

Commit f61979a

Browse files
authored
Merge pull request #11843 from kapi90/master
Fix ethernet memory handling issues on CM3DS
2 parents 09c2450 + 4dd7712 commit f61979a

File tree

4 files changed

+79
-72
lines changed

4 files changed

+79
-72
lines changed

features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Arm Limited
2+
* Copyright (c) 2019 Arm Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,6 +76,7 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input()
7676
{
7777
emac_mem_buf_t *p = NULL;
7878
uint32_t message_length = 0;
79+
uint32_t received_bytes = 0;
7980
8081
message_length = smsc9220_peek_next_packet_size(dev);
8182
if (message_length == 0) {
@@ -87,12 +88,20 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input()
8788
message_length -= CRC_LENGTH_BYTES;
8889
}
8990
90-
p = _memory_manager->alloc_heap(message_length, SMSC9220_BUFF_ALIGNMENT);
91+
p = _memory_manager->alloc_heap(SMSC9220_ETH_MAX_FRAME_SIZE,
92+
SMSC9220_BUFF_ALIGNMENT);
9193
9294
if (p != NULL) {
9395
_RXLockMutex.lock();
94-
smsc9220_receive_by_chunks(dev, (char*)_memory_manager->get_ptr(p),
95-
_memory_manager->get_len(p));
96+
received_bytes = smsc9220_receive_by_chunks(dev,
97+
(char*)_memory_manager->get_ptr(p),
98+
_memory_manager->get_len(p));
99+
if(received_bytes == 0){
100+
_memory_manager->free(p);
101+
p = nullptr;
102+
} else {
103+
_memory_manager->set_len(p, received_bytes);
104+
}
96105
_RXLockMutex.unlock();
97106
}
98107
@@ -169,12 +178,8 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf)
169178
(const char*)_memory_manager->get_ptr(buf),
170179
_memory_manager->get_len(buf));
171180
_memory_manager->free(buf);
172-
if (error != SMSC9220_ERROR_NONE) {
173-
_TXLockMutex.unlock();
174-
return false;
175-
}
176181
_TXLockMutex.unlock();
177-
return true;
182+
return (error == SMSC9220_ERROR_NONE);
178183
}
179184
}
180185
@@ -190,7 +195,7 @@ void SMSC9220_EMAC::link_status_task()
190195
current_link_status_up = (bool)(phy_basic_status_reg_value &
191196
(1ul << (PHY_REG_BSTATUS_LINK_STATUS_INDEX)));
192197
193-
/* Compare with previous state */
198+
/* Compare with the previous state */
194199
if (current_link_status_up != _prev_link_status_up) {
195200
_emac_link_state_cb(current_link_status_up);
196201
_prev_link_status_up = current_link_status_up;

features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac_config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Arm Limited
2+
* Copyright (c) 2019 Arm Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,11 +29,12 @@
2929
*/
3030
#define SMSC9220_ETH_MTU_SIZE 1500U
3131
#define SMSC9220_ETH_IF_NAME "smsc9220"
32+
#define SMSC9220_ETH_MAX_FRAME_SIZE 1522U
3233

3334
/** \brief Defines for receiver thread */
3435
#define FLAG_RX 1U
3536
#define LINK_STATUS_THREAD_PRIORITY (osPriorityNormal)
36-
#define LINK_STATUS_THREAD_STACKSIZE 2048U
37+
#define LINK_STATUS_THREAD_STACKSIZE 512U
3738
#define LINK_STATUS_TASK_PERIOD_MS 200U
3839
#define PHY_STATE_LINK_DOWN false
3940
#define PHY_STATE_LINK_UP true

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2018 ARM Limited
2+
* Copyright (c) 2016-2019 Arm Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -166,7 +166,6 @@ enum phy_reg_bctrl_reg_bits_t{
166166
* \brief TX Command A bit definitions
167167
*
168168
*/
169-
170169
#define TX_CMD_DATA_START_OFFSET_BYTES_POS 16U
171170
#define TX_CMD_DATA_START_OFFSET_BYTES_MASK 0x1FU
172171

@@ -186,7 +185,19 @@ enum tx_command_a_bits_t{
186185
*
187186
*/
188187
enum rx_fifo_status_bits_t{
189-
RX_FIFO_STATUS_ERROR_INDEX = 15U
188+
RX_FIFO_STATUS_CRC_ERROR_INDEX = 1U,
189+
RX_FIFO_STATUS_DRIBBLING_BIT_INDEX = 2U,
190+
RX_FIFO_STATUS_MII_ERROR_INDEX = 3U,
191+
RX_FIFO_STATUS_REC_WD_TIMEOUT_INDEX = 4U,
192+
RX_FIFO_STATUS_FRAME_TYPE_INDEX = 5U,
193+
RX_FIFO_STATUS_COLLISION_SEEN_INDEX = 6U,
194+
RX_FIFO_STATUS_FRAME_TOO_LONG_INDEX = 7U,
195+
RX_FIFO_STATUS_MULTICAST_INDEX = 10U,
196+
RX_FIFO_STATUS_RUNT_FRAME_INDEX = 11U,
197+
RX_FIFO_STATUS_LENGTH_ERROR_INDEX = 12U,
198+
RX_FIFO_STATUS_BROADCAST_FRAME_INDEX = 13U,
199+
RX_FIFO_STATUS_ERROR_INDEX = 15U,
200+
RX_FIFO_STATUS_FILTERING_FAIL_INDEX = 30U,
190201
};
191202
#define RX_FIFO_STATUS_PKT_LENGTH_POS 16U
192203
#define RX_FIFO_STATUS_PKT_LENGTH_MASK 0x3FFFU
@@ -299,7 +310,7 @@ static void fill_tx_fifo(const struct smsc9220_eth_dev_t* dev,
299310
data += remainder_bytes;
300311

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

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

743-
744754
void smsc9220_enable_interrupt(const struct smsc9220_eth_dev_t* dev,
745755
enum smsc9220_interrupt_source source)
746756
{
@@ -817,7 +827,6 @@ enum smsc9220_error_t smsc9220_read_mac_address(
817827
return SMSC9220_ERROR_PARAM;
818828
}
819829

820-
/* Read current mac address. */
821830
if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_ADDRH, &mac_high)) {
822831
return SMSC9220_ERROR_INTERNAL;
823832
}
@@ -947,10 +956,7 @@ enum smsc9220_error_t smsc9220_send_by_chunks(
947956
{
948957
struct smsc9220_eth_reg_map_t* register_map =
949958
(struct smsc9220_eth_reg_map_t*)dev->cfg->base;
950-
951-
/* signing this is the first segment of the packet to be sent */
952959
bool is_first_segment = false;
953-
/* signing this is the last segment of the packet to be sent */
954960
bool is_last_segment = false;
955961
uint32_t txcmd_a, txcmd_b = 0;
956962
uint32_t tx_buffer_free_space = 0;
@@ -1029,7 +1035,6 @@ uint32_t smsc9220_get_rxfifo_data_used_space(const struct
10291035
uint32_t smsc9220_receive_by_chunks(const struct smsc9220_eth_dev_t* dev,
10301036
char *data, uint32_t dlen)
10311037
{
1032-
10331038
uint32_t rxfifo_inf = 0;
10341039
uint32_t rxfifo_stat = 0;
10351040
uint32_t packet_length_byte = 0;

0 commit comments

Comments
 (0)