atl1e_ethtool.c 11 KB

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