aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkeem G. Abodunrin <akeem.g.abodunrin@intel.com>2013-04-11 02:36:35 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2013-04-18 19:39:33 -0400
commitf69aa3909eeb8444f9b980f6315696c3b0bb57d5 (patch)
treea7a3aa46bcfc9f6a450cad4e9a754513b9cec6fc
parentf502ef7d77dd09bad9c93ee854fcb61d6fc29815 (diff)
igb: Support to read and export SFF-8472/8079 data
This patch adds support to read and export SFF-8472/8079 (SFP data) over i2c, through Ethtool. v2: Changed implementation to accommodate any offset within SFF module length boundary. Reported-by: Aurélien Guillaume <footplus@gmail.com> CC: Aurélien Guillaume <footplus@gmail.com> CC: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: Akeem G Abodunrin <akeem.g.abodunrin@intel.com> Tested-by: Aaron Brown <aaron.f.brown@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
-rw-r--r--drivers/net/ethernet/intel/igb/igb.h8
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ethtool.c81
2 files changed, 89 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 25151401c2ab..7cb039827a0c 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -178,6 +178,14 @@ enum igb_tx_flags {
178#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGB_MAX_DATA_PER_TXD) 178#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGB_MAX_DATA_PER_TXD)
179#define DESC_NEEDED (MAX_SKB_FRAGS + 4) 179#define DESC_NEEDED (MAX_SKB_FRAGS + 4)
180 180
181/* EEPROM byte offsets */
182#define IGB_SFF_8472_SWAP 0x5C
183#define IGB_SFF_8472_COMP 0x5E
184
185/* Bitmasks */
186#define IGB_SFF_ADDRESSING_MODE 0x4
187#define IGB_SFF_8472_UNSUP 0x00
188
181/* wrapper around a pointer to a socket buffer, 189/* wrapper around a pointer to a socket buffer,
182 * so a DMA handle can be stored along with the buffer */ 190 * so a DMA handle can be stored along with the buffer */
183struct igb_tx_buffer { 191struct igb_tx_buffer {
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 8499c48090c6..6afd7278ad67 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -2622,6 +2622,85 @@ static int igb_set_eee(struct net_device *netdev,
2622 return 0; 2622 return 0;
2623} 2623}
2624 2624
2625static int igb_get_module_info(struct net_device *netdev,
2626 struct ethtool_modinfo *modinfo)
2627{
2628 struct igb_adapter *adapter = netdev_priv(netdev);
2629 struct e1000_hw *hw = &adapter->hw;
2630 u32 status = E1000_SUCCESS;
2631 u16 sff8472_rev, addr_mode;
2632 bool page_swap = false;
2633
2634 if ((hw->phy.media_type == e1000_media_type_copper) ||
2635 (hw->phy.media_type == e1000_media_type_unknown))
2636 return -EOPNOTSUPP;
2637
2638 /* Check whether we support SFF-8472 or not */
2639 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
2640 if (status != E1000_SUCCESS)
2641 return -EIO;
2642
2643 /* addressing mode is not supported */
2644 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
2645 if (status != E1000_SUCCESS)
2646 return -EIO;
2647
2648 /* addressing mode is not supported */
2649 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
2650 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
2651 page_swap = true;
2652 }
2653
2654 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
2655 /* We have an SFP, but it does not support SFF-8472 */
2656 modinfo->type = ETH_MODULE_SFF_8079;
2657 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
2658 } else {
2659 /* We have an SFP which supports a revision of SFF-8472 */
2660 modinfo->type = ETH_MODULE_SFF_8472;
2661 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2662 }
2663
2664 return 0;
2665}
2666
2667static int igb_get_module_eeprom(struct net_device *netdev,
2668 struct ethtool_eeprom *ee, u8 *data)
2669{
2670 struct igb_adapter *adapter = netdev_priv(netdev);
2671 struct e1000_hw *hw = &adapter->hw;
2672 u32 status = E1000_SUCCESS;
2673 u16 *dataword;
2674 u16 first_word, last_word;
2675 int i = 0;
2676
2677 if (ee->len == 0)
2678 return -EINVAL;
2679
2680 first_word = ee->offset >> 1;
2681 last_word = (ee->offset + ee->len - 1) >> 1;
2682
2683 dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
2684 GFP_KERNEL);
2685 if (!dataword)
2686 return -ENOMEM;
2687
2688 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
2689 for (i = 0; i < last_word - first_word + 1; i++) {
2690 status = igb_read_phy_reg_i2c(hw, first_word + i, &dataword[i]);
2691 if (status != E1000_SUCCESS)
2692 /* Error occurred while reading module */
2693 return -EIO;
2694
2695 be16_to_cpus(&dataword[i]);
2696 }
2697
2698 memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
2699 kfree(dataword);
2700
2701 return 0;
2702}
2703
2625static int igb_ethtool_begin(struct net_device *netdev) 2704static int igb_ethtool_begin(struct net_device *netdev)
2626{ 2705{
2627 struct igb_adapter *adapter = netdev_priv(netdev); 2706 struct igb_adapter *adapter = netdev_priv(netdev);
@@ -2666,6 +2745,8 @@ static const struct ethtool_ops igb_ethtool_ops = {
2666 .set_rxnfc = igb_set_rxnfc, 2745 .set_rxnfc = igb_set_rxnfc,
2667 .get_eee = igb_get_eee, 2746 .get_eee = igb_get_eee,
2668 .set_eee = igb_set_eee, 2747 .set_eee = igb_set_eee,
2748 .get_module_info = igb_get_module_info,
2749 .get_module_eeprom = igb_get_module_eeprom,
2669 .begin = igb_ethtool_begin, 2750 .begin = igb_ethtool_begin,
2670 .complete = igb_ethtool_complete, 2751 .complete = igb_ethtool_complete,
2671}; 2752};