netxen_nic_ethtool.c 26 KB

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