[PATCH] natsemi: Support oversized EEPROMs

The natsemi chip can have a larger EEPROM attached than it itself uses for
configuration. This patch adds support for user space access to such an
EEPROM.

Signed-off-by: Mark Brown <broonie@sirena.org.uk>
Cc: Tim Hockin <thockin@hockin.org>
Cc: Jeff Garzik <jgarzik@pobox.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Jeff Garzik <jeff@garzik.org>

authored by

Mark Brown and committed by
Jeff Garzik
a8b4cf42 8dfc914a

+14 -4
+14 -4
drivers/net/natsemi.c
··· 226 NATSEMI_PG1_NREGS) 227 #define NATSEMI_REGS_VER 1 /* v1 added RFDR registers */ 228 #define NATSEMI_REGS_SIZE (NATSEMI_NREGS * sizeof(u32)) 229 - #define NATSEMI_EEPROM_SIZE 24 /* 12 16-bit values */ 230 231 /* Buffer sizes: 232 * The nic writes 32-bit values, even if the upper bytes of ··· 714 unsigned int iosize; 715 spinlock_t lock; 716 u32 msg_enable; 717 }; 718 719 static void move_int_phy(struct net_device *dev, int addr); ··· 892 np->msg_enable = (debug >= 0) ? (1<<debug)-1 : NATSEMI_DEF_MSG; 893 np->hands_off = 0; 894 np->intr_status = 0; 895 896 /* Initial port: 897 * - If the nic was configured to use an external phy and if find_mii ··· 2585 2586 static int get_eeprom_len(struct net_device *dev) 2587 { 2588 - return NATSEMI_EEPROM_SIZE; 2589 } 2590 2591 static int get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) ··· 2673 static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) 2674 { 2675 struct netdev_private *np = netdev_priv(dev); 2676 - u8 eebuf[NATSEMI_EEPROM_SIZE]; 2677 int res; 2678 2679 eeprom->magic = PCI_VENDOR_ID_NS | (PCI_DEVICE_ID_NS_83815<<16); 2680 spin_lock_irq(&np->lock); ··· 2686 spin_unlock_irq(&np->lock); 2687 if (!res) 2688 memcpy(data, eebuf+eeprom->offset, eeprom->len); 2689 return res; 2690 } 2691 ··· 3042 int i; 3043 u16 *ebuf = (u16 *)buf; 3044 void __iomem * ioaddr = ns_ioaddr(dev); 3045 3046 /* eeprom_read reads 16 bits, and indexes by 16 bits */ 3047 - for (i = 0; i < NATSEMI_EEPROM_SIZE/2; i++) { 3048 ebuf[i] = eeprom_read(ioaddr, i); 3049 /* The EEPROM itself stores data bit-swapped, but eeprom_read 3050 * reads it back "sanely". So we swap it back here in order to
··· 226 NATSEMI_PG1_NREGS) 227 #define NATSEMI_REGS_VER 1 /* v1 added RFDR registers */ 228 #define NATSEMI_REGS_SIZE (NATSEMI_NREGS * sizeof(u32)) 229 + #define NATSEMI_DEF_EEPROM_SIZE 24 /* 12 16-bit values */ 230 231 /* Buffer sizes: 232 * The nic writes 32-bit values, even if the upper bytes of ··· 714 unsigned int iosize; 715 spinlock_t lock; 716 u32 msg_enable; 717 + /* EEPROM data */ 718 + int eeprom_size; 719 }; 720 721 static void move_int_phy(struct net_device *dev, int addr); ··· 890 np->msg_enable = (debug >= 0) ? (1<<debug)-1 : NATSEMI_DEF_MSG; 891 np->hands_off = 0; 892 np->intr_status = 0; 893 + np->eeprom_size = NATSEMI_DEF_EEPROM_SIZE; 894 895 /* Initial port: 896 * - If the nic was configured to use an external phy and if find_mii ··· 2582 2583 static int get_eeprom_len(struct net_device *dev) 2584 { 2585 + struct netdev_private *np = netdev_priv(dev); 2586 + return np->eeprom_size; 2587 } 2588 2589 static int get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) ··· 2669 static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) 2670 { 2671 struct netdev_private *np = netdev_priv(dev); 2672 + u8 *eebuf; 2673 int res; 2674 + 2675 + eebuf = kmalloc(np->eeprom_size, GFP_KERNEL); 2676 + if (!eebuf) 2677 + return -ENOMEM; 2678 2679 eeprom->magic = PCI_VENDOR_ID_NS | (PCI_DEVICE_ID_NS_83815<<16); 2680 spin_lock_irq(&np->lock); ··· 2678 spin_unlock_irq(&np->lock); 2679 if (!res) 2680 memcpy(data, eebuf+eeprom->offset, eeprom->len); 2681 + kfree(eebuf); 2682 return res; 2683 } 2684 ··· 3033 int i; 3034 u16 *ebuf = (u16 *)buf; 3035 void __iomem * ioaddr = ns_ioaddr(dev); 3036 + struct netdev_private *np = netdev_priv(dev); 3037 3038 /* eeprom_read reads 16 bits, and indexes by 16 bits */ 3039 + for (i = 0; i < np->eeprom_size/2; i++) { 3040 ebuf[i] = eeprom_read(ioaddr, i); 3041 /* The EEPROM itself stores data bit-swapped, but eeprom_read 3042 * reads it back "sanely". So we swap it back here in order to