User Tools

Site Tools


programming:linux

Linux Kernel Programming

Topics

  • Suppress scheduling by use of preempt_disable(), see preempt-locking.txt for other methods.
  • For use of [num]delay(), usleep() and friends see timers-howto.txt.
  • MII ioctl of a network device:
    const struct net_device_ops *ops = ndev->netdev_ops;
    int err = -ENXIO;
     
    if (ops->ndo_do_ioctl) {
    	struct ifreq ifr;
    	struct mii_ioctl_data mii;
     
    	mm_segment_t oldfs = get_fs();
     
    	mii.reg_num = MII_BMCR;
    	ifr.ifr_ifru.ifru_data = (__force void __user *)&mii;
    	set_fs(KERNEL_DS);
     
    	err = ops->ndo_do_ioctl(ndev, &ifr, SIOCGMIIPHY);
    	if (!err) {
    		mii.val_in = (mii.val_out & ~BMCR_RESET) | BMCR_ISOLATE;
    		err = ops->ndo_do_ioctl(ndev, &ifr, SIOCSMIIREG);
    		netdev_dbg(ndev, "%s: MII ioctl setting BMCR = 0x%04x\n",
    			__func__, mii.val_in);
    	}
     
    	set_fs(oldfs);
    }
programming/linux.txt · Last modified: 2018/01/15 12:59 by Ralf Hoppe