ixgb_ethtool.c 22 KB

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