atl1c_ethtool.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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_settings(struct net_device *netdev,
  27. struct ethtool_cmd *ecmd)
  28. {
  29. struct atl1c_adapter *adapter = netdev_priv(netdev);
  30. struct atl1c_hw *hw = &adapter->hw;
  31. ecmd->supported = (SUPPORTED_10baseT_Half |
  32. SUPPORTED_10baseT_Full |
  33. SUPPORTED_100baseT_Half |
  34. SUPPORTED_100baseT_Full |
  35. SUPPORTED_Autoneg |
  36. SUPPORTED_TP);
  37. if (hw->link_cap_flags & ATL1C_LINK_CAP_1000M)
  38. ecmd->supported |= SUPPORTED_1000baseT_Full;
  39. ecmd->advertising = ADVERTISED_TP;
  40. ecmd->advertising |= hw->autoneg_advertised;
  41. ecmd->port = PORT_TP;
  42. ecmd->phy_address = 0;
  43. ecmd->transceiver = XCVR_INTERNAL;
  44. if (adapter->link_speed != SPEED_0) {
  45. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  46. if (adapter->link_duplex == FULL_DUPLEX)
  47. ecmd->duplex = DUPLEX_FULL;
  48. else
  49. ecmd->duplex = DUPLEX_HALF;
  50. } else {
  51. ethtool_cmd_speed_set(ecmd, -1);
  52. ecmd->duplex = -1;
  53. }
  54. ecmd->autoneg = AUTONEG_ENABLE;
  55. return 0;
  56. }
  57. static int atl1c_set_settings(struct net_device *netdev,
  58. struct ethtool_cmd *ecmd)
  59. {
  60. struct atl1c_adapter *adapter = netdev_priv(netdev);
  61. struct atl1c_hw *hw = &adapter->hw;
  62. u16 autoneg_advertised;
  63. while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
  64. msleep(1);
  65. if (ecmd->autoneg == AUTONEG_ENABLE) {
  66. autoneg_advertised = ADVERTISED_Autoneg;
  67. } else {
  68. u32 speed = ethtool_cmd_speed(ecmd);
  69. if (speed == SPEED_1000) {
  70. if (ecmd->duplex != DUPLEX_FULL) {
  71. if (netif_msg_link(adapter))
  72. dev_warn(&adapter->pdev->dev,
  73. "1000M half is invalid\n");
  74. clear_bit(__AT_RESETTING, &adapter->flags);
  75. return -EINVAL;
  76. }
  77. autoneg_advertised = ADVERTISED_1000baseT_Full;
  78. } else if (speed == SPEED_100) {
  79. if (ecmd->duplex == DUPLEX_FULL)
  80. autoneg_advertised = ADVERTISED_100baseT_Full;
  81. else
  82. autoneg_advertised = ADVERTISED_100baseT_Half;
  83. } else {
  84. if (ecmd->duplex == DUPLEX_FULL)
  85. autoneg_advertised = ADVERTISED_10baseT_Full;
  86. else
  87. autoneg_advertised = ADVERTISED_10baseT_Half;
  88. }
  89. }
  90. if (hw->autoneg_advertised != autoneg_advertised) {
  91. hw->autoneg_advertised = autoneg_advertised;
  92. if (atl1c_restart_autoneg(hw) != 0) {
  93. if (netif_msg_link(adapter))
  94. dev_warn(&adapter->pdev->dev,
  95. "ethtool speed/duplex setting failed\n");
  96. clear_bit(__AT_RESETTING, &adapter->flags);
  97. return -EINVAL;
  98. }
  99. }
  100. clear_bit(__AT_RESETTING, &adapter->flags);
  101. return 0;
  102. }
  103. static u32 atl1c_get_msglevel(struct net_device *netdev)
  104. {
  105. struct atl1c_adapter *adapter = netdev_priv(netdev);
  106. return adapter->msg_enable;
  107. }
  108. static void atl1c_set_msglevel(struct net_device *netdev, u32 data)
  109. {
  110. struct atl1c_adapter *adapter = netdev_priv(netdev);
  111. adapter->msg_enable = data;
  112. }
  113. static int atl1c_get_regs_len(struct net_device *netdev)
  114. {
  115. return AT_REGS_LEN;
  116. }
  117. static void atl1c_get_regs(struct net_device *netdev,
  118. struct ethtool_regs *regs, void *p)
  119. {
  120. struct atl1c_adapter *adapter = netdev_priv(netdev);
  121. struct atl1c_hw *hw = &adapter->hw;
  122. u32 *regs_buff = p;
  123. u16 phy_data;
  124. memset(p, 0, AT_REGS_LEN);
  125. regs->version = 0;
  126. AT_READ_REG(hw, REG_VPD_CAP, p++);
  127. AT_READ_REG(hw, REG_PM_CTRL, p++);
  128. AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL, p++);
  129. AT_READ_REG(hw, REG_TWSI_CTRL, p++);
  130. AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL, p++);
  131. AT_READ_REG(hw, REG_MASTER_CTRL, p++);
  132. AT_READ_REG(hw, REG_MANUAL_TIMER_INIT, p++);
  133. AT_READ_REG(hw, REG_IRQ_MODRT_TIMER_INIT, p++);
  134. AT_READ_REG(hw, REG_GPHY_CTRL, p++);
  135. AT_READ_REG(hw, REG_LINK_CTRL, p++);
  136. AT_READ_REG(hw, REG_IDLE_STATUS, p++);
  137. AT_READ_REG(hw, REG_MDIO_CTRL, p++);
  138. AT_READ_REG(hw, REG_SERDES_LOCK, p++);
  139. AT_READ_REG(hw, REG_MAC_CTRL, p++);
  140. AT_READ_REG(hw, REG_MAC_IPG_IFG, p++);
  141. AT_READ_REG(hw, REG_MAC_STA_ADDR, p++);
  142. AT_READ_REG(hw, REG_MAC_STA_ADDR+4, p++);
  143. AT_READ_REG(hw, REG_RX_HASH_TABLE, p++);
  144. AT_READ_REG(hw, REG_RX_HASH_TABLE+4, p++);
  145. AT_READ_REG(hw, REG_RXQ_CTRL, p++);
  146. AT_READ_REG(hw, REG_TXQ_CTRL, p++);
  147. AT_READ_REG(hw, REG_MTU, p++);
  148. AT_READ_REG(hw, REG_WOL_CTRL, p++);
  149. atl1c_read_phy_reg(hw, MII_BMCR, &phy_data);
  150. regs_buff[73] = (u32) phy_data;
  151. atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
  152. regs_buff[74] = (u32) phy_data;
  153. }
  154. static int atl1c_get_eeprom_len(struct net_device *netdev)
  155. {
  156. struct atl1c_adapter *adapter = netdev_priv(netdev);
  157. if (atl1c_check_eeprom_exist(&adapter->hw))
  158. return AT_EEPROM_LEN;
  159. else
  160. return 0;
  161. }
  162. static int atl1c_get_eeprom(struct net_device *netdev,
  163. struct ethtool_eeprom *eeprom, u8 *bytes)
  164. {
  165. struct atl1c_adapter *adapter = netdev_priv(netdev);
  166. struct atl1c_hw *hw = &adapter->hw;
  167. u32 *eeprom_buff;
  168. int first_dword, last_dword;
  169. int ret_val = 0;
  170. int i;
  171. if (eeprom->len == 0)
  172. return -EINVAL;
  173. if (!atl1c_check_eeprom_exist(hw)) /* not exist */
  174. return -EINVAL;
  175. eeprom->magic = adapter->pdev->vendor |
  176. (adapter->pdev->device << 16);
  177. first_dword = eeprom->offset >> 2;
  178. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  179. eeprom_buff = kmalloc(sizeof(u32) *
  180. (last_dword - first_dword + 1), GFP_KERNEL);
  181. if (eeprom_buff == NULL)
  182. return -ENOMEM;
  183. for (i = first_dword; i < last_dword; i++) {
  184. if (!atl1c_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
  185. kfree(eeprom_buff);
  186. return -EIO;
  187. }
  188. }
  189. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
  190. eeprom->len);
  191. kfree(eeprom_buff);
  192. return ret_val;
  193. return 0;
  194. }
  195. static void atl1c_get_drvinfo(struct net_device *netdev,
  196. struct ethtool_drvinfo *drvinfo)
  197. {
  198. struct atl1c_adapter *adapter = netdev_priv(netdev);
  199. strlcpy(drvinfo->driver, atl1c_driver_name, sizeof(drvinfo->driver));
  200. strlcpy(drvinfo->version, atl1c_driver_version,
  201. sizeof(drvinfo->version));
  202. strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  203. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  204. sizeof(drvinfo->bus_info));
  205. drvinfo->n_stats = 0;
  206. drvinfo->testinfo_len = 0;
  207. drvinfo->regdump_len = atl1c_get_regs_len(netdev);
  208. drvinfo->eedump_len = atl1c_get_eeprom_len(netdev);
  209. }
  210. static void atl1c_get_wol(struct net_device *netdev,
  211. struct ethtool_wolinfo *wol)
  212. {
  213. struct atl1c_adapter *adapter = netdev_priv(netdev);
  214. wol->supported = WAKE_MAGIC | WAKE_PHY;
  215. wol->wolopts = 0;
  216. if (adapter->wol & AT_WUFC_EX)
  217. wol->wolopts |= WAKE_UCAST;
  218. if (adapter->wol & AT_WUFC_MC)
  219. wol->wolopts |= WAKE_MCAST;
  220. if (adapter->wol & AT_WUFC_BC)
  221. wol->wolopts |= WAKE_BCAST;
  222. if (adapter->wol & AT_WUFC_MAG)
  223. wol->wolopts |= WAKE_MAGIC;
  224. if (adapter->wol & AT_WUFC_LNKC)
  225. wol->wolopts |= WAKE_PHY;
  226. }
  227. static int atl1c_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  228. {
  229. struct atl1c_adapter *adapter = netdev_priv(netdev);
  230. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  231. WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
  232. return -EOPNOTSUPP;
  233. /* these settings will always override what we currently have */
  234. adapter->wol = 0;
  235. if (wol->wolopts & WAKE_MAGIC)
  236. adapter->wol |= AT_WUFC_MAG;
  237. if (wol->wolopts & WAKE_PHY)
  238. adapter->wol |= AT_WUFC_LNKC;
  239. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  240. return 0;
  241. }
  242. static int atl1c_nway_reset(struct net_device *netdev)
  243. {
  244. struct atl1c_adapter *adapter = netdev_priv(netdev);
  245. if (netif_running(netdev))
  246. atl1c_reinit_locked(adapter);
  247. return 0;
  248. }
  249. static const struct ethtool_ops atl1c_ethtool_ops = {
  250. .get_settings = atl1c_get_settings,
  251. .set_settings = atl1c_set_settings,
  252. .get_drvinfo = atl1c_get_drvinfo,
  253. .get_regs_len = atl1c_get_regs_len,
  254. .get_regs = atl1c_get_regs,
  255. .get_wol = atl1c_get_wol,
  256. .set_wol = atl1c_set_wol,
  257. .get_msglevel = atl1c_get_msglevel,
  258. .set_msglevel = atl1c_set_msglevel,
  259. .nway_reset = atl1c_nway_reset,
  260. .get_link = ethtool_op_get_link,
  261. .get_eeprom_len = atl1c_get_eeprom_len,
  262. .get_eeprom = atl1c_get_eeprom,
  263. };
  264. void atl1c_set_ethtool_ops(struct net_device *netdev)
  265. {
  266. SET_ETHTOOL_OPS(netdev, &atl1c_ethtool_ops);
  267. }