atl1c_ethtool.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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, SPEED_UNKNOWN);
  52. ecmd->duplex = DUPLEX_UNKNOWN;
  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 = 1;
  126. AT_READ_REG(hw, REG_PM_CTRL, p++);
  127. AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL, p++);
  128. AT_READ_REG(hw, REG_TWSI_CTRL, p++);
  129. AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL, p++);
  130. AT_READ_REG(hw, REG_MASTER_CTRL, p++);
  131. AT_READ_REG(hw, REG_MANUAL_TIMER_INIT, p++);
  132. AT_READ_REG(hw, REG_IRQ_MODRT_TIMER_INIT, p++);
  133. AT_READ_REG(hw, REG_GPHY_CTRL, p++);
  134. AT_READ_REG(hw, REG_LINK_CTRL, p++);
  135. AT_READ_REG(hw, REG_IDLE_STATUS, p++);
  136. AT_READ_REG(hw, REG_MDIO_CTRL, p++);
  137. AT_READ_REG(hw, REG_SERDES, p++);
  138. AT_READ_REG(hw, REG_MAC_CTRL, p++);
  139. AT_READ_REG(hw, REG_MAC_IPG_IFG, p++);
  140. AT_READ_REG(hw, REG_MAC_STA_ADDR, p++);
  141. AT_READ_REG(hw, REG_MAC_STA_ADDR+4, p++);
  142. AT_READ_REG(hw, REG_RX_HASH_TABLE, p++);
  143. AT_READ_REG(hw, REG_RX_HASH_TABLE+4, p++);
  144. AT_READ_REG(hw, REG_RXQ_CTRL, p++);
  145. AT_READ_REG(hw, REG_TXQ_CTRL, p++);
  146. AT_READ_REG(hw, REG_MTU, p++);
  147. AT_READ_REG(hw, REG_WOL_CTRL, p++);
  148. atl1c_read_phy_reg(hw, MII_BMCR, &phy_data);
  149. regs_buff[AT_REGS_LEN/sizeof(u32) - 2] = (u32) phy_data;
  150. atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
  151. regs_buff[AT_REGS_LEN/sizeof(u32) - 1] = (u32) phy_data;
  152. }
  153. static int atl1c_get_eeprom_len(struct net_device *netdev)
  154. {
  155. struct atl1c_adapter *adapter = netdev_priv(netdev);
  156. if (atl1c_check_eeprom_exist(&adapter->hw))
  157. return AT_EEPROM_LEN;
  158. else
  159. return 0;
  160. }
  161. static int atl1c_get_eeprom(struct net_device *netdev,
  162. struct ethtool_eeprom *eeprom, u8 *bytes)
  163. {
  164. struct atl1c_adapter *adapter = netdev_priv(netdev);
  165. struct atl1c_hw *hw = &adapter->hw;
  166. u32 *eeprom_buff;
  167. int first_dword, last_dword;
  168. int ret_val = 0;
  169. int i;
  170. if (eeprom->len == 0)
  171. return -EINVAL;
  172. if (!atl1c_check_eeprom_exist(hw)) /* not exist */
  173. return -EINVAL;
  174. eeprom->magic = adapter->pdev->vendor |
  175. (adapter->pdev->device << 16);
  176. first_dword = eeprom->offset >> 2;
  177. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  178. eeprom_buff = kmalloc(sizeof(u32) *
  179. (last_dword - first_dword + 1), GFP_KERNEL);
  180. if (eeprom_buff == NULL)
  181. return -ENOMEM;
  182. for (i = first_dword; i < last_dword; i++) {
  183. if (!atl1c_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
  184. kfree(eeprom_buff);
  185. return -EIO;
  186. }
  187. }
  188. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
  189. eeprom->len);
  190. kfree(eeprom_buff);
  191. return ret_val;
  192. return 0;
  193. }
  194. static void atl1c_get_drvinfo(struct net_device *netdev,
  195. struct ethtool_drvinfo *drvinfo)
  196. {
  197. struct atl1c_adapter *adapter = netdev_priv(netdev);
  198. strlcpy(drvinfo->driver, atl1c_driver_name, sizeof(drvinfo->driver));
  199. strlcpy(drvinfo->version, atl1c_driver_version,
  200. sizeof(drvinfo->version));
  201. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  202. sizeof(drvinfo->bus_info));
  203. }
  204. static void atl1c_get_wol(struct net_device *netdev,
  205. struct ethtool_wolinfo *wol)
  206. {
  207. struct atl1c_adapter *adapter = netdev_priv(netdev);
  208. wol->supported = WAKE_MAGIC | WAKE_PHY;
  209. wol->wolopts = 0;
  210. if (adapter->wol & AT_WUFC_EX)
  211. wol->wolopts |= WAKE_UCAST;
  212. if (adapter->wol & AT_WUFC_MC)
  213. wol->wolopts |= WAKE_MCAST;
  214. if (adapter->wol & AT_WUFC_BC)
  215. wol->wolopts |= WAKE_BCAST;
  216. if (adapter->wol & AT_WUFC_MAG)
  217. wol->wolopts |= WAKE_MAGIC;
  218. if (adapter->wol & AT_WUFC_LNKC)
  219. wol->wolopts |= WAKE_PHY;
  220. }
  221. static int atl1c_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  222. {
  223. struct atl1c_adapter *adapter = netdev_priv(netdev);
  224. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  225. WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
  226. return -EOPNOTSUPP;
  227. /* these settings will always override what we currently have */
  228. adapter->wol = 0;
  229. if (wol->wolopts & WAKE_MAGIC)
  230. adapter->wol |= AT_WUFC_MAG;
  231. if (wol->wolopts & WAKE_PHY)
  232. adapter->wol |= AT_WUFC_LNKC;
  233. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  234. return 0;
  235. }
  236. static int atl1c_nway_reset(struct net_device *netdev)
  237. {
  238. struct atl1c_adapter *adapter = netdev_priv(netdev);
  239. if (netif_running(netdev))
  240. atl1c_reinit_locked(adapter);
  241. return 0;
  242. }
  243. static const struct ethtool_ops atl1c_ethtool_ops = {
  244. .get_settings = atl1c_get_settings,
  245. .set_settings = atl1c_set_settings,
  246. .get_drvinfo = atl1c_get_drvinfo,
  247. .get_regs_len = atl1c_get_regs_len,
  248. .get_regs = atl1c_get_regs,
  249. .get_wol = atl1c_get_wol,
  250. .set_wol = atl1c_set_wol,
  251. .get_msglevel = atl1c_get_msglevel,
  252. .set_msglevel = atl1c_set_msglevel,
  253. .nway_reset = atl1c_nway_reset,
  254. .get_link = ethtool_op_get_link,
  255. .get_eeprom_len = atl1c_get_eeprom_len,
  256. .get_eeprom = atl1c_get_eeprom,
  257. };
  258. void atl1c_set_ethtool_ops(struct net_device *netdev)
  259. {
  260. netdev->ethtool_ops = &atl1c_ethtool_ops;
  261. }