Skip to content

Commit 2912e17

Browse files
ambroise-armDRuffer-tmo
authored andcommitted
drivers: eth_smsc91x: Implement promiscuous mode
Add the RCR_PRMS field to toggle the promiscuous mode in the Ethernet controller. Register a set_config function that can make use of the field when CONFIG_NET_PROMISCUOUS_MODE is enabled. Signed-off-by: Ambroise Vincent <[email protected]>
1 parent be476f1 commit 2912e17

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

drivers/ethernet/eth_smsc91x.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,12 @@ static enum ethernet_hw_caps eth_smsc_get_caps(const struct device *dev)
678678
{
679679
ARG_UNUSED(dev);
680680

681-
return ETHERNET_LINK_10BASE_T | ETHERNET_LINK_100BASE_T;
681+
return (ETHERNET_LINK_10BASE_T
682+
| ETHERNET_LINK_100BASE_T
683+
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
684+
| ETHERNET_PROMISC_MODE
685+
#endif
686+
);
682687
}
683688

684689
static int eth_tx(const struct device *dev, struct net_pkt *pkt)
@@ -696,6 +701,42 @@ static int eth_tx(const struct device *dev, struct net_pkt *pkt)
696701
return smsc_send_pkt(sc, tx_buffer, len);
697702
}
698703

704+
static int eth_smsc_set_config(const struct device *dev,
705+
enum ethernet_config_type type,
706+
const struct ethernet_config *config)
707+
{
708+
struct eth_context *data = dev->data;
709+
struct smsc_data *sc = &data->sc;
710+
uint8_t reg_val;
711+
int ret = 0;
712+
713+
(void) reg_val;
714+
715+
switch (type) {
716+
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
717+
case ETHERNET_CONFIG_TYPE_PROMISC_MODE:
718+
SMSC_LOCK(sc);
719+
smsc_select_bank(sc, 0);
720+
reg_val = smsc_read_1(sc, RCR);
721+
if (config->promisc_mode && !(reg_val & RCR_PRMS)) {
722+
smsc_write_1(sc, RCR, reg_val | RCR_PRMS);
723+
} else if (!config->promisc_mode && (reg_val & RCR_PRMS)) {
724+
smsc_write_1(sc, RCR, reg_val & ~RCR_PRMS);
725+
} else {
726+
ret = -EALREADY;
727+
}
728+
SMSC_UNLOCK(sc);
729+
break;
730+
#endif
731+
732+
default:
733+
ret = -ENOTSUP;
734+
break;
735+
}
736+
737+
return ret;
738+
}
739+
699740
static void eth_initialize(struct net_if *iface)
700741
{
701742
const struct device *dev = net_if_get_device(iface);
@@ -725,9 +766,10 @@ static void eth_initialize(struct net_if *iface)
725766
}
726767

727768
static const struct ethernet_api api_funcs = {
728-
.iface_api.init = eth_initialize,
769+
.iface_api.init = eth_initialize,
729770
.get_capabilities = eth_smsc_get_caps,
730-
.send = eth_tx,
771+
.set_config = eth_smsc_set_config,
772+
.send = eth_tx,
731773
};
732774

733775
static void eth_smsc_isr(const struct device *dev)

drivers/ethernet/eth_smsc91x_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
/* Bank 0, Offset 0x4: Receive Control Register */
2727
#define RCR 0x4
28+
#define RCR_PRMS 0x0002 /* Promiscuous mode */
2829
#define RCR_RXEN 0x0100 /* Enable/disable receiver */
2930
#define RCR_STRIP_CRC 0x0200 /* Strip CRC from RX packets */
3031
#define RCR_SOFT_RST 0x8000 /* Software reset */

0 commit comments

Comments
 (0)