ixgb_ethtool.c 22 KB

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