atl1e_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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_tx_csum(struct net_device *netdev)
  115. {
  116. return (netdev->features & NETIF_F_HW_CSUM) != 0;
  117. }
  118. static u32 atl1e_get_msglevel(struct net_device *netdev)
  119. {
  120. #ifdef DBG
  121. return 1;
  122. #else
  123. return 0;
  124. #endif
  125. }
  126. static void atl1e_set_msglevel(struct net_device *netdev, u32 data)
  127. {
  128. }
  129. static int atl1e_get_regs_len(struct net_device *netdev)
  130. {
  131. return AT_REGS_LEN * sizeof(u32);
  132. }
  133. static void atl1e_get_regs(struct net_device *netdev,
  134. struct ethtool_regs *regs, void *p)
  135. {
  136. struct atl1e_adapter *adapter = netdev_priv(netdev);
  137. struct atl1e_hw *hw = &adapter->hw;
  138. u32 *regs_buff = p;
  139. u16 phy_data;
  140. memset(p, 0, AT_REGS_LEN * sizeof(u32));
  141. regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  142. regs_buff[0] = AT_READ_REG(hw, REG_VPD_CAP);
  143. regs_buff[1] = AT_READ_REG(hw, REG_SPI_FLASH_CTRL);
  144. regs_buff[2] = AT_READ_REG(hw, REG_SPI_FLASH_CONFIG);
  145. regs_buff[3] = AT_READ_REG(hw, REG_TWSI_CTRL);
  146. regs_buff[4] = AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL);
  147. regs_buff[5] = AT_READ_REG(hw, REG_MASTER_CTRL);
  148. regs_buff[6] = AT_READ_REG(hw, REG_MANUAL_TIMER_INIT);
  149. regs_buff[7] = AT_READ_REG(hw, REG_IRQ_MODU_TIMER_INIT);
  150. regs_buff[8] = AT_READ_REG(hw, REG_GPHY_CTRL);
  151. regs_buff[9] = AT_READ_REG(hw, REG_CMBDISDMA_TIMER);
  152. regs_buff[10] = AT_READ_REG(hw, REG_IDLE_STATUS);
  153. regs_buff[11] = AT_READ_REG(hw, REG_MDIO_CTRL);
  154. regs_buff[12] = AT_READ_REG(hw, REG_SERDES_LOCK);
  155. regs_buff[13] = AT_READ_REG(hw, REG_MAC_CTRL);
  156. regs_buff[14] = AT_READ_REG(hw, REG_MAC_IPG_IFG);
  157. regs_buff[15] = AT_READ_REG(hw, REG_MAC_STA_ADDR);
  158. regs_buff[16] = AT_READ_REG(hw, REG_MAC_STA_ADDR+4);
  159. regs_buff[17] = AT_READ_REG(hw, REG_RX_HASH_TABLE);
  160. regs_buff[18] = AT_READ_REG(hw, REG_RX_HASH_TABLE+4);
  161. regs_buff[19] = AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL);
  162. regs_buff[20] = AT_READ_REG(hw, REG_MTU);
  163. regs_buff[21] = AT_READ_REG(hw, REG_WOL_CTRL);
  164. regs_buff[22] = AT_READ_REG(hw, REG_SRAM_TRD_ADDR);
  165. regs_buff[23] = AT_READ_REG(hw, REG_SRAM_TRD_LEN);
  166. regs_buff[24] = AT_READ_REG(hw, REG_SRAM_RXF_ADDR);
  167. regs_buff[25] = AT_READ_REG(hw, REG_SRAM_RXF_LEN);
  168. regs_buff[26] = AT_READ_REG(hw, REG_SRAM_TXF_ADDR);
  169. regs_buff[27] = AT_READ_REG(hw, REG_SRAM_TXF_LEN);
  170. regs_buff[28] = AT_READ_REG(hw, REG_SRAM_TCPH_ADDR);
  171. regs_buff[29] = AT_READ_REG(hw, REG_SRAM_PKTH_ADDR);
  172. atl1e_read_phy_reg(hw, MII_BMCR, &phy_data);
  173. regs_buff[73] = (u32)phy_data;
  174. atl1e_read_phy_reg(hw, MII_BMSR, &phy_data);
  175. regs_buff[74] = (u32)phy_data;
  176. }
  177. static int atl1e_get_eeprom_len(struct net_device *netdev)
  178. {
  179. struct atl1e_adapter *adapter = netdev_priv(netdev);
  180. if (!atl1e_check_eeprom_exist(&adapter->hw))
  181. return AT_EEPROM_LEN;
  182. else
  183. return 0;
  184. }
  185. static int atl1e_get_eeprom(struct net_device *netdev,
  186. struct ethtool_eeprom *eeprom, u8 *bytes)
  187. {
  188. struct atl1e_adapter *adapter = netdev_priv(netdev);
  189. struct atl1e_hw *hw = &adapter->hw;
  190. u32 *eeprom_buff;
  191. int first_dword, last_dword;
  192. int ret_val = 0;
  193. int i;
  194. if (eeprom->len == 0)
  195. return -EINVAL;
  196. if (atl1e_check_eeprom_exist(hw)) /* not exist */
  197. return -EINVAL;
  198. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  199. first_dword = eeprom->offset >> 2;
  200. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  201. eeprom_buff = kmalloc(sizeof(u32) *
  202. (last_dword - first_dword + 1), GFP_KERNEL);
  203. if (eeprom_buff == NULL)
  204. return -ENOMEM;
  205. for (i = first_dword; i < last_dword; i++) {
  206. if (!atl1e_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
  207. kfree(eeprom_buff);
  208. return -EIO;
  209. }
  210. }
  211. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
  212. eeprom->len);
  213. kfree(eeprom_buff);
  214. return ret_val;
  215. }
  216. static int atl1e_set_eeprom(struct net_device *netdev,
  217. struct ethtool_eeprom *eeprom, u8 *bytes)
  218. {
  219. struct atl1e_adapter *adapter = netdev_priv(netdev);
  220. struct atl1e_hw *hw = &adapter->hw;
  221. u32 *eeprom_buff;
  222. u32 *ptr;
  223. int first_dword, last_dword;
  224. int ret_val = 0;
  225. int i;
  226. if (eeprom->len == 0)
  227. return -EOPNOTSUPP;
  228. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  229. return -EINVAL;
  230. first_dword = eeprom->offset >> 2;
  231. last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
  232. eeprom_buff = kmalloc(AT_EEPROM_LEN, GFP_KERNEL);
  233. if (eeprom_buff == NULL)
  234. return -ENOMEM;
  235. ptr = (u32 *)eeprom_buff;
  236. if (eeprom->offset & 3) {
  237. /* need read/modify/write of first changed EEPROM word */
  238. /* only the second byte of the word is being modified */
  239. if (!atl1e_read_eeprom(hw, first_dword * 4, &(eeprom_buff[0]))) {
  240. ret_val = -EIO;
  241. goto out;
  242. }
  243. ptr++;
  244. }
  245. if (((eeprom->offset + eeprom->len) & 3)) {
  246. /* need read/modify/write of last changed EEPROM word */
  247. /* only the first byte of the word is being modified */
  248. if (!atl1e_read_eeprom(hw, last_dword * 4,
  249. &(eeprom_buff[last_dword - first_dword]))) {
  250. ret_val = -EIO;
  251. goto out;
  252. }
  253. }
  254. /* Device's eeprom is always little-endian, word addressable */
  255. memcpy(ptr, bytes, eeprom->len);
  256. for (i = 0; i < last_dword - first_dword + 1; i++) {
  257. if (!atl1e_write_eeprom(hw, ((first_dword + i) * 4),
  258. eeprom_buff[i])) {
  259. ret_val = -EIO;
  260. goto out;
  261. }
  262. }
  263. out:
  264. kfree(eeprom_buff);
  265. return ret_val;
  266. }
  267. static void atl1e_get_drvinfo(struct net_device *netdev,
  268. struct ethtool_drvinfo *drvinfo)
  269. {
  270. struct atl1e_adapter *adapter = netdev_priv(netdev);
  271. strncpy(drvinfo->driver, atl1e_driver_name, 32);
  272. strncpy(drvinfo->version, atl1e_driver_version, 32);
  273. strncpy(drvinfo->fw_version, "L1e", 32);
  274. strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  275. drvinfo->n_stats = 0;
  276. drvinfo->testinfo_len = 0;
  277. drvinfo->regdump_len = atl1e_get_regs_len(netdev);
  278. drvinfo->eedump_len = atl1e_get_eeprom_len(netdev);
  279. }
  280. static void atl1e_get_wol(struct net_device *netdev,
  281. struct ethtool_wolinfo *wol)
  282. {
  283. struct atl1e_adapter *adapter = netdev_priv(netdev);
  284. wol->supported = WAKE_MAGIC | WAKE_PHY;
  285. wol->wolopts = 0;
  286. if (adapter->wol & AT_WUFC_EX)
  287. wol->wolopts |= WAKE_UCAST;
  288. if (adapter->wol & AT_WUFC_MC)
  289. wol->wolopts |= WAKE_MCAST;
  290. if (adapter->wol & AT_WUFC_BC)
  291. wol->wolopts |= WAKE_BCAST;
  292. if (adapter->wol & AT_WUFC_MAG)
  293. wol->wolopts |= WAKE_MAGIC;
  294. if (adapter->wol & AT_WUFC_LNKC)
  295. wol->wolopts |= WAKE_PHY;
  296. return;
  297. }
  298. static int atl1e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  299. {
  300. struct atl1e_adapter *adapter = netdev_priv(netdev);
  301. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
  302. WAKE_UCAST | WAKE_MCAST | WAKE_BCAST))
  303. return -EOPNOTSUPP;
  304. /* these settings will always override what we currently have */
  305. adapter->wol = 0;
  306. if (wol->wolopts & WAKE_MAGIC)
  307. adapter->wol |= AT_WUFC_MAG;
  308. if (wol->wolopts & WAKE_PHY)
  309. adapter->wol |= AT_WUFC_LNKC;
  310. return 0;
  311. }
  312. static int atl1e_nway_reset(struct net_device *netdev)
  313. {
  314. struct atl1e_adapter *adapter = netdev_priv(netdev);
  315. if (netif_running(netdev))
  316. atl1e_reinit_locked(adapter);
  317. return 0;
  318. }
  319. static struct ethtool_ops atl1e_ethtool_ops = {
  320. .get_settings = atl1e_get_settings,
  321. .set_settings = atl1e_set_settings,
  322. .get_drvinfo = atl1e_get_drvinfo,
  323. .get_regs_len = atl1e_get_regs_len,
  324. .get_regs = atl1e_get_regs,
  325. .get_wol = atl1e_get_wol,
  326. .set_wol = atl1e_set_wol,
  327. .get_msglevel = atl1e_get_msglevel,
  328. .set_msglevel = atl1e_set_msglevel,
  329. .nway_reset = atl1e_nway_reset,
  330. .get_link = ethtool_op_get_link,
  331. .get_eeprom_len = atl1e_get_eeprom_len,
  332. .get_eeprom = atl1e_get_eeprom,
  333. .set_eeprom = atl1e_set_eeprom,
  334. .get_tx_csum = atl1e_get_tx_csum,
  335. .get_sg = ethtool_op_get_sg,
  336. .set_sg = ethtool_op_set_sg,
  337. #ifdef NETIF_F_TSO
  338. .get_tso = ethtool_op_get_tso,
  339. #endif
  340. };
  341. void atl1e_set_ethtool_ops(struct net_device *netdev)
  342. {
  343. SET_ETHTOOL_OPS(netdev, &atl1e_ethtool_ops);
  344. }