-static void write_eeprom(void __iomem *ioaddr, int location, u16 val,
- int addr_len)
-{
- int i;
- void __iomem *ee_addr = ioaddr + Cfg9346;
- int write_cmd = location | (EE_WRITE_CMD << addr_len);
-
- eeprom_extend_cmd(ee_addr, EE_EWEN_ADDR, addr_len);
-
- eeprom_cmd_start(ee_addr);
- eeprom_cmd(ee_addr, write_cmd, 3 + addr_len);
- eeprom_cmd(ee_addr, val, 16);
- eeprom_cmd_end(ee_addr);
-
- eeprom_cmd_start(ee_addr);
- for (i = 0; i < 20000; i++)
- if (readb(ee_addr) & EE_DATA_READ)
- break;
- eeprom_cmd_end(ee_addr);
-
- eeprom_extend_cmd(ee_addr, EE_EWDS_ADDR, addr_len);
-}
-
-static int cp_get_eeprom_len(struct net_device *dev)
-{
- struct cp_private *cp = netdev_priv(dev);
- int size;
-
- spin_lock_irq(&cp->lock);
- size = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 256 : 128;
- spin_unlock_irq(&cp->lock);
-
- return size;
-}
-
-static int cp_get_eeprom(struct net_device *dev,
- struct ethtool_eeprom *eeprom, u8 *data)
-{
- struct cp_private *cp = netdev_priv(dev);
- unsigned int addr_len;
- u16 val;
- u32 offset = eeprom->offset >> 1;
- u32 len = eeprom->len;
- u32 i = 0;
-
- eeprom->magic = CP_EEPROM_MAGIC;
-
- spin_lock_irq(&cp->lock);
-
- addr_len = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 8 : 6;
-
- if (eeprom->offset & 1) {
- val = read_eeprom(cp->regs, offset, addr_len);
- data[i++] = (u8)(val >> 8);
- offset++;
- }
-
- while (i < len - 1) {
- val = read_eeprom(cp->regs, offset, addr_len);
- data[i++] = (u8)val;
- data[i++] = (u8)(val >> 8);
- offset++;
- }
-
- if (i < len) {
- val = read_eeprom(cp->regs, offset, addr_len);
- data[i] = (u8)val;
- }
-
- spin_unlock_irq(&cp->lock);
- return 0;
-}
-
-static int cp_set_eeprom(struct net_device *dev,
- struct ethtool_eeprom *eeprom, u8 *data)
-{
- struct cp_private *cp = netdev_priv(dev);
- unsigned int addr_len;
- u16 val;
- u32 offset = eeprom->offset >> 1;
- u32 len = eeprom->len;
- u32 i = 0;
-
- if (eeprom->magic != CP_EEPROM_MAGIC)
- return -EINVAL;
-
- spin_lock_irq(&cp->lock);
-
- addr_len = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 8 : 6;
-
- if (eeprom->offset & 1) {
- val = read_eeprom(cp->regs, offset, addr_len) & 0xff;
- val |= (u16)data[i++] << 8;
- write_eeprom(cp->regs, offset, val, addr_len);
- offset++;
- }
-
- while (i < len - 1) {
- val = (u16)data[i++];
- val |= (u16)data[i++] << 8;
- write_eeprom(cp->regs, offset, val, addr_len);
- offset++;
- }
-
- if (i < len) {
- val = read_eeprom(cp->regs, offset, addr_len) & 0xff00;
- val |= (u16)data[i];
- write_eeprom(cp->regs, offset, val, addr_len);
- }
-
- spin_unlock_irq(&cp->lock);
- return 0;
-}
-