atl1c_ethtool.c 8.9 KB

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