drivers: ethernet: Fix device instance const qualifier loss
Passing driver's data to k_thread is sufficient for mcux. On enc424j600, however, the device pointer is needed and thus is wrapped into its data. But there seems to be a possible optimisation: all local spi related function in fact only needs the device's data (context) and so changing all spi related function to take the context would remove the need to wrap the device pointer into its data. Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
949b25cf68
commit
a1708cf2f2
|
@ -441,9 +441,8 @@ done:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void enc424j600_rx_thread(const struct device *dev)
|
||||
static void enc424j600_rx_thread(struct enc424j600_runtime *context)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
uint16_t eir;
|
||||
uint16_t estat;
|
||||
uint8_t counter;
|
||||
|
@ -451,28 +450,30 @@ static void enc424j600_rx_thread(const struct device *dev)
|
|||
while (true) {
|
||||
k_sem_take(&context->int_sem, K_FOREVER);
|
||||
|
||||
enc424j600_clear_sfru(dev, ENC424J600_SFR3_EIEL,
|
||||
enc424j600_clear_sfru(context->dev, ENC424J600_SFR3_EIEL,
|
||||
ENC424J600_EIE_INTIE);
|
||||
enc424j600_read_sfru(dev, ENC424J600_SFRX_EIRL, &eir);
|
||||
enc424j600_read_sfru(dev, ENC424J600_SFRX_ESTATL, &estat);
|
||||
enc424j600_read_sfru(context->dev, ENC424J600_SFRX_EIRL, &eir);
|
||||
enc424j600_read_sfru(context->dev,
|
||||
ENC424J600_SFRX_ESTATL, &estat);
|
||||
LOG_DBG("ESTAT: 0x%04x", estat);
|
||||
|
||||
if (eir & ENC424J600_EIR_PKTIF) {
|
||||
counter = (uint8_t)estat;
|
||||
while (counter) {
|
||||
enc424j600_rx(dev);
|
||||
enc424j600_read_sfru(dev,
|
||||
enc424j600_rx(context->dev);
|
||||
enc424j600_read_sfru(context->dev,
|
||||
ENC424J600_SFRX_ESTATL,
|
||||
&estat);
|
||||
counter = (uint8_t)estat;
|
||||
LOG_DBG("ESTAT: 0x%04x", estat);
|
||||
}
|
||||
} else if (eir & ENC424J600_EIR_LINKIF) {
|
||||
enc424j600_clear_sfru(dev, ENC424J600_SFRX_EIRL,
|
||||
enc424j600_clear_sfru(context->dev,
|
||||
ENC424J600_SFRX_EIRL,
|
||||
ENC424J600_EIR_LINKIF);
|
||||
if (estat & ENC424J600_ESTAT_PHYLNK) {
|
||||
LOG_INF("Link up");
|
||||
enc424j600_setup_mac(dev);
|
||||
enc424j600_setup_mac(context->dev);
|
||||
net_eth_carrier_on(context->iface);
|
||||
} else {
|
||||
LOG_INF("Link down");
|
||||
|
@ -486,7 +487,7 @@ static void enc424j600_rx_thread(const struct device *dev)
|
|||
continue;
|
||||
}
|
||||
|
||||
enc424j600_set_sfru(dev, ENC424J600_SFR3_EIEL,
|
||||
enc424j600_set_sfru(context->dev, ENC424J600_SFR3_EIEL,
|
||||
ENC424J600_EIE_INTIE);
|
||||
}
|
||||
}
|
||||
|
@ -599,6 +600,8 @@ static int enc424j600_init(const struct device *dev)
|
|||
uint8_t retries = ENC424J600_DEFAULT_NUMOF_RETRIES;
|
||||
uint16_t tmp;
|
||||
|
||||
context->dev;
|
||||
|
||||
/* SPI config */
|
||||
context->spi_cfg.operation = SPI_WORD_SET(8);
|
||||
context->spi_cfg.frequency = config->spi_freq;
|
||||
|
@ -732,7 +735,7 @@ static int enc424j600_init(const struct device *dev)
|
|||
k_thread_create(&context->thread, context->thread_stack,
|
||||
CONFIG_ETH_ENC424J600_RX_THREAD_STACK_SIZE,
|
||||
(k_thread_entry_t)enc424j600_rx_thread,
|
||||
(void *)dev, NULL, NULL,
|
||||
context, NULL, NULL,
|
||||
K_PRIO_COOP(CONFIG_ETH_ENC424J600_RX_THREAD_PRIO),
|
||||
0, K_NO_WAIT);
|
||||
|
||||
|
|
|
@ -288,6 +288,7 @@ struct enc424j600_config {
|
|||
|
||||
struct enc424j600_runtime {
|
||||
struct net_if *iface;
|
||||
const struct device *dev;
|
||||
|
||||
K_KERNEL_STACK_MEMBER(thread_stack,
|
||||
CONFIG_ETH_ENC424J600_RX_THREAD_STACK_SIZE);
|
||||
|
|
|
@ -773,9 +773,8 @@ static int eth_tx(const struct device *dev, struct net_pkt *pkt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void eth_rx(const struct device *iface)
|
||||
static void eth_rx(struct eth_context *context)
|
||||
{
|
||||
struct eth_context *context = iface->data;
|
||||
uint16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
|
||||
uint32_t frame_length = 0U;
|
||||
struct net_pkt *pkt;
|
||||
|
@ -930,12 +929,11 @@ static inline void ts_register_tx_event(struct eth_context *context)
|
|||
static void eth_callback(ENET_Type *base, enet_handle_t *handle,
|
||||
enet_event_t event, void *param)
|
||||
{
|
||||
const struct device *iface = param;
|
||||
struct eth_context *context = iface->data;
|
||||
struct eth_context *context = param;
|
||||
|
||||
switch (event) {
|
||||
case kENET_RxEvent:
|
||||
eth_rx(iface);
|
||||
eth_rx(context);
|
||||
break;
|
||||
case kENET_TxEvent:
|
||||
#if defined(CONFIG_PTP_CLOCK_MCUX)
|
||||
|
@ -1087,7 +1085,7 @@ static void eth_mcux_init(const struct device *dev)
|
|||
/* handle PHY setup after SMI initialization */
|
||||
eth_mcux_phy_setup(context);
|
||||
|
||||
ENET_SetCallback(&context->enet_handle, eth_callback, dev);
|
||||
ENET_SetCallback(&context->enet_handle, eth_callback, context);
|
||||
|
||||
eth_mcux_phy_start(context);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue