sfc: Fix some incorrect or redundant comments
[safe/jmp/linux-2.6] / drivers / net / sfc / net_driver.h
index 13bc1b4..ac77a25 100644 (file)
@@ -1,7 +1,7 @@
 /****************************************************************************
  * Driver for Solarflare Solarstorm network controllers and boards
  * Copyright 2005-2006 Fen Systems Ltd.
- * Copyright 2005-2008 Solarflare Communications Inc.
+ * Copyright 2005-2009 Solarflare Communications Inc.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
@@ -38,7 +38,7 @@
 #ifndef EFX_DRIVER_NAME
 #define EFX_DRIVER_NAME        "sfc"
 #endif
-#define EFX_DRIVER_VERSION     "2.3"
+#define EFX_DRIVER_VERSION     "3.0"
 
 #ifdef EFX_ENABLE_DEBUG
 #define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
@@ -101,9 +101,6 @@ do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
  * Special buffers are used for the event queues and the TX and RX
  * descriptor queues for each channel.  They are *not* used for the
  * actual transmit and receive buffers.
- *
- * Note that for Falcon, TX and RX descriptor queues live in host memory.
- * Allocation and freeing procedures must take this into account.
  */
 struct efx_special_buffer {
        void *addr;
@@ -113,6 +110,13 @@ struct efx_special_buffer {
        int entries;
 };
 
+enum efx_flush_state {
+       FLUSH_NONE,
+       FLUSH_PENDING,
+       FLUSH_FAILED,
+       FLUSH_DONE,
+};
+
 /**
  * struct efx_tx_buffer - An Efx TX buffer
  * @skb: The associated socket buffer.
@@ -189,7 +193,7 @@ struct efx_tx_queue {
        struct efx_nic *nic;
        struct efx_tx_buffer *buffer;
        struct efx_special_buffer txd;
-       bool flushed;
+       enum efx_flush_state flushed;
 
        /* Members used mainly on the completion path */
        unsigned int read_count ____cacheline_aligned_in_smp;
@@ -284,7 +288,7 @@ struct efx_rx_queue {
        struct page *buf_page;
        dma_addr_t buf_dma_addr;
        char *buf_data;
-       bool flushed;
+       enum efx_flush_state flushed;
 };
 
 /**
@@ -293,7 +297,7 @@ struct efx_rx_queue {
  * @dma_addr: DMA base address of the buffer
  * @len: Buffer length, in bytes
  *
- * Falcon uses these buffers for its interrupt status registers and
+ * The NIC uses these buffers for its interrupt status registers and
  * MAC stats dumps.
  */
 struct efx_buffer {
@@ -343,9 +347,9 @@ enum efx_rx_alloc_method {
  * @rx_alloc_push_pages: RX allocation method currently in use for pushing
  *     descriptors
  * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
- * @n_rx_ip_frag_err: Count of RX IP fragment errors
  * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
+ * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  * @n_rx_overlength: Count of RX_OVERLENGTH errors
  * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
@@ -373,9 +377,9 @@ struct efx_channel {
        int rx_alloc_push_pages;
 
        unsigned n_rx_tobe_disc;
-       unsigned n_rx_ip_frag_err;
        unsigned n_rx_ip_hdr_chksum_err;
        unsigned n_rx_tcp_udp_chksum_err;
+       unsigned n_rx_mcast_mismatch;
        unsigned n_rx_frm_trunc;
        unsigned n_rx_overlength;
        unsigned n_skbuff_leaks;
@@ -388,44 +392,29 @@ struct efx_channel {
 
 };
 
-/**
- * struct efx_board - board information
- * @type: Board model type
- * @major: Major rev. ('A', 'B' ...)
- * @minor: Minor rev. (0, 1, ...)
- * @init: Initialisation function
- * @init_leds: Sets up board LEDs. May be called repeatedly.
- * @set_id_led: Turns the identification LED on or off
- * @blink: Starts/stops blinking
- * @monitor: Board-specific health check function
- * @fini: Cleanup function
- * @blink_state: Current blink state
- * @blink_resubmit: Blink timer resubmission flag
- * @blink_timer: Blink timer
- * @hwmon_client: I2C client for hardware monitor
- * @ioexp_client: I2C client for power/port control
- */
-struct efx_board {
-       int type;
-       int major;
-       int minor;
-       int (*init) (struct efx_nic *nic);
-       /* As the LEDs are typically attached to the PHY, LEDs
-        * have a separate init callback that happens later than
-        * board init. */
-       void (*init_leds)(struct efx_nic *efx);
-       void (*set_id_led) (struct efx_nic *efx, bool state);
-       int (*monitor) (struct efx_nic *nic);
-       void (*blink) (struct efx_nic *efx, bool start);
-       void (*fini) (struct efx_nic *nic);
-       bool blink_state;
-       bool blink_resubmit;
-       struct timer_list blink_timer;
-       struct i2c_client *hwmon_client, *ioexp_client;
+enum efx_led_mode {
+       EFX_LED_OFF     = 0,
+       EFX_LED_ON      = 1,
+       EFX_LED_DEFAULT = 2
 };
 
-#define STRING_TABLE_LOOKUP(val, member)       \
-       member ## _names[val]
+#define STRING_TABLE_LOOKUP(val, member) \
+       ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
+
+extern const char *efx_loopback_mode_names[];
+extern const unsigned int efx_loopback_mode_max;
+#define LOOPBACK_MODE(efx) \
+       STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
+
+extern const char *efx_interrupt_mode_names[];
+extern const unsigned int efx_interrupt_mode_max;
+#define INT_MODE(efx) \
+       STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_interrupt_mode)
+
+extern const char *efx_reset_type_names[];
+extern const unsigned int efx_reset_type_max;
+#define RESET_TYPE(type) \
+       STRING_TABLE_LOOKUP(type, efx_reset_type)
 
 enum efx_int_mode {
        /* Be careful if altering to correct macro below */
@@ -436,20 +425,7 @@ enum efx_int_mode {
 };
 #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
 
-enum phy_type {
-       PHY_TYPE_NONE = 0,
-       PHY_TYPE_TXC43128 = 1,
-       PHY_TYPE_88E1111 = 2,
-       PHY_TYPE_SFX7101 = 3,
-       PHY_TYPE_QT2022C2 = 4,
-       PHY_TYPE_PM8358 = 6,
-       PHY_TYPE_SFT9001A = 8,
-       PHY_TYPE_QT2025C = 9,
-       PHY_TYPE_SFT9001B = 10,
-       PHY_TYPE_MAX    /* Insert any new items before this */
-};
-
-#define EFX_IS10G(efx) ((efx)->link_speed == 10000)
+#define EFX_IS10G(efx) ((efx)->link_state.speed == 10000)
 
 enum nic_state {
        STATE_INIT = 0,
@@ -491,72 +467,72 @@ enum efx_fc_type {
        EFX_FC_AUTO = 4,
 };
 
-/* Supported MAC bit-mask */
-enum efx_mac_type {
-       EFX_GMAC = 1,
-       EFX_XMAC = 2,
+/**
+ * struct efx_link_state - Current state of the link
+ * @up: Link is up
+ * @fd: Link is full-duplex
+ * @fc: Actual flow control flags
+ * @speed: Link speed (Mbps)
+ */
+struct efx_link_state {
+       bool up;
+       bool fd;
+       enum efx_fc_type fc;
+       unsigned int speed;
 };
 
-static inline enum efx_fc_type efx_fc_resolve(enum efx_fc_type wanted_fc,
-                                             unsigned int lpa)
+static inline bool efx_link_state_equal(const struct efx_link_state *left,
+                                       const struct efx_link_state *right)
 {
-       BUILD_BUG_ON(EFX_FC_AUTO & (EFX_FC_RX | EFX_FC_TX));
-
-       if (!(wanted_fc & EFX_FC_AUTO))
-               return wanted_fc;
-
-       return mii_resolve_flowctrl_fdx(mii_advertise_flowctrl(wanted_fc), lpa);
+       return left->up == right->up && left->fd == right->fd &&
+               left->fc == right->fc && left->speed == right->speed;
 }
 
 /**
  * struct efx_mac_operations - Efx MAC operations table
  * @reconfigure: Reconfigure MAC. Serialised by the mac_lock
  * @update_stats: Update statistics
- * @irq: Hardware MAC event callback. Serialised by the mac_lock
- * @poll: Poll for hardware state. Serialised by the mac_lock
+ * @check_fault: Check fault state. True if fault present.
  */
 struct efx_mac_operations {
-       void (*reconfigure) (struct efx_nic *efx);
+       int (*reconfigure) (struct efx_nic *efx);
        void (*update_stats) (struct efx_nic *efx);
-       void (*irq) (struct efx_nic *efx);
-       void (*poll) (struct efx_nic *efx);
+       bool (*check_fault)(struct efx_nic *efx);
 };
 
 /**
  * struct efx_phy_operations - Efx PHY operations table
+ * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
+ *     efx->loopback_modes.
  * @init: Initialise PHY
  * @fini: Shut down PHY
  * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
- * @clear_interrupt: Clear down interrupt
- * @poll: Poll for hardware state. Serialised by the mac_lock.
+ * @poll: Update @link_state and report whether it changed.
+ *     Serialised by the mac_lock.
  * @get_settings: Get ethtool settings. Serialised by the mac_lock.
  * @set_settings: Set ethtool settings. Serialised by the mac_lock.
  * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  *     (only needed where AN bit is set in mmds)
- * @num_tests: Number of PHY-specific tests/results
- * @test_names: Names of the tests/results
- * @run_tests: Run tests and record results as appropriate.
+ * @test_alive: Test that PHY is 'alive' (online)
+ * @test_name: Get the name of a PHY-specific test/result
+ * @run_tests: Run tests and record results as appropriate (offline).
  *     Flags are the ethtool tests flags.
- * @mmds: MMD presence mask
- * @loopbacks: Supported loopback modes mask
  */
 struct efx_phy_operations {
-       enum efx_mac_type macs;
+       int (*probe) (struct efx_nic *efx);
        int (*init) (struct efx_nic *efx);
        void (*fini) (struct efx_nic *efx);
-       void (*reconfigure) (struct efx_nic *efx);
-       void (*clear_interrupt) (struct efx_nic *efx);
-       void (*poll) (struct efx_nic *efx);
+       void (*remove) (struct efx_nic *efx);
+       int (*reconfigure) (struct efx_nic *efx);
+       bool (*poll) (struct efx_nic *efx);
        void (*get_settings) (struct efx_nic *efx,
                              struct ethtool_cmd *ecmd);
        int (*set_settings) (struct efx_nic *efx,
                             struct ethtool_cmd *ecmd);
        void (*set_npage_adv) (struct efx_nic *efx, u32);
-       u32 num_tests;
-       const char *const *test_names;
+       int (*test_alive) (struct efx_nic *efx);
+       const char *(*test_name) (struct efx_nic *efx, unsigned int index);
        int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
-       int mmds;
-       unsigned loopbacks;
 };
 
 /**
@@ -680,8 +656,6 @@ union efx_multicast_hash {
  * @interrupt_mode: Interrupt mode
  * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  * @irq_rx_moderation: IRQ moderation time for RX event queues
- * @i2c_adap: I2C adapter
- * @board_info: Board-level information
  * @state: Device state flag. Serialised by the rtnl_lock.
  * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
  * @tx_queue: TX DMA queues
@@ -697,22 +671,23 @@ union efx_multicast_hash {
  * @irq_status: Interrupt status buffer
  * @last_irq_cpu: Last CPU to handle interrupt.
  *     This register is written with the SMP processor ID whenever an
- *     interrupt is handled.  It is used by falcon_test_interrupt()
+ *     interrupt is handled.  It is used by efx_nic_test_interrupt()
  *     to verify that an interrupt has occurred.
  * @spi_flash: SPI flash device
- *     This field will be %NULL if no flash device is present.
+ *     This field will be %NULL if no flash device is present (or for Siena).
  * @spi_eeprom: SPI EEPROM device
- *     This field will be %NULL if no EEPROM device is present.
+ *     This field will be %NULL if no EEPROM device is present (or for Siena).
  * @spi_lock: SPI bus lock
+ * @mtd_list: List of MTDs attached to the NIC
  * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
  * @nic_data: Hardware dependant state
  * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  *     @port_inhibited, efx_monitor() and efx_reconfigure_port()
  * @port_enabled: Port enabled indicator.
- *     Serialises efx_stop_all(), efx_start_all(), efx_monitor(),
- *     efx_phy_work(), and efx_mac_work() with kernel interfaces. Safe to read
- *     under any one of the rtnl_lock, mac_lock, or netif_tx_lock, but all
- *     three must be held to modify it.
+ *     Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
+ *     efx_mac_work() with kernel interfaces. Safe to read under any
+ *     one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
+ *     be held to modify it.
  * @port_inhibited: If set, the netif_carrier is always off. Hold the mac_lock
  * @port_initialized: Port initialized?
  * @net_dev: Operating system network device. Consider holding the rtnl lock
@@ -724,32 +699,28 @@ union efx_multicast_hash {
  *     &struct net_device_stats.
  * @stats_buffer: DMA buffer for statistics
  * @stats_lock: Statistics update lock. Serialises statistics fetches
- * @stats_disable_count: Nest count for disabling statistics fetches
  * @mac_op: MAC interface
  * @mac_address: Permanent MAC address
  * @phy_type: PHY type
- * @phy_lock: PHY access lock
+ * @mdio_lock: MDIO lock
  * @phy_op: PHY interface
  * @phy_data: PHY private data (including PHY-specific stats)
  * @mdio: PHY MDIO interface
+ * @mdio_bus: PHY MDIO bus ID (only used by Siena)
  * @phy_mode: PHY operating mode. Serialised by @mac_lock.
- * @mac_up: MAC link state
- * @link_up: Link status
- * @link_fd: Link is full duplex
- * @link_fc: Actualy flow control flags
- * @link_speed: Link speed (Mbps)
+ * @xmac_poll_required: XMAC link state needs polling
+ * @link_advertising: Autonegotiation advertising flags
+ * @link_state: Current state of the link
  * @n_link_state_changes: Number of times the link has changed state
  * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
  * @multicast_hash: Multicast hash table
  * @wanted_fc: Wanted flow control flags
- * @phy_work: work item for dealing with PHY events
- * @mac_work: work item for dealing with MAC events
+ * @mac_work: Work item for changing MAC promiscuity and multicast hash
  * @loopback_mode: Loopback status
  * @loopback_modes: Supported loopback mode bitmask
  * @loopback_selftest: Offline self-test private state
  *
- * The @priv field of the corresponding &struct net_device points to
- * this.
+ * This is stored in the private area of the &struct net_device.
  */
 struct efx_nic {
        char name[IFNAMSIZ];
@@ -767,9 +738,6 @@ struct efx_nic {
        bool irq_rx_adaptive;
        unsigned int irq_rx_moderation;
 
-       struct i2c_adapter i2c_adap;
-       struct efx_board board_info;
-
        enum nic_state state;
        enum reset_type reset_pending;
 
@@ -788,14 +756,18 @@ struct efx_nic {
 
        struct efx_buffer irq_status;
        volatile signed int last_irq_cpu;
+       unsigned long irq_zero_count;
 
        struct efx_spi_device *spi_flash;
        struct efx_spi_device *spi_eeprom;
        struct mutex spi_lock;
+#ifdef CONFIG_SFC_MTD
+       struct list_head mtd_list;
+#endif
 
        unsigned n_rx_nodesc_drop_cnt;
 
-       struct falcon_nic_data *nic_data;
+       void *nic_data;
 
        struct mutex mac_lock;
        struct work_struct mac_work;
@@ -812,24 +784,21 @@ struct efx_nic {
        struct efx_mac_stats mac_stats;
        struct efx_buffer stats_buffer;
        spinlock_t stats_lock;
-       unsigned int stats_disable_count;
 
        struct efx_mac_operations *mac_op;
        unsigned char mac_address[ETH_ALEN];
 
-       enum phy_type phy_type;
-       spinlock_t phy_lock;
-       struct work_struct phy_work;
+       unsigned int phy_type;
+       struct mutex mdio_lock;
        struct efx_phy_operations *phy_op;
        void *phy_data;
        struct mdio_if_info mdio;
+       unsigned int mdio_bus;
        enum efx_phy_mode phy_mode;
 
-       bool mac_up;
-       bool link_up;
-       bool link_fd;
-       enum efx_fc_type link_fc;
-       unsigned int link_speed;
+       bool xmac_poll_required;
+       u32 link_advertising;
+       struct efx_link_state link_state;
        unsigned int n_link_state_changes;
 
        bool promiscuous;
@@ -838,7 +807,7 @@ struct efx_nic {
 
        atomic_t rx_reset;
        enum efx_loopback_mode loopback_mode;
-       unsigned int loopback_modes;
+       u64 loopback_modes;
 
        void *loopback_selftest;
 };
@@ -857,9 +826,37 @@ static inline const char *efx_dev_name(struct efx_nic *efx)
        return efx_dev_registered(efx) ? efx->name : "";
 }
 
+static inline unsigned int efx_port_num(struct efx_nic *efx)
+{
+       return PCI_FUNC(efx->pci_dev->devfn);
+}
+
 /**
  * struct efx_nic_type - Efx device type definition
- * @mem_bar: Memory BAR number
+ * @probe: Probe the controller
+ * @remove: Free resources allocated by probe()
+ * @init: Initialise the controller
+ * @fini: Shut down the controller
+ * @monitor: Periodic function for polling link state and hardware monitor
+ * @reset: Reset the controller hardware and possibly the PHY.  This will
+ *     be called while the controller is uninitialised.
+ * @probe_port: Probe the MAC and PHY
+ * @remove_port: Free resources allocated by probe_port()
+ * @prepare_flush: Prepare the hardware for flushing the DMA queues
+ * @update_stats: Update statistics not provided by event handling
+ * @start_stats: Start the regular fetching of statistics
+ * @stop_stats: Stop the regular fetching of statistics
+ * @set_id_led: Set state of identifying LED or revert to automatic function
+ * @push_irq_moderation: Apply interrupt moderation value
+ * @push_multicast_hash: Apply multicast hash table
+ * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
+ * @get_wol: Get WoL configuration from driver state
+ * @set_wol: Push WoL configuration to the NIC
+ * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
+ * @test_registers: Test read/write functionality of control registers
+ * @test_nvram: Test validity of NVRAM contents
+ * @default_mac_ops: efx_mac_operations to set at startup
+ * @revision: Hardware architecture revision
  * @mem_map_size: Memory BAR mapped size
  * @txd_ptr_tbl_base: TX descriptor ring base address
  * @rxd_ptr_tbl_base: RX descriptor ring base address
@@ -872,21 +869,52 @@ static inline const char *efx_dev_name(struct efx_nic *efx)
  *     from &enum efx_init_mode.
  * @phys_addr_channels: Number of channels with physically addressed
  *     descriptors
+ * @tx_dc_base: Base address in SRAM of TX queue descriptor caches
+ * @rx_dc_base: Base address in SRAM of RX queue descriptor caches
+ * @offload_features: net_device feature flags for protocol offload
+ *     features implemented in hardware
+ * @reset_world_flags: Flags for additional components covered by
+ *     reset method RESET_TYPE_WORLD
  */
 struct efx_nic_type {
-       unsigned int mem_bar;
+       int (*probe)(struct efx_nic *efx);
+       void (*remove)(struct efx_nic *efx);
+       int (*init)(struct efx_nic *efx);
+       void (*fini)(struct efx_nic *efx);
+       void (*monitor)(struct efx_nic *efx);
+       int (*reset)(struct efx_nic *efx, enum reset_type method);
+       int (*probe_port)(struct efx_nic *efx);
+       void (*remove_port)(struct efx_nic *efx);
+       void (*prepare_flush)(struct efx_nic *efx);
+       void (*update_stats)(struct efx_nic *efx);
+       void (*start_stats)(struct efx_nic *efx);
+       void (*stop_stats)(struct efx_nic *efx);
+       void (*set_id_led)(struct efx_nic *efx, enum efx_led_mode mode);
+       void (*push_irq_moderation)(struct efx_channel *channel);
+       void (*push_multicast_hash)(struct efx_nic *efx);
+       int (*reconfigure_port)(struct efx_nic *efx);
+       void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
+       int (*set_wol)(struct efx_nic *efx, u32 type);
+       void (*resume_wol)(struct efx_nic *efx);
+       int (*test_registers)(struct efx_nic *efx);
+       int (*test_nvram)(struct efx_nic *efx);
+       struct efx_mac_operations *default_mac_ops;
+
+       int revision;
        unsigned int mem_map_size;
        unsigned int txd_ptr_tbl_base;
        unsigned int rxd_ptr_tbl_base;
        unsigned int buf_tbl_base;
        unsigned int evq_ptr_tbl_base;
        unsigned int evq_rptr_tbl_base;
-
        u64 max_dma_mask;
-
        unsigned int rx_buffer_padding;
        unsigned int max_interrupt_mode;
        unsigned int phys_addr_channels;
+       unsigned int tx_dc_base;
+       unsigned int rx_dc_base;
+       unsigned long offload_features;
+       u32 reset_world_flags;
 };
 
 /**************************************************************************
@@ -965,7 +993,7 @@ static inline void clear_bit_le(unsigned nr, unsigned char *addr)
  * that the net driver will program into the MAC as the maximum frame
  * length.
  *
- * The 10G MAC used in Falcon requires 8-byte alignment on the frame
+ * The 10G MAC requires 8-byte alignment on the frame
  * length, so we round up to the nearest 8.
  *
  * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an