atl1c_ethtool.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. ecmd->speed = 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. ecmd->speed = -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. if (ecmd->speed == SPEED_1000) {
  69. if (ecmd->duplex != DUPLEX_FULL) {
  70. if (netif_msg_link(adapter))
  71. dev_warn(&adapter->pdev->dev,
  72. "1000M half is invalid\n");
  73. clear_bit(__AT_RESETTING, &adapter->flags);
  74. return -EINVAL;
  75. }
  76. autoneg_advertised = ADVERTISED_1000baseT_Full;
  77. } else if (ecmd->speed == SPEED_100) {
  78. if (ecmd->duplex == DUPLEX_FULL)
  79. autoneg_advertised = ADVERTISED_100baseT_Full;
  80. else
  81. autoneg_advertised = ADVERTISED_100baseT_Half;
  82. } else {
  83. if (ecmd->duplex == DUPLEX_FULL)
  84. autoneg_advertised = ADVERTISED_10baseT_Full;
  85. else
  86. autoneg_advertised = ADVERTISED_10baseT_Half;
  87. }
  88. }
  89. if (hw->autoneg_advertised != autoneg_advertised) {
  90. hw->autoneg_advertised = autoneg_advertised;
  91. if (atl1c_restart_autoneg(hw) != 0) {
  92. if (netif_msg_link(adapter))
  93. dev_warn(&adapter->pdev->dev,
  94. "ethtool speed/duplex setting failed\n");
  95. clear_bit(__AT_RESETTING, &adapter->flags);
  96. return -EINVAL;
  97. }
  98. }
  99. clear_bit(__AT_RESETTING, &adapter->flags);
  100. return 0;
  101. }
  102. static u32 atl1c_get_tx_csum(struct net_device *netdev)
  103. {
  104. return (netdev->features & NETIF_F_HW_CSUM) != 0;
  105. }
  106. static u32 atl1c_get_msglevel(struct net_device *netdev)
  107. {
  108. struct atl1c_adapter *adapter = netdev_priv(netdev);
  109. return adapter->msg_enable;
  110. }
  111. static void atl1c_set_msglevel(struct net_device *netdev, u32 data)
  112. {
  113. struct atl1c_adapter *adapter = netdev_priv(netdev);
  114. adapter->msg_enable = data;
  115. }
  116. static int atl1c_get_regs_len(struct net_device *netdev)
  117. {
  118. return AT_REGS_LEN;
  119. }
  120. static void atl1c_get_regs(struct net_device *netdev,
  121. struct ethtool_regs *regs, void *p)
  122. {
  123. struct atl1c_adapter *adapter = netdev_priv(netdev);
  124. struct atl1c_hw *hw = &adapter->hw;
  125. u32 *regs_buff = p;
  126. u16 phy_data;
  127. memset(p, 0, AT_REGS_LEN);
  128. regs->version = 0;
  129. AT_READ_REG(hw, REG_VPD_CAP, p++);
  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_LOCK, 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[73] = (u32) phy_data;
  154. atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
  155. regs_buff[74] = (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(sizeof(u32) *
  183. (last_dword - first_dword + 1), 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->fw_version, "N/A", sizeof(drvinfo->fw_version));
  206. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  207. sizeof(drvinfo->bus_info));
  208. drvinfo->n_stats = 0;
  209. drvinfo->testinfo_len = 0;
  210. drvinfo->regdump_len = atl1c_get_regs_len(netdev);
  211. drvinfo->eedump_len = atl1c_get_eeprom_len(netdev);
  212. }
  213. static void atl1c_get_wol(struct net_device *netdev,
  214. struct ethtool_wolinfo *wol)
  215. {
  216. struct atl1c_adapter *adapter = netdev_priv(netdev);
  217. wol->supported = WAKE_MAGIC | WAKE_PHY;
  218. wol->wolopts = 0;
  219. if (adapter->wol & AT_WUFC_EX)
  220. wol->wolopts |= WAKE_UCAST;
  221. if (adapter->wol & AT_WUFC_MC)
  222. wol->wolopts |= WAKE_MCAST;
  223. if (adapter->wol & AT_WUFC_BC)
  224. wol->wolopts |= WAKE_BCAST;
  225. if (adapter->wol & AT_WUFC_MAG)
  226. wol->wolopts |= WAKE_MAGIC;
  227. if (adapter->wol & AT_WUFC_LNKC)
  228. wol->wolopts |= WAKE_PHY;
  229. }
  230. static int atl1c_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  231. {
  232. struct atl1c_adapter *adapter = netdev_priv(netdev);
  233. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  234. WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
  235. return -EOPNOTSUPP;
  236. /* these settings will always override what we currently have */
  237. adapter->wol = 0;
  238. if (wol->wolopts & WAKE_MAGIC)
  239. adapter->wol |= AT_WUFC_MAG;
  240. if (wol->wolopts & WAKE_PHY)
  241. adapter->wol |= AT_WUFC_LNKC;
  242. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  243. return 0;
  244. }
  245. static int atl1c_nway_reset(struct net_device *netdev)
  246. {
  247. struct atl1c_adapter *adapter = netdev_priv(netdev);
  248. if (netif_running(netdev))
  249. atl1c_reinit_locked(adapter);
  250. return 0;
  251. }
  252. static const struct ethtool_ops atl1c_ethtool_ops = {
  253. .get_settings = atl1c_get_settings,
  254. .set_settings = atl1c_set_settings,
  255. .get_drvinfo = atl1c_get_drvinfo,
  256. .get_regs_len = atl1c_get_regs_len,
  257. .get_regs = atl1c_get_regs,
  258. .get_wol = atl1c_get_wol,
  259. .set_wol = atl1c_set_wol,
  260. .get_msglevel = atl1c_get_msglevel,
  261. .set_msglevel = atl1c_set_msglevel,
  262. .nway_reset = atl1c_nway_reset,
  263. .get_link = ethtool_op_get_link,
  264. .get_eeprom_len = atl1c_get_eeprom_len,
  265. .get_eeprom = atl1c_get_eeprom,
  266. .get_tx_csum = atl1c_get_tx_csum,
  267. .get_sg = ethtool_op_get_sg,
  268. .set_sg = ethtool_op_set_sg,
  269. };
  270. void atl1c_set_ethtool_ops(struct net_device *netdev)
  271. {
  272. SET_ETHTOOL_OPS(netdev, &atl1c_ethtool_ops);
  273. }