ixgb_ethtool.c 21 KB

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