atl1e_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * Copyright(c) 2007 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 "atl1e.h"
  26. static int atl1e_get_settings(struct net_device *netdev,
  27. struct ethtool_cmd *ecmd)
  28. {
  29. struct atl1e_adapter *adapter = netdev_priv(netdev);
  30. struct atl1e_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->nic_type == athr_l1e)
  38. ecmd->supported |= SUPPORTED_1000baseT_Full;
  39. ecmd->advertising = ADVERTISED_TP;
  40. ecmd->advertising |= ADVERTISED_Autoneg;
  41. ecmd->advertising |= hw->autoneg_advertised;
  42. ecmd->port = PORT_TP;
  43. ecmd->phy_address = 0;
  44. ecmd->transceiver = XCVR_INTERNAL;
  45. if (adapter->link_speed != SPEED_0) {
  46. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  47. if (adapter->link_duplex == FULL_DUPLEX)
  48. ecmd->duplex = DUPLEX_FULL;
  49. else
  50. ecmd->duplex = DUPLEX_HALF;
  51. } else {
  52. ethtool_cmd_speed_set(ecmd, -1);
  53. ecmd->duplex = -1;
  54. }
  55. ecmd->autoneg = AUTONEG_ENABLE;
  56. return 0;
  57. }
  58. static int atl1e_set_settings(struct net_device *netdev,
  59. struct ethtool_cmd *ecmd)
  60. {
  61. struct atl1e_adapter *adapter = netdev_priv(netdev);
  62. struct atl1e_hw *hw = &adapter->hw;
  63. while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
  64. msleep(1);
  65. if (ecmd->autoneg == AUTONEG_ENABLE) {
  66. u16 adv4, adv9;
  67. if ((ecmd->advertising&ADVERTISE_1000_FULL)) {
  68. if (hw->nic_type == athr_l1e) {
  69. hw->autoneg_advertised =
  70. ecmd->advertising & AT_ADV_MASK;
  71. } else {
  72. clear_bit(__AT_RESETTING, &adapter->flags);
  73. return -EINVAL;
  74. }
  75. } else if (ecmd->advertising&ADVERTISE_1000_HALF) {
  76. clear_bit(__AT_RESETTING, &adapter->flags);
  77. return -EINVAL;
  78. } else {
  79. hw->autoneg_advertised =
  80. ecmd->advertising & AT_ADV_MASK;
  81. }
  82. ecmd->advertising = hw->autoneg_advertised |
  83. ADVERTISED_TP | ADVERTISED_Autoneg;
  84. adv4 = hw->mii_autoneg_adv_reg & ~ADVERTISE_ALL;
  85. adv9 = hw->mii_1000t_ctrl_reg & ~MII_AT001_CR_1000T_SPEED_MASK;
  86. if (hw->autoneg_advertised & ADVERTISE_10_HALF)
  87. adv4 |= ADVERTISE_10HALF;
  88. if (hw->autoneg_advertised & ADVERTISE_10_FULL)
  89. adv4 |= ADVERTISE_10FULL;
  90. if (hw->autoneg_advertised & ADVERTISE_100_HALF)
  91. adv4 |= ADVERTISE_100HALF;
  92. if (hw->autoneg_advertised & ADVERTISE_100_FULL)
  93. adv4 |= ADVERTISE_100FULL;
  94. if (hw->autoneg_advertised & ADVERTISE_1000_FULL)
  95. adv9 |= ADVERTISE_1000FULL;
  96. if (adv4 != hw->mii_autoneg_adv_reg ||
  97. adv9 != hw->mii_1000t_ctrl_reg) {
  98. hw->mii_autoneg_adv_reg = adv4;
  99. hw->mii_1000t_ctrl_reg = adv9;
  100. hw->re_autoneg = true;
  101. }
  102. } else {
  103. clear_bit(__AT_RESETTING, &adapter->flags);
  104. return -EINVAL;
  105. }
  106. /* reset the link */
  107. if (netif_running(adapter->netdev)) {
  108. atl1e_down(adapter);
  109. atl1e_up(adapter);
  110. } else
  111. atl1e_reset_hw(&adapter->hw);
  112. clear_bit(__AT_RESETTING, &adapter->flags);
  113. return 0;
  114. }
  115. static u32 atl1e_get_msglevel(struct net_device *netdev)
  116. {
  117. #ifdef DBG
  118. return 1;
  119. #else
  120. return 0;
  121. #endif
  122. }
  123. static int atl1e_get_regs_len(struct net_device *netdev)
  124. {
  125. return AT_REGS_LEN * sizeof(u32);
  126. }
  127. static void atl1e_get_regs(struct net_device *netdev,
  128. struct ethtool_regs *regs, void *p)
  129. {
  130. struct atl1e_adapter *adapter = netdev_priv(netdev);
  131. struct atl1e_hw *hw = &adapter->hw;
  132. u32 *regs_buff = p;
  133. u16 phy_data;
  134. memset(p, 0, AT_REGS_LEN * sizeof(u32));
  135. regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  136. regs_buff[0] = AT_READ_REG(hw, REG_VPD_CAP);
  137. regs_buff[1] = AT_READ_REG(hw, REG_SPI_FLASH_CTRL);
  138. regs_buff[2] = AT_READ_REG(hw, REG_SPI_FLASH_CONFIG);
  139. regs_buff[3] = AT_READ_REG(hw, REG_TWSI_CTRL);
  140. regs_buff[4] = AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL);
  141. regs_buff[5] = AT_READ_REG(hw, REG_MASTER_CTRL);
  142. regs_buff[6] = AT_READ_REG(hw, REG_MANUAL_TIMER_INIT);
  143. regs_buff[7] = AT_READ_REG(hw, REG_IRQ_MODU_TIMER_INIT);
  144. regs_buff[8] = AT_READ_REG(hw, REG_GPHY_CTRL);
  145. regs_buff[9] = AT_READ_REG(hw, REG_CMBDISDMA_TIMER);
  146. regs_buff[10] = AT_READ_REG(hw, REG_IDLE_STATUS);
  147. regs_buff[11] = AT_READ_REG(hw, REG_MDIO_CTRL);
  148. regs_buff[12] = AT_READ_REG(hw, REG_SERDES_LOCK);
  149. regs_buff[13] = AT_READ_REG(hw, REG_MAC_CTRL);
  150. regs_buff[14] = AT_READ_REG(hw, REG_MAC_IPG_IFG);
  151. regs_buff[15] = AT_READ_REG(hw, REG_MAC_STA_ADDR);
  152. regs_buff[16] = AT_READ_REG(hw, REG_MAC_STA_ADDR+4);
  153. regs_buff[17] = AT_READ_REG(hw, REG_RX_HASH_TABLE);
  154. regs_buff[18] = AT_READ_REG(hw, REG_RX_HASH_TABLE+4);
  155. regs_buff[19] = AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL);
  156. regs_buff[20] = AT_READ_REG(hw, REG_MTU);
  157. regs_buff[21] = AT_READ_REG(hw, REG_WOL_CTRL);
  158. regs_buff[22] = AT_READ_REG(hw, REG_SRAM_TRD_ADDR);
  159. regs_buff[23] = AT_READ_REG(hw, REG_SRAM_TRD_LEN);
  160. regs_buff[24] = AT_READ_REG(hw, REG_SRAM_RXF_ADDR);
  161. regs_buff[25] = AT_READ_REG(hw, REG_SRAM_RXF_LEN);
  162. regs_buff[26] = AT_READ_REG(hw, REG_SRAM_TXF_ADDR);
  163. regs_buff[27] = AT_READ_REG(hw, REG_SRAM_TXF_LEN);
  164. regs_buff[28] = AT_READ_REG(hw, REG_SRAM_TCPH_ADDR);
  165. regs_buff[29] = AT_READ_REG(hw, REG_SRAM_PKTH_ADDR);
  166. atl1e_read_phy_reg(hw, MII_BMCR, &phy_data);
  167. regs_buff[73] = (u32)phy_data;
  168. atl1e_read_phy_reg(hw, MII_BMSR, &phy_data);
  169. regs_buff[74] = (u32)phy_data;
  170. }
  171. static int atl1e_get_eeprom_len(struct net_device *netdev)
  172. {
  173. struct atl1e_adapter *adapter = netdev_priv(netdev);
  174. if (!atl1e_check_eeprom_exist(&adapter->hw))
  175. return AT_EEPROM_LEN;
  176. else
  177. return 0;
  178. }
  179. static int atl1e_get_eeprom(struct net_device *netdev,
  180. struct ethtool_eeprom *eeprom, u8 *bytes)
  181. {
  182. struct atl1e_adapter *adapter = netdev_priv(netdev);
  183. struct atl1e_hw *hw = &adapter->hw;
  184. u32 *eeprom_buff;
  185. int first_dword, last_dword;
  186. int ret_val = 0;
  187. int i;
  188. if (eeprom->len == 0)
  189. return -EINVAL;
  190. if (atl1e_check_eeprom_exist(hw)) /* not exist */
  191. return -EINVAL;
  192. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  193. first_dword = eeprom->offset >> 2;
  194. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  195. eeprom_buff = kmalloc(sizeof(u32) *
  196. (last_dword - first_dword + 1), GFP_KERNEL);
  197. if (eeprom_buff == NULL)
  198. return -ENOMEM;
  199. for (i = first_dword; i < last_dword; i++) {
  200. if (!atl1e_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
  201. kfree(eeprom_buff);
  202. return -EIO;
  203. }
  204. }
  205. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
  206. eeprom->len);
  207. kfree(eeprom_buff);
  208. return ret_val;
  209. }
  210. static int atl1e_set_eeprom(struct net_device *netdev,
  211. struct ethtool_eeprom *eeprom, u8 *bytes)
  212. {
  213. struct atl1e_adapter *adapter = netdev_priv(netdev);
  214. struct atl1e_hw *hw = &adapter->hw;
  215. u32 *eeprom_buff;
  216. u32 *ptr;
  217. int first_dword, last_dword;
  218. int ret_val = 0;
  219. int i;
  220. if (eeprom->len == 0)
  221. return -EOPNOTSUPP;
  222. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  223. return -EINVAL;
  224. first_dword = eeprom->offset >> 2;
  225. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  226. eeprom_buff = kmalloc(AT_EEPROM_LEN, GFP_KERNEL);
  227. if (eeprom_buff == NULL)
  228. return -ENOMEM;
  229. ptr = eeprom_buff;
  230. if (eeprom->offset & 3) {
  231. /* need read/modify/write of first changed EEPROM word */
  232. /* only the second byte of the word is being modified */
  233. if (!atl1e_read_eeprom(hw, first_dword * 4, &(eeprom_buff[0]))) {
  234. ret_val = -EIO;
  235. goto out;
  236. }
  237. ptr++;
  238. }
  239. if (((eeprom->offset + eeprom->len) & 3)) {
  240. /* need read/modify/write of last changed EEPROM word */
  241. /* only the first byte of the word is being modified */
  242. if (!atl1e_read_eeprom(hw, last_dword * 4,
  243. &(eeprom_buff[last_dword - first_dword]))) {
  244. ret_val = -EIO;
  245. goto out;
  246. }
  247. }
  248. /* Device's eeprom is always little-endian, word addressable */
  249. memcpy(ptr, bytes, eeprom->len);
  250. for (i = 0; i < last_dword - first_dword + 1; i++) {
  251. if (!atl1e_write_eeprom(hw, ((first_dword + i) * 4),
  252. eeprom_buff[i])) {
  253. ret_val = -EIO;
  254. goto out;
  255. }
  256. }
  257. out:
  258. kfree(eeprom_buff);
  259. return ret_val;
  260. }
  261. static void atl1e_get_drvinfo(struct net_device *netdev,
  262. struct ethtool_drvinfo *drvinfo)
  263. {
  264. struct atl1e_adapter *adapter = netdev_priv(netdev);
  265. strlcpy(drvinfo->driver, atl1e_driver_name, sizeof(drvinfo->driver));
  266. strlcpy(drvinfo->version, atl1e_driver_version,
  267. sizeof(drvinfo->version));
  268. strlcpy(drvinfo->fw_version, "L1e", sizeof(drvinfo->fw_version));
  269. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  270. sizeof(drvinfo->bus_info));
  271. drvinfo->n_stats = 0;
  272. drvinfo->testinfo_len = 0;
  273. drvinfo->regdump_len = atl1e_get_regs_len(netdev);
  274. drvinfo->eedump_len = atl1e_get_eeprom_len(netdev);
  275. }
  276. static void atl1e_get_wol(struct net_device *netdev,
  277. struct ethtool_wolinfo *wol)
  278. {
  279. struct atl1e_adapter *adapter = netdev_priv(netdev);
  280. wol->supported = WAKE_MAGIC | WAKE_PHY;
  281. wol->wolopts = 0;
  282. if (adapter->wol & AT_WUFC_EX)
  283. wol->wolopts |= WAKE_UCAST;
  284. if (adapter->wol & AT_WUFC_MC)
  285. wol->wolopts |= WAKE_MCAST;
  286. if (adapter->wol & AT_WUFC_BC)
  287. wol->wolopts |= WAKE_BCAST;
  288. if (adapter->wol & AT_WUFC_MAG)
  289. wol->wolopts |= WAKE_MAGIC;
  290. if (adapter->wol & AT_WUFC_LNKC)
  291. wol->wolopts |= WAKE_PHY;
  292. }
  293. static int atl1e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  294. {
  295. struct atl1e_adapter *adapter = netdev_priv(netdev);
  296. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  297. WAKE_UCAST | WAKE_MCAST | WAKE_BCAST))
  298. return -EOPNOTSUPP;
  299. /* these settings will always override what we currently have */
  300. adapter->wol = 0;
  301. if (wol->wolopts & WAKE_MAGIC)
  302. adapter->wol |= AT_WUFC_MAG;
  303. if (wol->wolopts & WAKE_PHY)
  304. adapter->wol |= AT_WUFC_LNKC;
  305. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  306. return 0;
  307. }
  308. static int atl1e_nway_reset(struct net_device *netdev)
  309. {
  310. struct atl1e_adapter *adapter = netdev_priv(netdev);
  311. if (netif_running(netdev))
  312. atl1e_reinit_locked(adapter);
  313. return 0;
  314. }
  315. static const struct ethtool_ops atl1e_ethtool_ops = {
  316. .get_settings = atl1e_get_settings,
  317. .set_settings = atl1e_set_settings,
  318. .get_drvinfo = atl1e_get_drvinfo,
  319. .get_regs_len = atl1e_get_regs_len,
  320. .get_regs = atl1e_get_regs,
  321. .get_wol = atl1e_get_wol,
  322. .set_wol = atl1e_set_wol,
  323. .get_msglevel = atl1e_get_msglevel,
  324. .nway_reset = atl1e_nway_reset,
  325. .get_link = ethtool_op_get_link,
  326. .get_eeprom_len = atl1e_get_eeprom_len,
  327. .get_eeprom = atl1e_get_eeprom,
  328. .set_eeprom = atl1e_set_eeprom,
  329. };
  330. void atl1e_set_ethtool_ops(struct net_device *netdev)
  331. {
  332. SET_ETHTOOL_OPS(netdev, &atl1e_ethtool_ops);
  333. }