drivers/net/ethernet/micrel/ksz884x.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/micrel/ksz884x.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/micrel/ksz884x.c
Extension
.c
Size
173933 bytes
Lines
6878
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct net_device_ops netdev_ops = {
	.ndo_init		= netdev_init,
	.ndo_open		= netdev_open,
	.ndo_stop		= netdev_close,
	.ndo_get_stats		= netdev_query_statistics,
	.ndo_start_xmit		= netdev_tx,
	.ndo_tx_timeout		= netdev_tx_timeout,
	.ndo_change_mtu		= netdev_change_mtu,
	.ndo_set_features	= netdev_set_features,
	.ndo_set_mac_address	= netdev_set_mac_address,
	.ndo_validate_addr	= eth_validate_addr,
	.ndo_eth_ioctl		= netdev_ioctl,
	.ndo_set_rx_mode	= netdev_set_rx_mode,
#ifdef CONFIG_NET_POLL_CONTROLLER
	.ndo_poll_controller	= netdev_netpoll,
#endif
};

static void netdev_free(struct net_device *dev)
{
	if (dev->watchdog_timeo)
		unregister_netdev(dev);

	free_netdev(dev);
}

struct platform_info {
	struct dev_info dev_info;
	struct net_device *netdev[SWITCH_PORT_NUM];
};

static int net_device_present;

static void get_mac_addr(struct dev_info *hw_priv, u8 *macaddr, int port)
{
	int i;
	int j;
	int got_num;
	int num;

	i = j = num = got_num = 0;
	while (j < ETH_ALEN) {
		if (macaddr[i]) {
			int digit;

			got_num = 1;
			digit = hex_to_bin(macaddr[i]);
			if (digit >= 0)
				num = num * 16 + digit;
			else if (':' == macaddr[i])
				got_num = 2;
			else
				break;
		} else if (got_num)
			got_num = 2;
		else
			break;
		if (2 == got_num) {
			if (MAIN_PORT == port) {
				hw_priv->hw.override_addr[j++] = (u8) num;
				hw_priv->hw.override_addr[5] +=
					hw_priv->hw.id;
			} else {
				hw_priv->hw.ksz_switch->other_addr[j++] =
					(u8) num;
				hw_priv->hw.ksz_switch->other_addr[5] +=
					hw_priv->hw.id;
			}
			num = got_num = 0;
		}
		i++;
	}
	if (ETH_ALEN == j) {
		if (MAIN_PORT == port)
			hw_priv->hw.mac_override = 1;
	}
}

#define KS884X_DMA_MASK			(~0x0UL)

static void read_other_addr(struct ksz_hw *hw)
{
	int i;
	u16 data[3];
	struct ksz_switch *sw = hw->ksz_switch;

	for (i = 0; i < 3; i++)
		data[i] = eeprom_read(hw, i + EEPROM_DATA_OTHER_MAC_ADDR);
	if ((data[0] || data[1] || data[2]) && data[0] != 0xffff) {
		sw->other_addr[5] = (u8) data[0];

Annotation

Implementation Notes