atl1c_ethtool.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright(c) 2009 - 2009 Atheros Corporation. All rights reserved.
  3. *
  4. * Derived from Intel e1000 driver
  5. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc., 59
  19. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. */
  22. #include <linux/netdevice.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/slab.h>
  25. #include "atl1c.h"
  26. static int atl1c_get_link_ksettings(struct net_device *netdev,
  27. struct ethtool_link_ksettings *cmd)
  28. {
  29. struct atl1c_adapter *adapter = netdev_priv(netdev);
  30. struct atl1c_hw *hw = &adapter->hw;
  31. u32 supported, advertising;
  32. supported = (SUPPORTED_10baseT_Half |
  33. SUPPORTED_10baseT_Full |
  34. SUPPORTED_100baseT_Half |
  35. SUPPORTED_100baseT_Full |
  36. SUPPORTED_Autoneg |
  37. SUPPORTED_TP);
  38. if (hw->link_cap_flags & ATL1C_LINK_CAP_1000M)
  39. supported |= SUPPORTED_1000baseT_Full;
  40. advertising = ADVERTISED_TP;
  41. advertising |= hw->autoneg_advertised;
  42. cmd->base.port = PORT_TP;
  43. cmd->base.phy_address = 0;
  44. if (adapter->link_speed != SPEED_0) {
  45. cmd->base.speed = adapter->link_speed;
  46. if (adapter->link_duplex == FULL_DUPLEX)
  47. cmd->base.duplex = DUPLEX_FULL;
  48. else
  49. cmd->base.duplex = DUPLEX_HALF;
  50. } else {
  51. cmd->base.speed = SPEED_UNKNOWN;
  52. cmd->base.duplex = DUPLEX_UNKNOWN;
  53. }
  54. cmd->base.autoneg = AUTONEG_ENABLE;
  55. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  56. supported);
  57. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  58. advertising);
  59. return 0;
  60. }
  61. static int atl1c_set_link_ksettings(struct net_device *netdev,
  62. const struct ethtool_link_ksettings *cmd)
  63. {
  64. struct atl1c_adapter *adapter = netdev_priv(netdev);
  65. struct atl1c_hw *hw = &adapter->hw;
  66. u16 autoneg_advertised;
  67. while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
  68. msleep(1);
  69. if (cmd->base.autoneg == AUTONEG_ENABLE) {
  70. autoneg_advertised = ADVERTISED_Autoneg;
  71. } else {
  72. u32 speed = cmd->base.speed;
  73. if (speed == SPEED_1000) {
  74. if (cmd->base.duplex != DUPLEX_FULL) {
  75. if (netif_msg_link(adapter))
  76. dev_warn(&adapter->pdev->dev,
  77. "1000M half is invalid\n");
  78. clear_bit(__AT_RESETTING, &adapter->flags);
  79. return -EINVAL;
  80. }
  81. autoneg_advertised = ADVERTISED_1000baseT_Full;
  82. } else if (speed == SPEED_100) {
  83. if (cmd->base.duplex == DUPLEX_FULL)
  84. autoneg_advertised = ADVERTISED_100baseT_Full;
  85. else
  86. autoneg_advertised = ADVERTISED_100baseT_Half;
  87. } else {
  88. if (cmd->base.duplex == DUPLEX_FULL)
  89. autoneg_advertised = ADVERTISED_10baseT_Full;
  90. else
  91. autoneg_advertised = ADVERTISED_10baseT_Half;
  92. }
  93. }
  94. if (hw->autoneg_advertised != autoneg_advertised) {
  95. hw->autoneg_advertised = autoneg_advertised;
  96. if (atl1c_restart_autoneg(hw) != 0) {
  97. if (netif_msg_link(adapter))
  98. dev_warn(&adapter->pdev->dev,
  99. "ethtool speed/duplex setting failed\n");
  100. clear_bit(__AT_RESETTING, &adapter->flags);
  101. return -EINVAL;
  102. }
  103. }
  104. clear_bit(__AT_RESETTING, &adapter->flags);
  105. return 0;
  106. }
  107. static u32 atl1c_get_msglevel(struct net_device *netdev)
  108. {
  109. struct atl1c_adapter *adapter = netdev_priv(netdev);
  110. return adapter->msg_enable;
  111. }
  112. static void atl1c_set_msglevel(struct net_device *netdev, u32 data)
  113. {
  114. struct atl1c_adapter *adapter = netdev_priv(netdev);
  115. adapter->msg_enable = data;
  116. }
  117. static int atl1c_get_regs_len(struct net_device *netdev)
  118. {
  119. return AT_REGS_LEN;
  120. }
  121. static void atl1c_get_regs(struct net_device *netdev,
  122. struct ethtool_regs *regs, void *p)
  123. {
  124. struct atl1c_adapter *adapter = netdev_priv(netdev);
  125. struct atl1c_hw *hw = &adapter->hw;
  126. u32 *regs_buff = p;
  127. u16 phy_data;
  128. memset(p, 0, AT_REGS_LEN);
  129. regs->version = 1;
  130. AT_READ_REG(hw, REG_PM_CTRL, p++);
  131. AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL, p++);
  132. AT_READ_REG(hw, REG_TWSI_CTRL, p++);
  133. AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL, p++);
  134. AT_READ_REG(hw, REG_MASTER_CTRL, p++);
  135. AT_READ_REG(hw, REG_MANUAL_TIMER_INIT, p++);
  136. AT_READ_REG(hw, REG_IRQ_MODRT_TIMER_INIT, p++);
  137. AT_READ_REG(hw, REG_GPHY_CTRL, p++);
  138. AT_READ_REG(hw, REG_LINK_CTRL, p++);
  139. AT_READ_REG(hw, REG_IDLE_STATUS, p++);
  140. AT_READ_REG(hw, REG_MDIO_CTRL, p++);
  141. AT_READ_REG(hw, REG_SERDES, p++);
  142. AT_READ_REG(hw, REG_MAC_CTRL, p++);
  143. AT_READ_REG(hw, REG_MAC_IPG_IFG, p++);
  144. AT_READ_REG(hw, REG_MAC_STA_ADDR, p++);
  145. AT_READ_REG(hw, REG_MAC_STA_ADDR+4, p++);
  146. AT_READ_REG(hw, REG_RX_HASH_TABLE, p++);
  147. AT_READ_REG(hw, REG_RX_HASH_TABLE+4, p++);
  148. AT_READ_REG(hw, REG_RXQ_CTRL, p++);
  149. AT_READ_REG(hw, REG_TXQ_CTRL, p++);
  150. AT_READ_REG(hw, REG_MTU, p++);
  151. AT_READ_REG(hw, REG_WOL_CTRL, p++);
  152. atl1c_read_phy_reg(hw, MII_BMCR, &phy_data);
  153. regs_buff[AT_REGS_LEN/sizeof(u32) - 2] = (u32) phy_data;
  154. atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
  155. regs_buff[AT_REGS_LEN/sizeof(u32) - 1] = (u32) phy_data;
  156. }
  157. static int atl1c_get_eeprom_len(struct net_device *netdev)
  158. {
  159. struct atl1c_adapter *adapter = netdev_priv(netdev);
  160. if (atl1c_check_eeprom_exist(&adapter->hw))
  161. return AT_EEPROM_LEN;
  162. else
  163. return 0;
  164. }
  165. static int atl1c_get_eeprom(struct net_device *netdev,
  166. struct ethtool_eeprom *eeprom, u8 *bytes)
  167. {
  168. struct atl1c_adapter *adapter = netdev_priv(netdev);
  169. struct atl1c_hw *hw = &adapter->hw;
  170. u32 *eeprom_buff;
  171. int first_dword, last_dword;
  172. int ret_val = 0;
  173. int i;
  174. if (eeprom->len == 0)
  175. return -EINVAL;
  176. if (!atl1c_check_eeprom_exist(hw)) /* not exist */
  177. return -EINVAL;
  178. eeprom->magic = adapter->pdev->vendor |
  179. (adapter->pdev->device << 16);
  180. first_dword = eeprom->offset >> 2;
  181. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  182. eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32),
  183. GFP_KERNEL);
  184. if (eeprom_buff == NULL)
  185. return -ENOMEM;
  186. for (i = first_dword; i < last_dword; i++) {
  187. if (!atl1c_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
  188. kfree(eeprom_buff);
  189. return -EIO;
  190. }
  191. }
  192. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
  193. eeprom->len);
  194. kfree(eeprom_buff);
  195. return ret_val;
  196. return 0;
  197. }
  198. static void atl1c_get_drvinfo(struct net_device *netdev,
  199. struct ethtool_drvinfo *drvinfo)
  200. {
  201. struct atl1c_adapter *adapter = netdev_priv(netdev);
  202. strlcpy(drvinfo->driver, atl1c_driver_name, sizeof(drvinfo->driver));
  203. strlcpy(drvinfo->version, atl1c_driver_version,
  204. sizeof(drvinfo->version));
  205. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  206. sizeof(drvinfo->bus_info));
  207. }
  208. static void atl1c_get_wol(struct net_device *netdev,
  209. struct ethtool_wolinfo *wol)
  210. {
  211. struct atl1c_adapter *adapter = netdev_priv(netdev);
  212. wol->supported = WAKE_MAGIC | WAKE_PHY;
  213. wol->wolopts = 0;
  214. if (adapter->wol & AT_WUFC_EX)
  215. wol->wolopts |= WAKE_UCAST;
  216. if (adapter->wol & AT_WUFC_MC)
  217. wol->wolopts |= WAKE_MCAST;
  218. if (adapter->wol & AT_WUFC_BC)
  219. wol->wolopts |= WAKE_BCAST;
  220. if (adapter->wol & AT_WUFC_MAG)
  221. wol->wolopts |= WAKE_MAGIC;
  222. if (adapter->wol & AT_WUFC_LNKC)
  223. wol->wolopts |= WAKE_PHY;
  224. }
  225. static int atl1c_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  226. {
  227. struct atl1c_adapter *adapter = netdev_priv(netdev);
  228. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  229. WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
  230. return -EOPNOTSUPP;
  231. /* these settings will always override what we currently have */
  232. adapter->wol = 0;
  233. if (wol->wolopts & WAKE_MAGIC)
  234. adapter->wol |= AT_WUFC_MAG;
  235. if (wol->wolopts & WAKE_PHY)
  236. adapter->wol |= AT_WUFC_LNKC;
  237. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  238. return 0;
  239. }
  240. static int atl1c_nway_reset(struct net_device *netdev)
  241. {
  242. struct atl1c_adapter *adapter = netdev_priv(netdev);
  243. if (netif_running(netdev))
  244. atl1c_reinit_locked(adapter);
  245. return 0;
  246. }
  247. static const struct ethtool_ops atl1c_ethtool_ops = {
  248. .get_drvinfo = atl1c_get_drvinfo,
  249. .get_regs_len = atl1c_get_regs_len,
  250. .get_regs = atl1c_get_regs,
  251. .get_wol = atl1c_get_wol,
  252. .set_wol = atl1c_set_wol,
  253. .get_msglevel = atl1c_get_msglevel,
  254. .set_msglevel = atl1c_set_msglevel,
  255. .nway_reset = atl1c_nway_reset,
  256. .get_link = ethtool_op_get_link,
  257. .get_eeprom_len = atl1c_get_eeprom_len,
  258. .get_eeprom = atl1c_get_eeprom,
  259. .get_link_ksettings = atl1c_get_link_ksettings,
  260. .set_link_ksettings = atl1c_set_link_ksettings,
  261. };
  262. void atl1c_set_ethtool_ops(struct net_device *netdev)
  263. {
  264. netdev->ethtool_ops = &atl1c_ethtool_ops;
  265. }