Merge branch 'ro-bind.b6' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[safe/jmp/linux-2.6] / include / linux / phy.h
index 9447a57..779cbcd 100644 (file)
 
 #include <linux/spinlock.h>
 #include <linux/device.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
+
+#include <asm/atomic.h>
 
 #define PHY_BASIC_FEATURES     (SUPPORTED_10baseT_Half | \
                                 SUPPORTED_10baseT_Full | \
@@ -33,7 +39,8 @@
                                 SUPPORTED_1000baseT_Half | \
                                 SUPPORTED_1000baseT_Full)
 
-/* Set phydev->irq to PHY_POLL if interrupts are not supported,
+/*
+ * Set phydev->irq to PHY_POLL if interrupts are not supported,
  * or not desired for this PHY.  Set to PHY_IGNORE_INTERRUPT if
  * the attached driver handles the interrupt
  */
 #define PHY_HAS_INTERRUPT      0x00000001
 #define PHY_HAS_MAGICANEG      0x00000002
 
-#define MII_BUS_MAX 4
-
-
-#define PHY_INIT_TIMEOUT 100000
+/* Interface Mode definitions */
+typedef enum {
+       PHY_INTERFACE_MODE_MII,
+       PHY_INTERFACE_MODE_GMII,
+       PHY_INTERFACE_MODE_SGMII,
+       PHY_INTERFACE_MODE_TBI,
+       PHY_INTERFACE_MODE_RMII,
+       PHY_INTERFACE_MODE_RGMII,
+       PHY_INTERFACE_MODE_RGMII_ID,
+       PHY_INTERFACE_MODE_RGMII_RXID,
+       PHY_INTERFACE_MODE_RGMII_TXID,
+       PHY_INTERFACE_MODE_RTBI
+} phy_interface_t;
+
+
+#define PHY_INIT_TIMEOUT       100000
 #define PHY_STATE_TIME         1
 #define PHY_FORCE_TIMEOUT      10
 #define PHY_AN_TIMEOUT         10
 
-#define PHY_MAX_ADDR 32
+#define PHY_MAX_ADDR   32
 
 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
-#define PHY_ID_FMT "%x:%02x"
+#define PHY_ID_FMT "%s:%02x"
 
-/* The Bus class for PHYs.  Devices which provide access to
- * PHYs should register using this structure */
+/*
+ * Need to be a little smaller than phydev->dev.bus_id to leave room
+ * for the ":%02x"
+ */
+#define MII_BUS_ID_SIZE        (BUS_ID_SIZE - 3)
+
+/*
+ * The Bus class for PHYs.  Devices which provide access to
+ * PHYs should register using this structure
+ */
 struct mii_bus {
        const char *name;
-       int id;
+       char id[MII_BUS_ID_SIZE];
        void *priv;
        int (*read)(struct mii_bus *bus, int phy_id, int regnum);
        int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
        int (*reset)(struct mii_bus *bus);
 
-       /* A lock to ensure that only one thing can read/write
-        * the MDIO bus at a time */
-       spinlock_t mdio_lock;
+       /*
+        * A lock to ensure that only one thing can read/write
+        * the MDIO bus at a time
+        */
+       struct mutex mdio_lock;
 
        struct device *dev;
 
@@ -78,13 +107,15 @@ struct mii_bus {
        /* Phy addresses to be ignored when probing */
        u32 phy_mask;
 
-       /* Pointer to an array of interrupts, each PHY's
-        * interrupt at the index matching its address */
+       /*
+        * Pointer to an array of interrupts, each PHY's
+        * interrupt at the index matching its address
+        */
        int *irq;
 };
 
-#define PHY_INTERRUPT_DISABLED 0x0
-#define PHY_INTERRUPT_ENABLED 0x80000000
+#define PHY_INTERRUPT_DISABLED 0x0
+#define PHY_INTERRUPT_ENABLED  0x80000000
 
 /* PHY state machine states:
  *
@@ -226,10 +257,13 @@ struct phy_device {
 
        u32 dev_flags;
 
+       phy_interface_t interface;
+
        /* Bus address of the PHY (0-32) */
        int addr;
 
-       /* forced speed & duplex (no autoneg)
+       /*
+        * forced speed & duplex (no autoneg)
         * partner speed & duplex & pause (autoneg)
         */
        int speed;
@@ -252,8 +286,10 @@ struct phy_device {
 
        int link_timeout;
 
-       /* Interrupt number for this PHY
-        * -1 means no interrupt */
+       /*
+        * Interrupt number for this PHY
+        * -1 means no interrupt
+        */
        int irq;
 
        /* private data pointer */
@@ -262,9 +298,11 @@ struct phy_device {
 
        /* Interrupt and Polling infrastructure */
        struct work_struct phy_queue;
+       struct work_struct state_queue;
        struct timer_list phy_timer;
+       atomic_t irq_disable;
 
-       spinlock_t lock;
+       struct mutex lock;
 
        struct net_device *attached_dev;
 
@@ -301,22 +339,28 @@ struct phy_driver {
        u32 features;
        u32 flags;
 
-       /* Called to initialize the PHY,
-        * including after a reset */
+       /*
+        * Called to initialize the PHY,
+        * including after a reset
+        */
        int (*config_init)(struct phy_device *phydev);
 
-       /* Called during discovery.  Used to set
-        * up device-specific structures, if any */
+       /*
+        * Called during discovery.  Used to set
+        * up device-specific structures, if any
+        */
        int (*probe)(struct phy_device *phydev);
 
        /* PHY Power Management */
        int (*suspend)(struct phy_device *phydev);
        int (*resume)(struct phy_device *phydev);
 
-       /* Configures the advertisement and resets
+       /*
+        * Configures the advertisement and resets
         * autonegotiation if phydev->autoneg is on,
         * forces the speed to the current settings in phydev
-        * if phydev->autoneg is off */
+        * if phydev->autoneg is off
+        */
        int (*config_aneg)(struct phy_device *phydev);
 
        /* Determines the negotiated speed and duplex */
@@ -337,13 +381,15 @@ struct phy_driver {
 
 int phy_read(struct phy_device *phydev, u16 regnum);
 int phy_write(struct phy_device *phydev, u16 regnum, u16 val);
+int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id);
 struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
 int phy_clear_interrupt(struct phy_device *phydev);
 int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
 struct phy_device * phy_attach(struct net_device *dev,
-               const char *phy_id, u32 flags);
+               const char *phy_id, u32 flags, phy_interface_t interface);
 struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
-               void (*handler)(struct net_device *), u32 flags);
+               void (*handler)(struct net_device *), u32 flags,
+               phy_interface_t interface);
 void phy_disconnect(struct phy_device *phydev);
 void phy_detach(struct phy_device *phydev);
 void phy_start(struct phy_device *phydev);
@@ -379,6 +425,7 @@ int phy_mii_ioctl(struct phy_device *phydev,
 int phy_start_interrupts(struct phy_device *phydev);
 void phy_print_status(struct phy_device *phydev);
 struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id);
+void phy_device_free(struct phy_device *phydev);
 
 extern struct bus_type mdio_bus_type;
 #endif /* __PHY_H */