Category:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
0
1
2
3
4
5
6
7
8
9
Position:IcFull.com » IC Electronic information » Category: L

IC Electronic information

Linux network drive

In Electronic Infomation Category: L | on April 26,2011

Const char * devname,

Void * dev / / DMA mode to transmit packets to the network card physical device. If it is wireless, then the 802.11 protocol and MC14512B datasheet and the need to standardize the hardware from the new fill

/ / Hardware header, and MC14512B price and then submitted to the hardware sent.

Mapping = pci_map_single (tp-> pdev, skb-> data, len, PCI_DMA_TODEVICE);

Tp-> tx_buffers [entry]. Skb = skb;

Pci_unmap_addr_set (& tp-> tx_buffers [entry], mapping, mapping);

/ / Hardware to send

Tg3_set_txd (tp, entry, mapping, len, base_flags, mss_and_is_end);

/ / Record start time of contract

Dev-> trans_start = jiffies;

}

7. Interrupt handling received packets, and MC14512B suppliers and the developer

Static void tg3_interrupt (int irq, void * dev_id, struct pt_regs * regs)

{

/ / If you want to receive packages

Tg3_rx (tp);

/ / If you want to contract

Tg3_tx (tp);

}

8. Employer

Static void tg3_tx (struct tg3 * tp)

{

Struct tx_ring_info * ri = & tp-> tx_buffers [sw_idx];

Struct sk_buff * skb = ri-> skb;

/ / DMA mode to transmit packets to the network card is completed

Pci_unmap_single (tp-> pdev, pci_unmap_addr (ri, mapping),

(Skb-> len - skb-> data_len), PCI_DMA_TODEVICE);

Ri-> skb = NULL;

Dev_kfree_skb_irq (skb);

}

9. Closing package

Static int tg3_rx (struct tg3 * tp, int budget)

{

Struct sk_buff * copy_skb;

/ / Allocate a package

Copy_skb = dev_alloc_skb (len + 2);

Copy_skb-> dev = tp-> dev;

/ / Modify header space

Skb_reserve (copy_skb, 2);

/ / Add data to a package

Skb_put (copy_skb, len);

/ / DMA mode to transmit data back from the card

Pci_dma_sync_single (tp-> pdev, dma_addr, len, PCI_DMA_FROMDEVICE);

Memcpy (copy_skb-> data, skb-> data, len);

Skb = copy_skb;

/ / Analytical package deal

Skb-> protocol = eth_type_trans (skb, tp-> dev);

/ / The packet to the protocol layer

Netif_rx (skb);

/ / Record time of collection bag

Tp-> dev-> last_rx = jiffies;

}

10. Read the packet send and receive packets the network card status, statistics

Static struct net_device_stats * tg3_get_stats (struct net_device * dev)

{

/ / Read the registers from the hardware-related data, cumulative

/ / Stats-> rx_packets, stats-> tx_packets, stats-> rx_bytes, stats-> tx_bytes, etc.

}

11. User ioctl command system call

Static int tg3_ioctl (struct net_device * dev, struct ifreq * ifr, int cmd)

{

Struct mii_ioctl_data * data = (struct mii_ioctl_data *) & ifr-> ifr_data;

Switch (cmd) {

/ / Ethtool command procedure call

Case SIO * HTOOL:

Return tg3_ethtool_ioctl (dev, (void *) ifr-> ifr_data);

/ / Mii program command calls

Case SIOCGMIIREG: {

Err = tg3_readphy (tp, data-> reg_num & 0x1f, & mii_regval)

Data-> val_out = mii_regval;

Return err;

}

... ...

}

}

12.PCI equipment, suspend and resume function

Static int tg3_suspend (struct pci_dev * pdev, u32 state)

{

/ / Disable the network card interrupt register

Tg3_disable_ints (tp);

/ / Stop the NIC send and receive packets

Netif_device_detach (dev);

/ / Stop the card some of the hardware, fireware some features

Tg3_halt (tp);

/ / Set the NICs power state

Tg3_set_power_state (tp, state);

}

Static int tg3_resume (struct pci_dev * pdev)

{

/ / Restore LAN Power

Tg3_set_power_state (tp, 0);

/ / Allow LAN transceiver package

Netif_device_attach (dev);

/ / Initialize the send and receive packet buffer

Tg3_init_rings (tp);

/ / Initialize the network card hardware

Tg3_init_hw (tp);

/ / Open the card interrupt register

Tg3_enable_ints (tp);

}

13. Parameter settings

In the driver inside the system also provides some methods for setting the parameters of the device and reading information. General only the super user (root) privileges to set the parameters of the device. Setting method:

Tg3_set_mac_addr (dev-> set_mac_address)

When the user when calling ioctl type SIOCSIFHWADDR is to set the device mac address. Generally set the mac address is not much sense.

Dev-> set_config () When the user when calling ioctl

type SIOCSIFMAP, the system calls the drivers set_config methods

Users will need to pass a ifmap structure contains the I / O, interrupts and other parameters.

Summary:

All the Linux network drivers to follow a common interface. Designed with the object-oriented approach. A device is an object (net_device structure), which has its own internal data and methods. The most basic method of a network device has initialized, send and receive.

Linux network driver architecture can be divided into four:

Network protocol interface, the network device interface, device driver functions, network equipment and network media layer

Network driver, the most important job is to complete the device driver function layer. In Linux, all network devices are abstracted as an interface that provides a collection of all network equipment operation. Struct net_device by the data structure to represent the network device operation in the kernel, that the network device interface. It includes a software network device interface, such as the loop (Loopback), also includes hardware network device interface, such as Ethernet cards. Dev_base by the equipment list for the first pointer to the collective management of all network equipment, the equipment list for each element represents a network device interface. There are many net_device data structure for system access and protocol layer device called methods, including initialization, open and close the open and stop network equipment function, processing of data packets sent hard_start_xmit functions, and interrupt handler and so on.

Doing network equipment in the Linux specific treatment. Linux network system is mainly based on BSD unix the socket mechanism. Between the system and driver specific data structure definition (sk_buff) for data transmission. Support system to send data and receive data cache, providing flow control mechanism, provides multi-protocol support.

MC14512B datasheetMC14512B suppliersMC14512B Price

Related technical information

All right reserved:icfull.com © 2010-2016 Certificate