//-------------------------------------------------------------------
//rtl_eeprom_type():
//  tell the eeprom type
//return value:
//  0: the eeprom type is 93C46
//  1: the eeprom type is 93C56 or 93C66
//-------------------------------------------------------------------
void rtl_eeprom_type(struct rtl8168_private *tp)
{
    void __iomem *ioaddr=tp->mmio_addr;
    u16 magic = 0;

    if (tp->mcfg == CFG_METHOD_DEFAULT)
        goto out_no_eeprom;

    if(RTL_R8(0xD2)&0x04) {
        //not support
        //tp->eeprom_type = EEPROM_TWSI;
        //tp->eeprom_len = 256;
        goto out_no_eeprom;
    } else if(RTL_R32(RxConfig) & RxCfg_9356SEL) {
        tp->eeprom_type = EEPROM_TYPE_93C56;
        tp->eeprom_len = 256;
    } else {
        tp->eeprom_type = EEPROM_TYPE_93C46;
        tp->eeprom_len = 128;
    }

    magic = rtl_eeprom_read_sc(tp, 0);

out_no_eeprom:
    if ((magic != 0x8129) && (magic != 0x8128)) {
        tp->eeprom_type = EEPROM_TYPE_NONE;
        tp->eeprom_len = 0;
    }
}
示例#2
0
int rtltool_ioctl(struct rtl8168_private *tp, struct ifreq *ifr)
{
    struct rtltool_cmd my_cmd;
    unsigned long flags;
    int ret;

    if (copy_from_user(&my_cmd, ifr->ifr_data, sizeof(my_cmd)))
        return -EFAULT;

    ret = 0;
    switch (my_cmd.cmd) {
    case RTLTOOL_READ_MAC:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        if (my_cmd.len==1)
            my_cmd.data = readb(tp->mmio_addr+my_cmd.offset);
        else if (my_cmd.len==2)
            my_cmd.data = readw(tp->mmio_addr+(my_cmd.offset&~1));
        else if (my_cmd.len==4)
            my_cmd.data = readl(tp->mmio_addr+(my_cmd.offset&~3));
        else {
            ret = -EOPNOTSUPP;
            break;
        }

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }
        break;

    case RTLTOOL_WRITE_MAC:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        if (my_cmd.len==1)
            writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
        else if (my_cmd.len==2)
            writew(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~1));
        else if (my_cmd.len==4)
            writel(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~3));
        else {
            ret = -EOPNOTSUPP;
            break;
        }

        break;

    case RTLTOOL_READ_PHY:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        spin_lock_irqsave(&tp->phy_lock, flags);
        my_cmd.data = mdio_read(tp, my_cmd.offset);
        spin_unlock_irqrestore(&tp->phy_lock, flags);

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }

        break;

    case RTLTOOL_WRITE_PHY:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        spin_lock_irqsave(&tp->phy_lock, flags);
        mdio_write(tp, my_cmd.offset, my_cmd.data);
        spin_unlock_irqrestore(&tp->phy_lock, flags);
        break;

    case RTLTOOL_READ_EPHY:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        my_cmd.data = rtl8168_ephy_read(tp->mmio_addr, my_cmd.offset);

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }

        break;

    case RTLTOOL_WRITE_EPHY:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        rtl8168_ephy_write(tp->mmio_addr, my_cmd.offset, my_cmd.data);
        break;

    case RTLTOOL_READ_PCI:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        my_cmd.data = 0;
        if (my_cmd.len==1)
            pci_read_config_byte(tp->pci_dev, my_cmd.offset,
                                 (u8 *)&my_cmd.data);
        else if (my_cmd.len==2)
            pci_read_config_word(tp->pci_dev, my_cmd.offset,
                                 (u16 *)&my_cmd.data);
        else if (my_cmd.len==4)
            pci_read_config_dword(tp->pci_dev, my_cmd.offset,
                                  &my_cmd.data);
        else {
            ret = -EOPNOTSUPP;
            break;
        }

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }
        break;

    case RTLTOOL_WRITE_PCI:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        if (my_cmd.len==1)
            pci_write_config_byte(tp->pci_dev, my_cmd.offset,
                                  my_cmd.data);
        else if (my_cmd.len==2)
            pci_write_config_word(tp->pci_dev, my_cmd.offset,
                                  my_cmd.data);
        else if (my_cmd.len==4)
            pci_write_config_dword(tp->pci_dev, my_cmd.offset,
                                   my_cmd.data);
        else {
            ret = -EOPNOTSUPP;
            break;
        }

        break;

    case RTLTOOL_READ_EEPROM:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        my_cmd.data = rtl_eeprom_read_sc(tp, my_cmd.offset);

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }

        break;

    case RTLTOOL_WRITE_EEPROM:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        rtl_eeprom_write_sc(tp->mmio_addr, my_cmd.offset, my_cmd.data);
        break;

    case RTL_ARP_NS_OFFLOAD:
        break;

    case RTL_SET_OOB_IPMAC:
        ret = OOB_set_ip_mac(tp,
                             (struct sockaddr_in *)&my_cmd.ifru_addr,
                             my_cmd.ifru_hwaddr.sa_data);
        break;

    case RTL_READ_OOB_MAC:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        my_cmd.data = OCP_read(tp, 0xf, my_cmd.offset);

        if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
            ret = -EFAULT;
            break;
        }
        break;

    case RTL_WRITE_OOB_MAC:
        if (!capable(CAP_NET_ADMIN))
            return -EPERM;

        OOB_mutex_lock(tp);
        if (my_cmd.len == 1)
            OCP_write(tp, 0x1, my_cmd.offset, my_cmd.data);
        else if (my_cmd.len == 2)
            OCP_write(tp, 0x3, my_cmd.offset, my_cmd.data);
        else if (my_cmd.len == 4)
            OCP_write(tp, 0xf, my_cmd.offset, my_cmd.data);
        else {
            ret = -EOPNOTSUPP;
        }
        OOB_mutex_unlock(tp);
        break;

    default:
        ret = -EOPNOTSUPP;
        break;
    }

    return ret;
}