(1)1582 module_init(dm9000_init);
(2)
1568 static int __init
1569 dm9000_init(void)
1570 {
1571 printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);
1572
1573 return platform_driver_register(&dm9000_driver);
1574 }
(3)定义 dm9000_driver
1558 static struct platform_driver dm9000_driver = {
1559 .driver = {
1560 .name = "dm9000",
1561 .owner = THIS_MODULE,
1562 .pm = &dm9000_drv_pm_ops,
1563 },
1564 .probe = dm9000_probe,
1565 .remove = __devexit_p(dm9000_drv_remove),
1566 };
(4)
1270 /*
1271 * Search DM9000 board, allocate space and register it
1272 */
1273 static int __devinit
1274 dm9000_probe(struct platform_device *pdev)
1275 {
1440 /* driver system function */
1441 ether_setup(ndev);
1442
1443 ndev->netdev_ops = &dm9000_netdev_ops;
1444 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
1445 ndev->ethtool_ops = &dm9000_ethtool_ops;
1446
1447 db->msg_enable = NETIF_MSG_LINK;
1448 db->mii.phy_id_mask = 0x1f;
1449 db->mii.reg_num_mask = 0x1f;
1450 db->mii.force_media = 0;
1451 db->mii.full_duplex = 0;
1452 db->mii.dev = ndev;
1453 db->mii.mdio_read = dm9000_phy_read;
1454 db->mii.mdio_write = dm9000_phy_write;
1455
(5)
1255 static const struct net_device_ops dm9000_netdev_ops = {
1256 .ndo_open = dm9000_open,
1257 .ndo_stop = dm9000_stop,
1258 .ndo_start_xmit = dm9000_start_xmit, // 发送
1259 .ndo_tx_timeout = dm9000_timeout,
1260 .ndo_set_multicast_list = dm9000_hash_table,
1261 .ndo_do_ioctl = dm9000_ioctl,
1262 .ndo_change_mtu = eth_change_mtu,
1263 .ndo_validate_addr = eth_validate_addr,
1264 .ndo_set_mac_address = eth_mac_addr,
1265 #ifdef CONFIG_NET_POLL_CONTROLLER
1266 .ndo_poll_controller = dm9000_poll_controller,
1267 #endif
1268 };
(6)
1068 static void dm9000_poll_controller(struct net_device *dev)
1069 {
1070 disable_irq(dev->irq);
1071 dm9000_interrupt(dev->irq, dev);
1072 enable_irq(dev->irq);
1073 }
(7) 处理网卡中断,准备接收数据
1010 static irqreturn_t dm9000_interrupt(int irq, void *dev_id)
1011 {
1012 struct net_device *dev = dev_id;
1013 board_info_t *db = netdev_priv(dev);
1014 int int_status;
1015 unsigned long flags;
1016 u8 reg_save;
1017
1018 dm9000_dbg(db, 3, "entering %s\n", __func__);
1019
1020 /* A real interrupt coming */
1021
1022 /* holders of db->lock must always block IRQs */
1023 spin_lock_irqsave(&db->lock, flags);
1024
1025 /* Save previous register address */
1026 reg_save = readb(db->io_addr);
1027
1028 /* Disable all interrupts */
1029 iow(db, DM9000_IMR, IMR_PAR);
1030
1031 /* Got DM9000 interrupt status */
1032 int_status = ior(db, DM9000_ISR); /* Got ISR */
1033 iow(db, DM9000_ISR, int_status); /* Clear ISR status */
1034
1035 if (netif_msg_intr(db))
1036 dev_dbg(db->dev, "interrupt status %02x\n", int_status);
1037
1038 /* Received the coming packet */
1039 if (int_status & ISR_PRS)
1040 dm9000_rx(dev);
1041
1042 /* Trnasmit Interrupt check */
1043 if (int_status & ISR_PTS)
1044 dm9000_tx_done(dev, db);
1045
1046 if (db->type != TYPE_DM9000E) {
1047 if (int_status & ISR_LNKCHNG) {
1048 /* fire a link-change request */
1049 schedule_delayed_work(&db->phy_poll, 1);
1050 }
1051 }
1052
1053 /* Re-enable interrupt mask */
1054 iow(db, DM9000_IMR, db->imr_all);
1055
1056 /* Restore previous register address */
1057 writeb(reg_save, db->io_addr);
1058
1059 spin_unlock_irqrestore(&db->lock, flags);
1060
1061 return IRQ_HANDLED;
1062 }
(8) 通过链路层接口netif_rx接收数据
907 static void
908 dm9000_rx(struct net_device *dev)
909 {
980 /* Move data from DM9000 */
981 if (GoodPacket
982 && ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) {
983 skb_reserve(skb, 2);
984 rdptr = (u8 *) skb_put(skb, RxLen - 4);
985
986 /* Read received packet from RX SRAM */
987
988 (db->inblk)(db->io_data, rdptr, RxLen);
989 dev->stats.rx_bytes += RxLen;
990
991 /* Pass to upper layer */
992 skb->protocol = eth_type_trans(skb, dev);
993 if (db->rx_csum) {
994 if ((((rxbyte & 0x1c) << 3) & rxbyte) == 0)
995 skb->ip_summed = CHECKSUM_UNNECESSARY;
996 else
997 skb->ip_summed = CHECKSUM_NONE;
998 }
999 netif_rx(skb);
1000 dev->stats.rx_packets++;
1001
1002 } else {
1003 /* need to dump the packet's data */
1004
1005 (db->dumpblk)(db->io_data, RxLen);
1006 }
发送数据过程
831 /*
832 * Hardware start transmission.
833 * Send a packet to media from the upper layer.
834 */
835 static int
836 dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
837 {
838 unsigned long flags;
839 board_info_t *db = netdev_priv(dev);
840
841 dm9000_dbg(db, 3, "%s:\n", __func__);
842
843 if (db->tx_pkt_cnt > 1)
844 return NETDEV_TX_BUSY;
845
846 spin_lock_irqsave(&db->lock, flags);
847
848 /* Move data to DM9000 TX RAM */
849 writeb(DM9000_MWCMD, db->io_addr);
850
851 (db->outblk)(db->io_data, skb->data, skb->len);
852 dev->stats.tx_bytes += skb->len;
853
854 db->tx_pkt_cnt++;
855 /* TX control: First packet immediately send, second packet queue */
856 if (db->tx_pkt_cnt == 1) {
857 dm9000_send_packet(dev, skb->ip_summed, skb->len);
858 } else {
859 /* Second packet */
860 db->queue_pkt_len = skb->len;
861 db->queue_ip_summed = skb->ip_summed;
862 netif_stop_queue(dev);
863 }
864
865 spin_unlock_irqrestore(&db->lock, flags);
866
867 /* free this SKB */
868 dev_kfree_skb(skb);
869
870 return NETDEV_TX_OK;
871 }