ksz9897_driver.c File Reference

KSZ9897 7-port Gigabit Ethernet switch driver. More...

#include "core/net.h"
#include "core/ethernet_misc.h"
#include "drivers/switch/ksz9897_driver.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   NIC_TRACE_LEVEL
 

Functions

error_t ksz9897Init (NetInterface *interface)
 KSZ9897 Ethernet switch initialization. More...
 
__weak_func void ksz9897InitHook (NetInterface *interface)
 KSZ9897 custom configuration. More...
 
void ksz9897Tick (NetInterface *interface)
 KSZ9897 timer handler. More...
 
void ksz9897EnableIrq (NetInterface *interface)
 Enable interrupts. More...
 
void ksz9897DisableIrq (NetInterface *interface)
 Disable interrupts. More...
 
void ksz9897EventHandler (NetInterface *interface)
 KSZ9897 event handler. More...
 
error_t ksz9897TagFrame (NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
 Add tail tag to Ethernet frame. More...
 
error_t ksz9897UntagFrame (NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
 Decode tail tag from incoming Ethernet frame. More...
 
bool_t ksz9897GetLinkState (NetInterface *interface, uint8_t port)
 Get link state. More...
 
uint32_t ksz9897GetLinkSpeed (NetInterface *interface, uint8_t port)
 Get link speed. More...
 
NicDuplexMode ksz9897GetDuplexMode (NetInterface *interface, uint8_t port)
 Get duplex mode. More...
 
void ksz9897SetPortState (NetInterface *interface, uint8_t port, SwitchPortState state)
 Set port state. More...
 
SwitchPortState ksz9897GetPortState (NetInterface *interface, uint8_t port)
 Get port state. More...
 
void ksz9897SetAgingTime (NetInterface *interface, uint32_t agingTime)
 Set aging time for dynamic filtering entries. More...
 
void ksz9897EnableIgmpSnooping (NetInterface *interface, bool_t enable)
 Enable IGMP snooping. More...
 
void ksz9897EnableMldSnooping (NetInterface *interface, bool_t enable)
 Enable MLD snooping. More...
 
void ksz9897EnableRsvdMcastTable (NetInterface *interface, bool_t enable)
 Enable reserved multicast table. More...
 
error_t ksz9897AddStaticFdbEntry (NetInterface *interface, const SwitchFdbEntry *entry)
 Add a new entry to the static MAC table. More...
 
error_t ksz9897DeleteStaticFdbEntry (NetInterface *interface, const SwitchFdbEntry *entry)
 Remove an entry from the static MAC table. More...
 
error_t ksz9897GetStaticFdbEntry (NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
 Read an entry from the static MAC table. More...
 
void ksz9897FlushStaticFdbTable (NetInterface *interface)
 Flush static MAC table. More...
 
error_t ksz9897GetDynamicFdbEntry (NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
 Read an entry from the dynamic MAC table. More...
 
void ksz9897FlushDynamicFdbTable (NetInterface *interface, uint8_t port)
 Flush dynamic MAC table. More...
 
void ksz9897SetUnknownMcastFwdPorts (NetInterface *interface, bool_t enable, uint32_t forwardPorts)
 Set forward ports for unknown multicast packets. More...
 
void ksz9897WritePhyReg (NetInterface *interface, uint8_t port, uint8_t address, uint16_t data)
 Write PHY register. More...
 
uint16_t ksz9897ReadPhyReg (NetInterface *interface, uint8_t port, uint8_t address)
 Read PHY register. More...
 
void ksz9897DumpPhyReg (NetInterface *interface, uint8_t port)
 Dump PHY registers for debugging purpose. More...
 
void ksz9897WriteMmdReg (NetInterface *interface, uint8_t port, uint8_t devAddr, uint16_t regAddr, uint16_t data)
 Write MMD register. More...
 
uint16_t ksz9897ReadMmdReg (NetInterface *interface, uint8_t port, uint8_t devAddr, uint16_t regAddr)
 Read MMD register. More...
 
void ksz9897WriteSwitchReg8 (NetInterface *interface, uint16_t address, uint8_t data)
 Write switch register (8 bits) More...
 
uint8_t ksz9897ReadSwitchReg8 (NetInterface *interface, uint16_t address)
 Read switch register (8 bits) More...
 
void ksz9897WriteSwitchReg16 (NetInterface *interface, uint16_t address, uint16_t data)
 Write switch register (16 bits) More...
 
uint16_t ksz9897ReadSwitchReg16 (NetInterface *interface, uint16_t address)
 Read switch register (16 bits) More...
 
void ksz9897WriteSwitchReg32 (NetInterface *interface, uint16_t address, uint32_t data)
 Write switch register (32 bits) More...
 
uint32_t ksz9897ReadSwitchReg32 (NetInterface *interface, uint16_t address)
 Read switch register (32 bits) More...
 

Variables

const SwitchDriver ksz9897SwitchDriver
 KSZ9897 Ethernet switch driver. More...
 
const uint16_t ksz9897IngressTailTag [6]
 Tail tag rules (host to KSZ9897) More...
 

Detailed Description

KSZ9897 7-port Gigabit Ethernet switch driver.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ksz9897_driver.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   NIC_TRACE_LEVEL

Definition at line 32 of file ksz9897_driver.c.

Function Documentation

◆ ksz9897AddStaticFdbEntry()

error_t ksz9897AddStaticFdbEntry ( NetInterface interface,
const SwitchFdbEntry entry 
)

Add a new entry to the static MAC table.

Parameters
[in]interfaceUnderlying network interface
[in]entryPointer to the forwarding database entry
Returns
Error code

Definition at line 1006 of file ksz9897_driver.c.

◆ ksz9897DeleteStaticFdbEntry()

error_t ksz9897DeleteStaticFdbEntry ( NetInterface interface,
const SwitchFdbEntry entry 
)

Remove an entry from the static MAC table.

Parameters
[in]interfaceUnderlying network interface
[in]entryForwarding database entry to remove from the table
Returns
Error code

Definition at line 1128 of file ksz9897_driver.c.

◆ ksz9897DisableIrq()

void ksz9897DisableIrq ( NetInterface interface)

Disable interrupts.

Parameters
[in]interfaceUnderlying network interface

Definition at line 338 of file ksz9897_driver.c.

◆ ksz9897DumpPhyReg()

void ksz9897DumpPhyReg ( NetInterface interface,
uint8_t  port 
)

Dump PHY registers for debugging purpose.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number

Definition at line 1623 of file ksz9897_driver.c.

◆ ksz9897EnableIgmpSnooping()

void ksz9897EnableIgmpSnooping ( NetInterface interface,
bool_t  enable 
)

Enable IGMP snooping.

Parameters
[in]interfaceUnderlying network interface
[in]enableEnable or disable IGMP snooping

Definition at line 917 of file ksz9897_driver.c.

◆ ksz9897EnableIrq()

void ksz9897EnableIrq ( NetInterface interface)

Enable interrupts.

Parameters
[in]interfaceUnderlying network interface

Definition at line 328 of file ksz9897_driver.c.

◆ ksz9897EnableMldSnooping()

void ksz9897EnableMldSnooping ( NetInterface interface,
bool_t  enable 
)

Enable MLD snooping.

Parameters
[in]interfaceUnderlying network interface
[in]enableEnable or disable MLD snooping

Definition at line 947 of file ksz9897_driver.c.

◆ ksz9897EnableRsvdMcastTable()

void ksz9897EnableRsvdMcastTable ( NetInterface interface,
bool_t  enable 
)

Enable reserved multicast table.

Parameters
[in]interfaceUnderlying network interface
[in]enableEnable or disable reserved group addresses

Definition at line 977 of file ksz9897_driver.c.

◆ ksz9897EventHandler()

void ksz9897EventHandler ( NetInterface interface)

KSZ9897 event handler.

Parameters
[in]interfaceUnderlying network interface

Definition at line 348 of file ksz9897_driver.c.

◆ ksz9897FlushDynamicFdbTable()

void ksz9897FlushDynamicFdbTable ( NetInterface interface,
uint8_t  port 
)

Flush dynamic MAC table.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number

Definition at line 1461 of file ksz9897_driver.c.

◆ ksz9897FlushStaticFdbTable()

void ksz9897FlushStaticFdbTable ( NetInterface interface)

Flush static MAC table.

Parameters
[in]interfaceUnderlying network interface

Definition at line 1305 of file ksz9897_driver.c.

◆ ksz9897GetDuplexMode()

NicDuplexMode ksz9897GetDuplexMode ( NetInterface interface,
uint8_t  port 
)

Get duplex mode.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
Returns
Duplex mode

Definition at line 713 of file ksz9897_driver.c.

◆ ksz9897GetDynamicFdbEntry()

error_t ksz9897GetDynamicFdbEntry ( NetInterface interface,
uint_t  index,
SwitchFdbEntry entry 
)

Read an entry from the dynamic MAC table.

Parameters
[in]interfaceUnderlying network interface
[in]indexZero-based index of the entry to read
[out]entryPointer to the forwarding database entry
Returns
Error code

Definition at line 1354 of file ksz9897_driver.c.

◆ ksz9897GetLinkSpeed()

uint32_t ksz9897GetLinkSpeed ( NetInterface interface,
uint8_t  port 
)

Get link speed.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
Returns
Link speed

Definition at line 618 of file ksz9897_driver.c.

◆ ksz9897GetLinkState()

bool_t ksz9897GetLinkState ( NetInterface interface,
uint8_t  port 
)

Get link state.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
Returns
Link state

Definition at line 584 of file ksz9897_driver.c.

◆ ksz9897GetPortState()

SwitchPortState ksz9897GetPortState ( NetInterface interface,
uint8_t  port 
)

Get port state.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
Returns
Port state

Definition at line 833 of file ksz9897_driver.c.

◆ ksz9897GetStaticFdbEntry()

error_t ksz9897GetStaticFdbEntry ( NetInterface interface,
uint_t  index,
SwitchFdbEntry entry 
)

Read an entry from the static MAC table.

Parameters
[in]interfaceUnderlying network interface
[in]indexZero-based index of the entry to read
[out]entryPointer to the forwarding database entry
Returns
Error code

Definition at line 1208 of file ksz9897_driver.c.

◆ ksz9897Init()

error_t ksz9897Init ( NetInterface interface)

KSZ9897 Ethernet switch initialization.

Parameters
[in]interfaceUnderlying network interface
Returns
Error code

Definition at line 94 of file ksz9897_driver.c.

◆ ksz9897InitHook()

__weak_func void ksz9897InitHook ( NetInterface interface)

KSZ9897 custom configuration.

Parameters
[in]interfaceUnderlying network interface

Definition at line 248 of file ksz9897_driver.c.

◆ ksz9897ReadMmdReg()

uint16_t ksz9897ReadMmdReg ( NetInterface interface,
uint8_t  port,
uint8_t  devAddr,
uint16_t  regAddr 
)

Read MMD register.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
[in]devAddrDevice address
[in]regAddrRegister address
Returns
Register value

Definition at line 1677 of file ksz9897_driver.c.

◆ ksz9897ReadPhyReg()

uint16_t ksz9897ReadPhyReg ( NetInterface interface,
uint8_t  port,
uint8_t  address 
)

Read PHY register.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
[in]addressPHY register address
Returns
Register value

Definition at line 1587 of file ksz9897_driver.c.

◆ ksz9897ReadSwitchReg16()

uint16_t ksz9897ReadSwitchReg16 ( NetInterface interface,
uint16_t  address 
)

Read switch register (16 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
Returns
Register value

Definition at line 1837 of file ksz9897_driver.c.

◆ ksz9897ReadSwitchReg32()

uint32_t ksz9897ReadSwitchReg32 ( NetInterface interface,
uint16_t  address 
)

Read switch register (32 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
Returns
Register value

Definition at line 1931 of file ksz9897_driver.c.

◆ ksz9897ReadSwitchReg8()

uint8_t ksz9897ReadSwitchReg8 ( NetInterface interface,
uint16_t  address 
)

Read switch register (8 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
Returns
Register value

Definition at line 1746 of file ksz9897_driver.c.

◆ ksz9897SetAgingTime()

void ksz9897SetAgingTime ( NetInterface interface,
uint32_t  agingTime 
)

Set aging time for dynamic filtering entries.

Parameters
[in]interfaceUnderlying network interface
[in]agingTimeAging time, in seconds

Definition at line 896 of file ksz9897_driver.c.

◆ ksz9897SetPortState()

void ksz9897SetPortState ( NetInterface interface,
uint8_t  port,
SwitchPortState  state 
)

Set port state.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
[in]statePort state

Definition at line 777 of file ksz9897_driver.c.

◆ ksz9897SetUnknownMcastFwdPorts()

void ksz9897SetUnknownMcastFwdPorts ( NetInterface interface,
bool_t  enable,
uint32_t  forwardPorts 
)

Set forward ports for unknown multicast packets.

Parameters
[in]interfaceUnderlying network interface
[in]enableEnable or disable forwarding of unknown multicast packets
[in]forwardPortsPort map

Definition at line 1508 of file ksz9897_driver.c.

◆ ksz9897TagFrame()

error_t ksz9897TagFrame ( NetInterface interface,
NetBuffer buffer,
size_t *  offset,
NetTxAncillary ancillary 
)

Add tail tag to Ethernet frame.

Parameters
[in]interfaceUnderlying network interface
[in]bufferMulti-part buffer containing the payload
[in,out]offsetOffset to the first payload byte
[in]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 473 of file ksz9897_driver.c.

◆ ksz9897Tick()

void ksz9897Tick ( NetInterface interface)

KSZ9897 timer handler.

Parameters
[in]interfaceUnderlying network interface

Definition at line 258 of file ksz9897_driver.c.

◆ ksz9897UntagFrame()

error_t ksz9897UntagFrame ( NetInterface interface,
uint8_t **  frame,
size_t *  length,
NetRxAncillary ancillary 
)

Decode tail tag from incoming Ethernet frame.

Parameters
[in]interfaceUnderlying network interface
[in,out]framePointer to the received Ethernet frame
[in,out]lengthLength of the frame, in bytes
[in,out]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 532 of file ksz9897_driver.c.

◆ ksz9897WriteMmdReg()

void ksz9897WriteMmdReg ( NetInterface interface,
uint8_t  port,
uint8_t  devAddr,
uint16_t  regAddr,
uint16_t  data 
)

Write MMD register.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
[in]devAddrDevice address
[in]regAddrRegister address
[in]dataRegister value

Definition at line 1649 of file ksz9897_driver.c.

◆ ksz9897WritePhyReg()

void ksz9897WritePhyReg ( NetInterface interface,
uint8_t  port,
uint8_t  address,
uint16_t  data 
)

Write PHY register.

Parameters
[in]interfaceUnderlying network interface
[in]portPort number
[in]addressPHY register address
[in]dataRegister value

Definition at line 1553 of file ksz9897_driver.c.

◆ ksz9897WriteSwitchReg16()

void ksz9897WriteSwitchReg16 ( NetInterface interface,
uint16_t  address,
uint16_t  data 
)

Write switch register (16 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
[in]dataRegister value

Definition at line 1793 of file ksz9897_driver.c.

◆ ksz9897WriteSwitchReg32()

void ksz9897WriteSwitchReg32 ( NetInterface interface,
uint16_t  address,
uint32_t  data 
)

Write switch register (32 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
[in]dataRegister value

Definition at line 1885 of file ksz9897_driver.c.

◆ ksz9897WriteSwitchReg8()

void ksz9897WriteSwitchReg8 ( NetInterface interface,
uint16_t  address,
uint8_t  data 
)

Write switch register (8 bits)

Parameters
[in]interfaceUnderlying network interface
[in]addressSwitch register address
[in]dataRegister value

Definition at line 1703 of file ksz9897_driver.c.

Variable Documentation

◆ ksz9897IngressTailTag

◆ ksz9897SwitchDriver

error_t ksz9897TagFrame(NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
Add tail tag to Ethernet frame.
error_t ksz9897DeleteStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Remove an entry from the static MAC table.
void ksz9897EventHandler(NetInterface *interface)
KSZ9897 event handler.
void ksz9897EnableIgmpSnooping(NetInterface *interface, bool_t enable)
Enable IGMP snooping.
error_t ksz9897Init(NetInterface *interface)
KSZ9897 Ethernet switch initialization.
void ksz9897EnableIrq(NetInterface *interface)
Enable interrupts.
#define KSZ9897_TAIL_TAG_DEST_PORT3
error_t ksz9897GetStaticFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the static MAC table.
void ksz9897SetPortState(NetInterface *interface, uint8_t port, SwitchPortState state)
Set port state.
error_t ksz9897UntagFrame(NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
Decode tail tag from incoming Ethernet frame.
void ksz9897FlushStaticFdbTable(NetInterface *interface)
Flush static MAC table.
void ksz9897SetUnknownMcastFwdPorts(NetInterface *interface, bool_t enable, uint32_t forwardPorts)
Set forward ports for unknown multicast packets.
uint32_t ksz9897GetLinkSpeed(NetInterface *interface, uint8_t port)
Get link speed.
#define KSZ9897_TAIL_TAG_DEST_PORT1
void ksz9897DisableIrq(NetInterface *interface)
Disable interrupts.
void ksz9897EnableRsvdMcastTable(NetInterface *interface, bool_t enable)
Enable reserved multicast table.
void ksz9897EnableMldSnooping(NetInterface *interface, bool_t enable)
Enable MLD snooping.
#define KSZ9897_TAIL_TAG_DEST_PORT4
error_t ksz9897GetDynamicFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the dynamic MAC table.
#define HTONS(value)
Definition: cpu_endian.h:410
#define KSZ9897_TAIL_TAG_NORMAL_ADDR_LOOKUP
void ksz9897SetAgingTime(NetInterface *interface, uint32_t agingTime)
Set aging time for dynamic filtering entries.
#define KSZ9897_TAIL_TAG_DEST_PORT2
#define KSZ9897_TAIL_TAG_PORT_BLOCKING_OVERRIDE
bool_t ksz9897GetLinkState(NetInterface *interface, uint8_t port)
Get link state.
SwitchPortState ksz9897GetPortState(NetInterface *interface, uint8_t port)
Get port state.
NicDuplexMode ksz9897GetDuplexMode(NetInterface *interface, uint8_t port)
Get duplex mode.
void ksz9897FlushDynamicFdbTable(NetInterface *interface, uint8_t port)
Flush dynamic MAC table.
error_t ksz9897AddStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Add a new entry to the static MAC table.
void ksz9897Tick(NetInterface *interface)
KSZ9897 timer handler.