ixgb_ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*******************************************************************************
  2. Intel PRO/10GbE Linux driver
  3. Copyright(c) 1999 - 2008 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. /* ethtool support for ixgb */
  22. #include "ixgb.h"
  23. #include <asm/uaccess.h>
  24. #define IXGB_ALL_RAR_ENTRIES 16
  25. enum {NETDEV_STATS, IXGB_STATS};
  26. struct ixgb_stats {
  27. char stat_string[ETH_GSTRING_LEN];
  28. int type;
  29. int sizeof_stat;
  30. int stat_offset;
  31. };
  32. #define IXGB_STAT(m) IXGB_STATS, \
  33. FIELD_SIZEOF(struct ixgb_adapter, m), \
  34. offsetof(struct ixgb_adapter, m)
  35. #define IXGB_NETDEV_STAT(m) NETDEV_STATS, \
  36. FIELD_SIZEOF(struct net_device, m), \
  37. offsetof(struct net_device, m)
  38. static struct ixgb_stats ixgb_gstrings_stats[] = {
  39. {"rx_packets", IXGB_NETDEV_STAT(stats.rx_packets)},
  40. {"tx_packets", IXGB_NETDEV_STAT(stats.tx_packets)},
  41. {"rx_bytes", IXGB_NETDEV_STAT(stats.rx_bytes)},
  42. {"tx_bytes", IXGB_NETDEV_STAT(stats.tx_bytes)},
  43. {"rx_errors", IXGB_NETDEV_STAT(stats.rx_errors)},
  44. {"tx_errors", IXGB_NETDEV_STAT(stats.tx_errors)},
  45. {"rx_dropped", IXGB_NETDEV_STAT(stats.rx_dropped)},
  46. {"tx_dropped", IXGB_NETDEV_STAT(stats.tx_dropped)},
  47. {"multicast", IXGB_NETDEV_STAT(stats.multicast)},
  48. {"collisions", IXGB_NETDEV_STAT(stats.collisions)},
  49. /* { "rx_length_errors", IXGB_NETDEV_STAT(stats.rx_length_errors) }, */
  50. {"rx_over_errors", IXGB_NETDEV_STAT(stats.rx_over_errors)},
  51. {"rx_crc_errors", IXGB_NETDEV_STAT(stats.rx_crc_errors)},
  52. {"rx_frame_errors", IXGB_NETDEV_STAT(stats.rx_frame_errors)},
  53. {"rx_no_buffer_count", IXGB_STAT(stats.rnbc)},
  54. {"rx_fifo_errors", IXGB_NETDEV_STAT(stats.rx_fifo_errors)},
  55. {"rx_missed_errors", IXGB_NETDEV_STAT(stats.rx_missed_errors)},
  56. {"tx_aborted_errors", IXGB_NETDEV_STAT(stats.tx_aborted_errors)},
  57. {"tx_carrier_errors", IXGB_NETDEV_STAT(stats.tx_carrier_errors)},
  58. {"tx_fifo_errors", IXGB_NETDEV_STAT(stats.tx_fifo_errors)},
  59. {"tx_heartbeat_errors", IXGB_NETDEV_STAT(stats.tx_heartbeat_errors)},
  60. {"tx_window_errors", IXGB_NETDEV_STAT(stats.tx_window_errors)},
  61. {"tx_deferred_ok", IXGB_STAT(stats.dc)},
  62. {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
  63. {"tx_restart_queue", IXGB_STAT(restart_queue) },
  64. {"rx_long_length_errors", IXGB_STAT(stats.roc)},
  65. {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
  66. {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
  67. {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
  68. {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
  69. {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
  70. {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
  71. {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
  72. {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
  73. {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
  74. {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
  75. {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
  76. };
  77. #define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats)
  78. static int
  79. ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  80. {
  81. struct ixgb_adapter *adapter = netdev_priv(netdev);
  82. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  83. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  84. ecmd->port = PORT_FIBRE;
  85. ecmd->transceiver = XCVR_EXTERNAL;
  86. if (netif_carrier_ok(adapter->netdev)) {
  87. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  88. ecmd->duplex = DUPLEX_FULL;
  89. } else {
  90. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  91. ecmd->duplex = DUPLEX_UNKNOWN;
  92. }
  93. ecmd->autoneg = AUTONEG_DISABLE;
  94. return 0;
  95. }
  96. void ixgb_set_speed_duplex(struct net_device *netdev)
  97. {
  98. struct ixgb_adapter *adapter = netdev_priv(netdev);
  99. /* be optimistic about our link, since we were up before */
  100. adapter->link_speed = 10000;
  101. adapter->link_duplex = FULL_DUPLEX;
  102. netif_carrier_on(netdev);
  103. netif_wake_queue(netdev);
  104. }
  105. static int
  106. ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  107. {
  108. struct ixgb_adapter *adapter = netdev_priv(netdev);
  109. u32 speed = ethtool_cmd_speed(ecmd);
  110. if (ecmd->autoneg == AUTONEG_ENABLE ||
  111. (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL))
  112. return -EINVAL;
  113. if (netif_running(adapter->netdev)) {
  114. ixgb_down(adapter, true);
  115. ixgb_reset(adapter);
  116. ixgb_up(adapter);
  117. ixgb_set_speed_duplex(netdev);
  118. } else
  119. ixgb_reset(adapter);
  120. return 0;
  121. }
  122. static void
  123. ixgb_get_pauseparam(struct net_device *netdev,
  124. struct ethtool_pauseparam *pause)
  125. {
  126. struct ixgb_adapter *adapter = netdev_priv(netdev);
  127. struct ixgb_hw *hw = &adapter->hw;
  128. pause->autoneg = AUTONEG_DISABLE;
  129. if (hw->fc.type == ixgb_fc_rx_pause)
  130. pause->rx_pause = 1;
  131. else if (hw->fc.type == ixgb_fc_tx_pause)
  132. pause->tx_pause = 1;
  133. else if (hw->fc.type == ixgb_fc_full) {
  134. pause->rx_pause = 1;
  135. pause->tx_pause = 1;
  136. }
  137. }
  138. static int
  139. ixgb_set_pauseparam(struct net_device *netdev,
  140. struct ethtool_pauseparam *pause)
  141. {
  142. struct ixgb_adapter *adapter = netdev_priv(netdev);
  143. struct ixgb_hw *hw = &adapter->hw;
  144. if (pause->autoneg == AUTONEG_ENABLE)
  145. return -EINVAL;
  146. if (pause->rx_pause && pause->tx_pause)
  147. hw->fc.type = ixgb_fc_full;
  148. else if (pause->rx_pause && !pause->tx_pause)
  149. hw->fc.type = ixgb_fc_rx_pause;
  150. else if (!pause->rx_pause && pause->tx_pause)
  151. hw->fc.type = ixgb_fc_tx_pause;
  152. else if (!pause->rx_pause && !pause->tx_pause)
  153. hw->fc.type = ixgb_fc_none;
  154. if (netif_running(adapter->netdev)) {
  155. ixgb_down(adapter, true);
  156. ixgb_up(adapter);
  157. ixgb_set_speed_duplex(netdev);
  158. } else
  159. ixgb_reset(adapter);
  160. return 0;
  161. }
  162. static u32
  163. ixgb_get_msglevel(struct net_device *netdev)
  164. {
  165. struct ixgb_adapter *adapter = netdev_priv(netdev);
  166. return adapter->msg_enable;
  167. }
  168. static void
  169. ixgb_set_msglevel(struct net_device *netdev, u32 data)
  170. {
  171. struct ixgb_adapter *adapter = netdev_priv(netdev);
  172. adapter->msg_enable = data;
  173. }
  174. #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
  175. static int
  176. ixgb_get_regs_len(struct net_device *netdev)
  177. {
  178. #define IXGB_REG_DUMP_LEN 136*sizeof(u32)
  179. return IXGB_REG_DUMP_LEN;
  180. }
  181. static void
  182. ixgb_get_regs(struct net_device *netdev,
  183. struct ethtool_regs *regs, void *p)
  184. {
  185. struct ixgb_adapter *adapter = netdev_priv(netdev);
  186. struct ixgb_hw *hw = &adapter->hw;
  187. u32 *reg = p;
  188. u32 *reg_start = reg;
  189. u8 i;
  190. /* the 1 (one) below indicates an attempt at versioning, if the
  191. * interface in ethtool or the driver changes, this 1 should be
  192. * incremented */
  193. regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
  194. /* General Registers */
  195. *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
  196. *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
  197. *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
  198. *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
  199. *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
  200. /* Interrupt */
  201. *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
  202. *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
  203. *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
  204. *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
  205. /* Receive */
  206. *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
  207. *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
  208. *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
  209. *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
  210. *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
  211. *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
  212. *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
  213. *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
  214. *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
  215. *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
  216. *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
  217. *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
  218. /* there are 16 RAR entries in hardware, we only use 3 */
  219. for (i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) {
  220. *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
  221. *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
  222. }
  223. /* Transmit */
  224. *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
  225. *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
  226. *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
  227. *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
  228. *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
  229. *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
  230. *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
  231. *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
  232. *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
  233. *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
  234. /* Physical */
  235. *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
  236. *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
  237. *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
  238. *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
  239. *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
  240. *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
  241. *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
  242. *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
  243. *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
  244. *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
  245. *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
  246. *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
  247. *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
  248. /* Statistics */
  249. *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
  250. *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
  251. *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
  252. *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
  253. *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
  254. *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
  255. *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
  256. *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
  257. *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
  258. *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
  259. *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
  260. *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
  261. *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
  262. *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
  263. *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
  264. *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
  265. *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
  266. *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
  267. *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
  268. *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
  269. *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
  270. *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
  271. *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
  272. *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
  273. *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
  274. *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
  275. *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
  276. *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
  277. *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
  278. *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
  279. *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
  280. *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
  281. *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
  282. *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
  283. *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
  284. *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
  285. *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
  286. *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
  287. *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
  288. *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
  289. *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
  290. *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
  291. *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
  292. *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
  293. *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
  294. *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
  295. *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
  296. *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
  297. *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
  298. *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
  299. *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
  300. *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
  301. *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
  302. *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
  303. *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
  304. *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
  305. *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
  306. *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
  307. *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
  308. *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
  309. regs->len = (reg - reg_start) * sizeof(u32);
  310. }
  311. static int
  312. ixgb_get_eeprom_len(struct net_device *netdev)
  313. {
  314. /* return size in bytes */
  315. return IXGB_EEPROM_SIZE << 1;
  316. }
  317. static int
  318. ixgb_get_eeprom(struct net_device *netdev,
  319. struct ethtool_eeprom *eeprom, u8 *bytes)
  320. {
  321. struct ixgb_adapter *adapter = netdev_priv(netdev);
  322. struct ixgb_hw *hw = &adapter->hw;
  323. __le16 *eeprom_buff;
  324. int i, max_len, first_word, last_word;
  325. int ret_val = 0;
  326. if (eeprom->len == 0) {
  327. ret_val = -EINVAL;
  328. goto geeprom_error;
  329. }
  330. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  331. max_len = ixgb_get_eeprom_len(netdev);
  332. if (eeprom->offset > eeprom->offset + eeprom->len) {
  333. ret_val = -EINVAL;
  334. goto geeprom_error;
  335. }
  336. if ((eeprom->offset + eeprom->len) > max_len)
  337. eeprom->len = (max_len - eeprom->offset);
  338. first_word = eeprom->offset >> 1;
  339. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  340. eeprom_buff = kmalloc(sizeof(__le16) *
  341. (last_word - first_word + 1), GFP_KERNEL);
  342. if (!eeprom_buff)
  343. return -ENOMEM;
  344. /* note the eeprom was good because the driver loaded */
  345. for (i = 0; i <= (last_word - first_word); i++)
  346. eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
  347. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  348. kfree(eeprom_buff);
  349. geeprom_error:
  350. return ret_val;
  351. }
  352. static int
  353. ixgb_set_eeprom(struct net_device *netdev,
  354. struct ethtool_eeprom *eeprom, u8 *bytes)
  355. {
  356. struct ixgb_adapter *adapter = netdev_priv(netdev);
  357. struct ixgb_hw *hw = &adapter->hw;
  358. u16 *eeprom_buff;
  359. void *ptr;
  360. int max_len, first_word, last_word;
  361. u16 i;
  362. if (eeprom->len == 0)
  363. return -EINVAL;
  364. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  365. return -EFAULT;
  366. max_len = ixgb_get_eeprom_len(netdev);
  367. if (eeprom->offset > eeprom->offset + eeprom->len)
  368. return -EINVAL;
  369. if ((eeprom->offset + eeprom->len) > max_len)
  370. eeprom->len = (max_len - eeprom->offset);
  371. first_word = eeprom->offset >> 1;
  372. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  373. eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  374. if (!eeprom_buff)
  375. return -ENOMEM;
  376. ptr = (void *)eeprom_buff;
  377. if (eeprom->offset & 1) {
  378. /* need read/modify/write of first changed EEPROM word */
  379. /* only the second byte of the word is being modified */
  380. eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
  381. ptr++;
  382. }
  383. if ((eeprom->offset + eeprom->len) & 1) {
  384. /* need read/modify/write of last changed EEPROM word */
  385. /* only the first byte of the word is being modified */
  386. eeprom_buff[last_word - first_word]
  387. = ixgb_read_eeprom(hw, last_word);
  388. }
  389. memcpy(ptr, bytes, eeprom->len);
  390. for (i = 0; i <= (last_word - first_word); i++)
  391. ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
  392. /* Update the checksum over the first part of the EEPROM if needed */
  393. if (first_word <= EEPROM_CHECKSUM_REG)
  394. ixgb_update_eeprom_checksum(hw);
  395. kfree(eeprom_buff);
  396. return 0;
  397. }
  398. static void
  399. ixgb_get_drvinfo(struct net_device *netdev,
  400. struct ethtool_drvinfo *drvinfo)
  401. {
  402. struct ixgb_adapter *adapter = netdev_priv(netdev);
  403. strlcpy(drvinfo->driver, ixgb_driver_name,
  404. sizeof(drvinfo->driver));
  405. strlcpy(drvinfo->version, ixgb_driver_version,
  406. sizeof(drvinfo->version));
  407. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  408. sizeof(drvinfo->bus_info));
  409. }
  410. static void
  411. ixgb_get_ringparam(struct net_device *netdev,
  412. struct ethtool_ringparam *ring)
  413. {
  414. struct ixgb_adapter *adapter = netdev_priv(netdev);
  415. struct ixgb_desc_ring *txdr = &adapter->tx_ring;
  416. struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
  417. ring->rx_max_pending = MAX_RXD;
  418. ring->tx_max_pending = MAX_TXD;
  419. ring->rx_pending = rxdr->count;
  420. ring->tx_pending = txdr->count;
  421. }
  422. static int
  423. ixgb_set_ringparam(struct net_device *netdev,
  424. struct ethtool_ringparam *ring)
  425. {
  426. struct ixgb_adapter *adapter = netdev_priv(netdev);
  427. struct ixgb_desc_ring *txdr = &adapter->tx_ring;
  428. struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
  429. struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
  430. int err;
  431. tx_old = adapter->tx_ring;
  432. rx_old = adapter->rx_ring;
  433. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  434. return -EINVAL;
  435. if (netif_running(adapter->netdev))
  436. ixgb_down(adapter, true);
  437. rxdr->count = max(ring->rx_pending,(u32)MIN_RXD);
  438. rxdr->count = min(rxdr->count,(u32)MAX_RXD);
  439. rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
  440. txdr->count = max(ring->tx_pending,(u32)MIN_TXD);
  441. txdr->count = min(txdr->count,(u32)MAX_TXD);
  442. txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
  443. if (netif_running(adapter->netdev)) {
  444. /* Try to get new resources before deleting old */
  445. if ((err = ixgb_setup_rx_resources(adapter)))
  446. goto err_setup_rx;
  447. if ((err = ixgb_setup_tx_resources(adapter)))
  448. goto err_setup_tx;
  449. /* save the new, restore the old in order to free it,
  450. * then restore the new back again */
  451. rx_new = adapter->rx_ring;
  452. tx_new = adapter->tx_ring;
  453. adapter->rx_ring = rx_old;
  454. adapter->tx_ring = tx_old;
  455. ixgb_free_rx_resources(adapter);
  456. ixgb_free_tx_resources(adapter);
  457. adapter->rx_ring = rx_new;
  458. adapter->tx_ring = tx_new;
  459. if ((err = ixgb_up(adapter)))
  460. return err;
  461. ixgb_set_speed_duplex(netdev);
  462. }
  463. return 0;
  464. err_setup_tx:
  465. ixgb_free_rx_resources(adapter);
  466. err_setup_rx:
  467. adapter->rx_ring = rx_old;
  468. adapter->tx_ring = tx_old;
  469. ixgb_up(adapter);
  470. return err;
  471. }
  472. static int
  473. ixgb_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
  474. {
  475. struct ixgb_adapter *adapter = netdev_priv(netdev);
  476. switch (state) {
  477. case ETHTOOL_ID_ACTIVE:
  478. return 2;
  479. case ETHTOOL_ID_ON:
  480. ixgb_led_on(&adapter->hw);
  481. break;
  482. case ETHTOOL_ID_OFF:
  483. case ETHTOOL_ID_INACTIVE:
  484. ixgb_led_off(&adapter->hw);
  485. }
  486. return 0;
  487. }
  488. static int
  489. ixgb_get_sset_count(struct net_device *netdev, int sset)
  490. {
  491. switch (sset) {
  492. case ETH_SS_STATS:
  493. return IXGB_STATS_LEN;
  494. default:
  495. return -EOPNOTSUPP;
  496. }
  497. }
  498. static void
  499. ixgb_get_ethtool_stats(struct net_device *netdev,
  500. struct ethtool_stats *stats, u64 *data)
  501. {
  502. struct ixgb_adapter *adapter = netdev_priv(netdev);
  503. int i;
  504. char *p = NULL;
  505. ixgb_update_stats(adapter);
  506. for (i = 0; i < IXGB_STATS_LEN; i++) {
  507. switch (ixgb_gstrings_stats[i].type) {
  508. case NETDEV_STATS:
  509. p = (char *) netdev +
  510. ixgb_gstrings_stats[i].stat_offset;
  511. break;
  512. case IXGB_STATS:
  513. p = (char *) adapter +
  514. ixgb_gstrings_stats[i].stat_offset;
  515. break;
  516. }
  517. data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
  518. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  519. }
  520. }
  521. static void
  522. ixgb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  523. {
  524. int i;
  525. switch(stringset) {
  526. case ETH_SS_STATS:
  527. for (i = 0; i < IXGB_STATS_LEN; i++) {
  528. memcpy(data + i * ETH_GSTRING_LEN,
  529. ixgb_gstrings_stats[i].stat_string,
  530. ETH_GSTRING_LEN);
  531. }
  532. break;
  533. }
  534. }
  535. static const struct ethtool_ops ixgb_ethtool_ops = {
  536. .get_settings = ixgb_get_settings,
  537. .set_settings = ixgb_set_settings,
  538. .get_drvinfo = ixgb_get_drvinfo,
  539. .get_regs_len = ixgb_get_regs_len,
  540. .get_regs = ixgb_get_regs,
  541. .get_link = ethtool_op_get_link,
  542. .get_eeprom_len = ixgb_get_eeprom_len,
  543. .get_eeprom = ixgb_get_eeprom,
  544. .set_eeprom = ixgb_set_eeprom,
  545. .get_ringparam = ixgb_get_ringparam,
  546. .set_ringparam = ixgb_set_ringparam,
  547. .get_pauseparam = ixgb_get_pauseparam,
  548. .set_pauseparam = ixgb_set_pauseparam,
  549. .get_msglevel = ixgb_get_msglevel,
  550. .set_msglevel = ixgb_set_msglevel,
  551. .get_strings = ixgb_get_strings,
  552. .set_phys_id = ixgb_set_phys_id,
  553. .get_sset_count = ixgb_get_sset_count,
  554. .get_ethtool_stats = ixgb_get_ethtool_stats,
  555. };
  556. void ixgb_set_ethtool_ops(struct net_device *netdev)
  557. {
  558. netdev->ethtool_ops = &ixgb_ethtool_ops;
  559. }