netxen_nic_ethtool.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /*
  2. * Copyright (C) 2003 - 2009 NetXen, Inc.
  3. * Copyright (C) 2009 - QLogic Corporation.
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called "COPYING".
  23. *
  24. */
  25. #include <linux/types.h>
  26. #include <linux/delay.h>
  27. #include <linux/pci.h>
  28. #include <asm/io.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/ethtool.h>
  31. #include "netxen_nic.h"
  32. #include "netxen_nic_hw.h"
  33. struct netxen_nic_stats {
  34. char stat_string[ETH_GSTRING_LEN];
  35. int sizeof_stat;
  36. int stat_offset;
  37. };
  38. #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
  39. offsetof(struct netxen_adapter, m)
  40. #define NETXEN_NIC_PORT_WINDOW 0x10000
  41. #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
  42. static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
  43. {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
  44. {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
  45. {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
  46. {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
  47. {"csummed", NETXEN_NIC_STAT(stats.csummed)},
  48. {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
  49. {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
  50. {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
  51. {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
  52. };
  53. #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
  54. static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
  55. "Register_Test_on_offline",
  56. "Link_Test_on_offline"
  57. };
  58. #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
  59. #define NETXEN_NIC_REGS_COUNT 30
  60. #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
  61. #define NETXEN_MAX_EEPROM_LEN 1024
  62. static int netxen_nic_get_eeprom_len(struct net_device *dev)
  63. {
  64. return NETXEN_FLASH_TOTAL_SIZE;
  65. }
  66. static void
  67. netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  68. {
  69. struct netxen_adapter *adapter = netdev_priv(dev);
  70. u32 fw_major = 0;
  71. u32 fw_minor = 0;
  72. u32 fw_build = 0;
  73. strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
  74. strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
  75. fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
  76. fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
  77. fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
  78. sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
  79. strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  80. drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
  81. drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
  82. }
  83. static int
  84. netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  85. {
  86. struct netxen_adapter *adapter = netdev_priv(dev);
  87. int check_sfp_module = 0;
  88. /* read which mode */
  89. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  90. ecmd->supported = (SUPPORTED_10baseT_Half |
  91. SUPPORTED_10baseT_Full |
  92. SUPPORTED_100baseT_Half |
  93. SUPPORTED_100baseT_Full |
  94. SUPPORTED_1000baseT_Half |
  95. SUPPORTED_1000baseT_Full);
  96. ecmd->advertising = (ADVERTISED_100baseT_Half |
  97. ADVERTISED_100baseT_Full |
  98. ADVERTISED_1000baseT_Half |
  99. ADVERTISED_1000baseT_Full);
  100. ecmd->port = PORT_TP;
  101. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  102. ecmd->duplex = adapter->link_duplex;
  103. ecmd->autoneg = adapter->link_autoneg;
  104. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  105. u32 val;
  106. val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
  107. if (val == NETXEN_PORT_MODE_802_3_AP) {
  108. ecmd->supported = SUPPORTED_1000baseT_Full;
  109. ecmd->advertising = ADVERTISED_1000baseT_Full;
  110. } else {
  111. ecmd->supported = SUPPORTED_10000baseT_Full;
  112. ecmd->advertising = ADVERTISED_10000baseT_Full;
  113. }
  114. if (netif_running(dev) && adapter->has_link_events) {
  115. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  116. ecmd->autoneg = adapter->link_autoneg;
  117. ecmd->duplex = adapter->link_duplex;
  118. goto skip;
  119. }
  120. ecmd->port = PORT_TP;
  121. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  122. u16 pcifn = adapter->ahw.pci_func;
  123. val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
  124. ethtool_cmd_speed_set(ecmd, P3_LINK_SPEED_MHZ *
  125. P3_LINK_SPEED_VAL(pcifn, val));
  126. } else
  127. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  128. ecmd->duplex = DUPLEX_FULL;
  129. ecmd->autoneg = AUTONEG_DISABLE;
  130. } else
  131. return -EIO;
  132. skip:
  133. ecmd->phy_address = adapter->physical_port;
  134. ecmd->transceiver = XCVR_EXTERNAL;
  135. switch (adapter->ahw.board_type) {
  136. case NETXEN_BRDTYPE_P2_SB35_4G:
  137. case NETXEN_BRDTYPE_P2_SB31_2G:
  138. case NETXEN_BRDTYPE_P3_REF_QG:
  139. case NETXEN_BRDTYPE_P3_4_GB:
  140. case NETXEN_BRDTYPE_P3_4_GB_MM:
  141. ecmd->supported |= SUPPORTED_Autoneg;
  142. ecmd->advertising |= ADVERTISED_Autoneg;
  143. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  144. case NETXEN_BRDTYPE_P3_10G_CX4:
  145. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  146. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  147. ecmd->supported |= SUPPORTED_TP;
  148. ecmd->advertising |= ADVERTISED_TP;
  149. ecmd->port = PORT_TP;
  150. ecmd->autoneg = (adapter->ahw.board_type ==
  151. NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
  152. (AUTONEG_DISABLE) : (adapter->link_autoneg);
  153. break;
  154. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  155. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  156. case NETXEN_BRDTYPE_P3_IMEZ:
  157. case NETXEN_BRDTYPE_P3_XG_LOM:
  158. case NETXEN_BRDTYPE_P3_HMEZ:
  159. ecmd->supported |= SUPPORTED_MII;
  160. ecmd->advertising |= ADVERTISED_MII;
  161. ecmd->port = PORT_MII;
  162. ecmd->autoneg = AUTONEG_DISABLE;
  163. break;
  164. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  165. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  166. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  167. ecmd->advertising |= ADVERTISED_TP;
  168. ecmd->supported |= SUPPORTED_TP;
  169. check_sfp_module = netif_running(dev) &&
  170. adapter->has_link_events;
  171. case NETXEN_BRDTYPE_P2_SB31_10G:
  172. case NETXEN_BRDTYPE_P3_10G_XFP:
  173. ecmd->supported |= SUPPORTED_FIBRE;
  174. ecmd->advertising |= ADVERTISED_FIBRE;
  175. ecmd->port = PORT_FIBRE;
  176. ecmd->autoneg = AUTONEG_DISABLE;
  177. break;
  178. case NETXEN_BRDTYPE_P3_10G_TP:
  179. if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  180. ecmd->autoneg = AUTONEG_DISABLE;
  181. ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
  182. ecmd->advertising |=
  183. (ADVERTISED_FIBRE | ADVERTISED_TP);
  184. ecmd->port = PORT_FIBRE;
  185. check_sfp_module = netif_running(dev) &&
  186. adapter->has_link_events;
  187. } else {
  188. ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
  189. ecmd->advertising |=
  190. (ADVERTISED_TP | ADVERTISED_Autoneg);
  191. ecmd->port = PORT_TP;
  192. }
  193. break;
  194. default:
  195. printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
  196. adapter->ahw.board_type);
  197. return -EIO;
  198. }
  199. if (check_sfp_module) {
  200. switch (adapter->module_type) {
  201. case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
  202. case LINKEVENT_MODULE_OPTICAL_SRLR:
  203. case LINKEVENT_MODULE_OPTICAL_LRM:
  204. case LINKEVENT_MODULE_OPTICAL_SFP_1G:
  205. ecmd->port = PORT_FIBRE;
  206. break;
  207. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
  208. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
  209. case LINKEVENT_MODULE_TWINAX:
  210. ecmd->port = PORT_TP;
  211. break;
  212. default:
  213. ecmd->port = -1;
  214. }
  215. }
  216. return 0;
  217. }
  218. static int
  219. netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  220. {
  221. struct netxen_adapter *adapter = netdev_priv(dev);
  222. u32 speed = ethtool_cmd_speed(ecmd);
  223. int ret;
  224. if (adapter->ahw.port_type != NETXEN_NIC_GBE)
  225. return -EOPNOTSUPP;
  226. if (!(adapter->capabilities & NX_FW_CAPABILITY_GBE_LINK_CFG))
  227. return -EOPNOTSUPP;
  228. ret = nx_fw_cmd_set_gbe_port(adapter, speed, ecmd->duplex,
  229. ecmd->autoneg);
  230. if (ret == NX_RCODE_NOT_SUPPORTED)
  231. return -EOPNOTSUPP;
  232. else if (ret)
  233. return -EIO;
  234. adapter->link_speed = speed;
  235. adapter->link_duplex = ecmd->duplex;
  236. adapter->link_autoneg = ecmd->autoneg;
  237. if (!netif_running(dev))
  238. return 0;
  239. dev->netdev_ops->ndo_stop(dev);
  240. return dev->netdev_ops->ndo_open(dev);
  241. }
  242. static int netxen_nic_get_regs_len(struct net_device *dev)
  243. {
  244. return NETXEN_NIC_REGS_LEN;
  245. }
  246. static void
  247. netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  248. {
  249. struct netxen_adapter *adapter = netdev_priv(dev);
  250. struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
  251. struct nx_host_sds_ring *sds_ring;
  252. u32 *regs_buff = p;
  253. int ring, i = 0;
  254. int port = adapter->physical_port;
  255. memset(p, 0, NETXEN_NIC_REGS_LEN);
  256. regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
  257. (adapter->pdev)->device;
  258. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  259. return;
  260. regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE);
  261. regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE);
  262. regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
  263. regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg);
  264. regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
  265. regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE);
  266. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
  267. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
  268. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2);
  269. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c);
  270. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c);
  271. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c);
  272. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c);
  273. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  274. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c);
  275. i += 2;
  276. regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3);
  277. regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer));
  278. } else {
  279. i++;
  280. regs_buff[i++] = NXRD32(adapter,
  281. NETXEN_NIU_XGE_CONFIG_0+(0x10000*port));
  282. regs_buff[i++] = NXRD32(adapter,
  283. NETXEN_NIU_XGE_CONFIG_1+(0x10000*port));
  284. regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE);
  285. regs_buff[i++] = NXRDIO(adapter,
  286. adapter->tx_ring->crb_cmd_consumer);
  287. }
  288. regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer);
  289. regs_buff[i++] = NXRDIO(adapter,
  290. recv_ctx->rds_rings[0].crb_rcv_producer);
  291. regs_buff[i++] = NXRDIO(adapter,
  292. recv_ctx->rds_rings[1].crb_rcv_producer);
  293. regs_buff[i++] = adapter->max_sds_rings;
  294. for (ring = 0; ring < adapter->max_sds_rings; ring++) {
  295. sds_ring = &(recv_ctx->sds_rings[ring]);
  296. regs_buff[i++] = NXRDIO(adapter,
  297. sds_ring->crb_sts_consumer);
  298. }
  299. }
  300. static u32 netxen_nic_test_link(struct net_device *dev)
  301. {
  302. struct netxen_adapter *adapter = netdev_priv(dev);
  303. u32 val, port;
  304. port = adapter->physical_port;
  305. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  306. val = NXRD32(adapter, CRB_XG_STATE_P3);
  307. val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
  308. return (val == XG_LINK_UP_P3) ? 0 : 1;
  309. } else {
  310. val = NXRD32(adapter, CRB_XG_STATE);
  311. val = (val >> port*8) & 0xff;
  312. return (val == XG_LINK_UP) ? 0 : 1;
  313. }
  314. }
  315. static int
  316. netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  317. u8 * bytes)
  318. {
  319. struct netxen_adapter *adapter = netdev_priv(dev);
  320. int offset;
  321. int ret;
  322. if (eeprom->len == 0)
  323. return -EINVAL;
  324. eeprom->magic = (adapter->pdev)->vendor |
  325. ((adapter->pdev)->device << 16);
  326. offset = eeprom->offset;
  327. ret = netxen_rom_fast_read_words(adapter, offset, bytes,
  328. eeprom->len);
  329. if (ret < 0)
  330. return ret;
  331. return 0;
  332. }
  333. static void
  334. netxen_nic_get_ringparam(struct net_device *dev,
  335. struct ethtool_ringparam *ring)
  336. {
  337. struct netxen_adapter *adapter = netdev_priv(dev);
  338. ring->rx_pending = adapter->num_rxd;
  339. ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
  340. ring->rx_jumbo_pending += adapter->num_lro_rxd;
  341. ring->tx_pending = adapter->num_txd;
  342. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  343. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
  344. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
  345. } else {
  346. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
  347. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  348. }
  349. ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
  350. ring->rx_mini_max_pending = 0;
  351. ring->rx_mini_pending = 0;
  352. }
  353. static u32
  354. netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
  355. {
  356. u32 num_desc;
  357. num_desc = max(val, min);
  358. num_desc = min(num_desc, max);
  359. num_desc = roundup_pow_of_two(num_desc);
  360. if (val != num_desc) {
  361. printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
  362. netxen_nic_driver_name, r_name, num_desc, val);
  363. }
  364. return num_desc;
  365. }
  366. static int
  367. netxen_nic_set_ringparam(struct net_device *dev,
  368. struct ethtool_ringparam *ring)
  369. {
  370. struct netxen_adapter *adapter = netdev_priv(dev);
  371. u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
  372. u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  373. u16 num_rxd, num_jumbo_rxd, num_txd;
  374. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  375. return -EOPNOTSUPP;
  376. if (ring->rx_mini_pending)
  377. return -EOPNOTSUPP;
  378. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  379. max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
  380. max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  381. }
  382. num_rxd = netxen_validate_ringparam(ring->rx_pending,
  383. MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
  384. num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
  385. MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
  386. num_txd = netxen_validate_ringparam(ring->tx_pending,
  387. MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
  388. if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
  389. num_jumbo_rxd == adapter->num_jumbo_rxd)
  390. return 0;
  391. adapter->num_rxd = num_rxd;
  392. adapter->num_jumbo_rxd = num_jumbo_rxd;
  393. adapter->num_txd = num_txd;
  394. return netxen_nic_reset_context(adapter);
  395. }
  396. static void
  397. netxen_nic_get_pauseparam(struct net_device *dev,
  398. struct ethtool_pauseparam *pause)
  399. {
  400. struct netxen_adapter *adapter = netdev_priv(dev);
  401. __u32 val;
  402. int port = adapter->physical_port;
  403. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  404. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  405. return;
  406. /* get flow control settings */
  407. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  408. pause->rx_pause = netxen_gb_get_rx_flowctl(val);
  409. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  410. switch (port) {
  411. case 0:
  412. pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
  413. break;
  414. case 1:
  415. pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
  416. break;
  417. case 2:
  418. pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
  419. break;
  420. case 3:
  421. default:
  422. pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
  423. break;
  424. }
  425. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  426. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  427. return;
  428. pause->rx_pause = 1;
  429. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  430. if (port == 0)
  431. pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
  432. else
  433. pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
  434. } else {
  435. printk(KERN_ERR"%s: Unknown board type: %x\n",
  436. netxen_nic_driver_name, adapter->ahw.port_type);
  437. }
  438. }
  439. static int
  440. netxen_nic_set_pauseparam(struct net_device *dev,
  441. struct ethtool_pauseparam *pause)
  442. {
  443. struct netxen_adapter *adapter = netdev_priv(dev);
  444. __u32 val;
  445. int port = adapter->physical_port;
  446. /* read mode */
  447. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  448. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  449. return -EIO;
  450. /* set flow control */
  451. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  452. if (pause->rx_pause)
  453. netxen_gb_rx_flowctl(val);
  454. else
  455. netxen_gb_unset_rx_flowctl(val);
  456. NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
  457. val);
  458. /* set autoneg */
  459. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  460. switch (port) {
  461. case 0:
  462. if (pause->tx_pause)
  463. netxen_gb_unset_gb0_mask(val);
  464. else
  465. netxen_gb_set_gb0_mask(val);
  466. break;
  467. case 1:
  468. if (pause->tx_pause)
  469. netxen_gb_unset_gb1_mask(val);
  470. else
  471. netxen_gb_set_gb1_mask(val);
  472. break;
  473. case 2:
  474. if (pause->tx_pause)
  475. netxen_gb_unset_gb2_mask(val);
  476. else
  477. netxen_gb_set_gb2_mask(val);
  478. break;
  479. case 3:
  480. default:
  481. if (pause->tx_pause)
  482. netxen_gb_unset_gb3_mask(val);
  483. else
  484. netxen_gb_set_gb3_mask(val);
  485. break;
  486. }
  487. NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
  488. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  489. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  490. return -EIO;
  491. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  492. if (port == 0) {
  493. if (pause->tx_pause)
  494. netxen_xg_unset_xg0_mask(val);
  495. else
  496. netxen_xg_set_xg0_mask(val);
  497. } else {
  498. if (pause->tx_pause)
  499. netxen_xg_unset_xg1_mask(val);
  500. else
  501. netxen_xg_set_xg1_mask(val);
  502. }
  503. NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
  504. } else {
  505. printk(KERN_ERR "%s: Unknown board type: %x\n",
  506. netxen_nic_driver_name,
  507. adapter->ahw.port_type);
  508. }
  509. return 0;
  510. }
  511. static int netxen_nic_reg_test(struct net_device *dev)
  512. {
  513. struct netxen_adapter *adapter = netdev_priv(dev);
  514. u32 data_read, data_written;
  515. data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
  516. if ((data_read & 0xffff) != adapter->pdev->vendor)
  517. return 1;
  518. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  519. return 0;
  520. data_written = (u32)0xa5a5a5a5;
  521. NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
  522. data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
  523. if (data_written != data_read)
  524. return 1;
  525. return 0;
  526. }
  527. static int netxen_get_sset_count(struct net_device *dev, int sset)
  528. {
  529. switch (sset) {
  530. case ETH_SS_TEST:
  531. return NETXEN_NIC_TEST_LEN;
  532. case ETH_SS_STATS:
  533. return NETXEN_NIC_STATS_LEN;
  534. default:
  535. return -EOPNOTSUPP;
  536. }
  537. }
  538. static void
  539. netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
  540. u64 * data)
  541. {
  542. memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
  543. if ((data[0] = netxen_nic_reg_test(dev)))
  544. eth_test->flags |= ETH_TEST_FL_FAILED;
  545. /* link test */
  546. if ((data[1] = (u64) netxen_nic_test_link(dev)))
  547. eth_test->flags |= ETH_TEST_FL_FAILED;
  548. }
  549. static void
  550. netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
  551. {
  552. int index;
  553. switch (stringset) {
  554. case ETH_SS_TEST:
  555. memcpy(data, *netxen_nic_gstrings_test,
  556. NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
  557. break;
  558. case ETH_SS_STATS:
  559. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  560. memcpy(data + index * ETH_GSTRING_LEN,
  561. netxen_nic_gstrings_stats[index].stat_string,
  562. ETH_GSTRING_LEN);
  563. }
  564. break;
  565. }
  566. }
  567. static void
  568. netxen_nic_get_ethtool_stats(struct net_device *dev,
  569. struct ethtool_stats *stats, u64 * data)
  570. {
  571. struct netxen_adapter *adapter = netdev_priv(dev);
  572. int index;
  573. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  574. char *p =
  575. (char *)adapter +
  576. netxen_nic_gstrings_stats[index].stat_offset;
  577. data[index] =
  578. (netxen_nic_gstrings_stats[index].sizeof_stat ==
  579. sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
  580. }
  581. }
  582. static void
  583. netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  584. {
  585. struct netxen_adapter *adapter = netdev_priv(dev);
  586. u32 wol_cfg = 0;
  587. wol->supported = 0;
  588. wol->wolopts = 0;
  589. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  590. return;
  591. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  592. if (wol_cfg & (1UL << adapter->portnum))
  593. wol->supported |= WAKE_MAGIC;
  594. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  595. if (wol_cfg & (1UL << adapter->portnum))
  596. wol->wolopts |= WAKE_MAGIC;
  597. }
  598. static int
  599. netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  600. {
  601. struct netxen_adapter *adapter = netdev_priv(dev);
  602. u32 wol_cfg = 0;
  603. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  604. return -EOPNOTSUPP;
  605. if (wol->wolopts & ~WAKE_MAGIC)
  606. return -EOPNOTSUPP;
  607. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  608. if (!(wol_cfg & (1 << adapter->portnum)))
  609. return -EOPNOTSUPP;
  610. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  611. if (wol->wolopts & WAKE_MAGIC)
  612. wol_cfg |= 1UL << adapter->portnum;
  613. else
  614. wol_cfg &= ~(1UL << adapter->portnum);
  615. NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
  616. return 0;
  617. }
  618. /*
  619. * Set the coalescing parameters. Currently only normal is supported.
  620. * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
  621. * firmware coalescing to default.
  622. */
  623. static int netxen_set_intr_coalesce(struct net_device *netdev,
  624. struct ethtool_coalesce *ethcoal)
  625. {
  626. struct netxen_adapter *adapter = netdev_priv(netdev);
  627. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  628. return -EINVAL;
  629. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  630. return -EINVAL;
  631. /*
  632. * Return Error if unsupported values or
  633. * unsupported parameters are set.
  634. */
  635. if (ethcoal->rx_coalesce_usecs > 0xffff ||
  636. ethcoal->rx_max_coalesced_frames > 0xffff ||
  637. ethcoal->tx_coalesce_usecs > 0xffff ||
  638. ethcoal->tx_max_coalesced_frames > 0xffff ||
  639. ethcoal->rx_coalesce_usecs_irq ||
  640. ethcoal->rx_max_coalesced_frames_irq ||
  641. ethcoal->tx_coalesce_usecs_irq ||
  642. ethcoal->tx_max_coalesced_frames_irq ||
  643. ethcoal->stats_block_coalesce_usecs ||
  644. ethcoal->use_adaptive_rx_coalesce ||
  645. ethcoal->use_adaptive_tx_coalesce ||
  646. ethcoal->pkt_rate_low ||
  647. ethcoal->rx_coalesce_usecs_low ||
  648. ethcoal->rx_max_coalesced_frames_low ||
  649. ethcoal->tx_coalesce_usecs_low ||
  650. ethcoal->tx_max_coalesced_frames_low ||
  651. ethcoal->pkt_rate_high ||
  652. ethcoal->rx_coalesce_usecs_high ||
  653. ethcoal->rx_max_coalesced_frames_high ||
  654. ethcoal->tx_coalesce_usecs_high ||
  655. ethcoal->tx_max_coalesced_frames_high)
  656. return -EINVAL;
  657. if (!ethcoal->rx_coalesce_usecs ||
  658. !ethcoal->rx_max_coalesced_frames) {
  659. adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
  660. adapter->coal.normal.data.rx_time_us =
  661. NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
  662. adapter->coal.normal.data.rx_packets =
  663. NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
  664. } else {
  665. adapter->coal.flags = 0;
  666. adapter->coal.normal.data.rx_time_us =
  667. ethcoal->rx_coalesce_usecs;
  668. adapter->coal.normal.data.rx_packets =
  669. ethcoal->rx_max_coalesced_frames;
  670. }
  671. adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
  672. adapter->coal.normal.data.tx_packets =
  673. ethcoal->tx_max_coalesced_frames;
  674. netxen_config_intr_coalesce(adapter);
  675. return 0;
  676. }
  677. static int netxen_get_intr_coalesce(struct net_device *netdev,
  678. struct ethtool_coalesce *ethcoal)
  679. {
  680. struct netxen_adapter *adapter = netdev_priv(netdev);
  681. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  682. return -EINVAL;
  683. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  684. return -EINVAL;
  685. ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
  686. ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
  687. ethcoal->rx_max_coalesced_frames =
  688. adapter->coal.normal.data.rx_packets;
  689. ethcoal->tx_max_coalesced_frames =
  690. adapter->coal.normal.data.tx_packets;
  691. return 0;
  692. }
  693. const struct ethtool_ops netxen_nic_ethtool_ops = {
  694. .get_settings = netxen_nic_get_settings,
  695. .set_settings = netxen_nic_set_settings,
  696. .get_drvinfo = netxen_nic_get_drvinfo,
  697. .get_regs_len = netxen_nic_get_regs_len,
  698. .get_regs = netxen_nic_get_regs,
  699. .get_link = ethtool_op_get_link,
  700. .get_eeprom_len = netxen_nic_get_eeprom_len,
  701. .get_eeprom = netxen_nic_get_eeprom,
  702. .get_ringparam = netxen_nic_get_ringparam,
  703. .set_ringparam = netxen_nic_set_ringparam,
  704. .get_pauseparam = netxen_nic_get_pauseparam,
  705. .set_pauseparam = netxen_nic_set_pauseparam,
  706. .get_wol = netxen_nic_get_wol,
  707. .set_wol = netxen_nic_set_wol,
  708. .self_test = netxen_nic_diag_test,
  709. .get_strings = netxen_nic_get_strings,
  710. .get_ethtool_stats = netxen_nic_get_ethtool_stats,
  711. .get_sset_count = netxen_get_sset_count,
  712. .get_coalesce = netxen_get_intr_coalesce,
  713. .set_coalesce = netxen_set_intr_coalesce,
  714. };