netxen_nic_ethtool.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution
  20. * in the file called "COPYING".
  21. *
  22. */
  23. #include <linux/types.h>
  24. #include <linux/delay.h>
  25. #include <linux/pci.h>
  26. #include <asm/io.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/ethtool.h>
  29. #include "netxen_nic.h"
  30. #include "netxen_nic_hw.h"
  31. struct netxen_nic_stats {
  32. char stat_string[ETH_GSTRING_LEN];
  33. int sizeof_stat;
  34. int stat_offset;
  35. };
  36. #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
  37. offsetof(struct netxen_adapter, m)
  38. #define NETXEN_NIC_PORT_WINDOW 0x10000
  39. #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
  40. static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
  41. {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
  42. {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
  43. {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
  44. {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
  45. {"csummed", NETXEN_NIC_STAT(stats.csummed)},
  46. {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
  47. {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
  48. {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
  49. {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
  50. };
  51. #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
  52. static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
  53. "Register_Test_on_offline",
  54. "Link_Test_on_offline"
  55. };
  56. #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
  57. #define NETXEN_NIC_REGS_COUNT 30
  58. #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
  59. #define NETXEN_MAX_EEPROM_LEN 1024
  60. static int netxen_nic_get_eeprom_len(struct net_device *dev)
  61. {
  62. return NETXEN_FLASH_TOTAL_SIZE;
  63. }
  64. static void
  65. netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  66. {
  67. struct netxen_adapter *adapter = netdev_priv(dev);
  68. u32 fw_major = 0;
  69. u32 fw_minor = 0;
  70. u32 fw_build = 0;
  71. strlcpy(drvinfo->driver, netxen_nic_driver_name,
  72. sizeof(drvinfo->driver));
  73. strlcpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID,
  74. sizeof(drvinfo->version));
  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. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  79. "%d.%d.%d", fw_major, fw_minor, fw_build);
  80. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  81. sizeof(drvinfo->bus_info));
  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. if (!netif_running(dev) || !adapter->ahw.linkup) {
  217. ecmd->duplex = DUPLEX_UNKNOWN;
  218. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  219. }
  220. return 0;
  221. }
  222. static int
  223. netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  224. {
  225. struct netxen_adapter *adapter = netdev_priv(dev);
  226. u32 speed = ethtool_cmd_speed(ecmd);
  227. int ret;
  228. if (adapter->ahw.port_type != NETXEN_NIC_GBE)
  229. return -EOPNOTSUPP;
  230. if (!(adapter->capabilities & NX_FW_CAPABILITY_GBE_LINK_CFG))
  231. return -EOPNOTSUPP;
  232. ret = nx_fw_cmd_set_gbe_port(adapter, speed, ecmd->duplex,
  233. ecmd->autoneg);
  234. if (ret == NX_RCODE_NOT_SUPPORTED)
  235. return -EOPNOTSUPP;
  236. else if (ret)
  237. return -EIO;
  238. adapter->link_speed = speed;
  239. adapter->link_duplex = ecmd->duplex;
  240. adapter->link_autoneg = ecmd->autoneg;
  241. if (!netif_running(dev))
  242. return 0;
  243. dev->netdev_ops->ndo_stop(dev);
  244. return dev->netdev_ops->ndo_open(dev);
  245. }
  246. static int netxen_nic_get_regs_len(struct net_device *dev)
  247. {
  248. return NETXEN_NIC_REGS_LEN;
  249. }
  250. static void
  251. netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  252. {
  253. struct netxen_adapter *adapter = netdev_priv(dev);
  254. struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
  255. struct nx_host_sds_ring *sds_ring;
  256. u32 *regs_buff = p;
  257. int ring, i = 0;
  258. int port = adapter->physical_port;
  259. memset(p, 0, NETXEN_NIC_REGS_LEN);
  260. regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
  261. (adapter->pdev)->device;
  262. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  263. return;
  264. regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE);
  265. regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE);
  266. regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
  267. regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg);
  268. regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
  269. regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE);
  270. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
  271. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
  272. regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2);
  273. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c);
  274. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c);
  275. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c);
  276. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c);
  277. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  278. regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c);
  279. i += 2;
  280. regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3);
  281. regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer));
  282. } else {
  283. i++;
  284. regs_buff[i++] = NXRD32(adapter,
  285. NETXEN_NIU_XGE_CONFIG_0+(0x10000*port));
  286. regs_buff[i++] = NXRD32(adapter,
  287. NETXEN_NIU_XGE_CONFIG_1+(0x10000*port));
  288. regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE);
  289. regs_buff[i++] = NXRDIO(adapter,
  290. adapter->tx_ring->crb_cmd_consumer);
  291. }
  292. regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer);
  293. regs_buff[i++] = NXRDIO(adapter,
  294. recv_ctx->rds_rings[0].crb_rcv_producer);
  295. regs_buff[i++] = NXRDIO(adapter,
  296. recv_ctx->rds_rings[1].crb_rcv_producer);
  297. regs_buff[i++] = adapter->max_sds_rings;
  298. for (ring = 0; ring < adapter->max_sds_rings; ring++) {
  299. sds_ring = &(recv_ctx->sds_rings[ring]);
  300. regs_buff[i++] = NXRDIO(adapter,
  301. sds_ring->crb_sts_consumer);
  302. }
  303. }
  304. static u32 netxen_nic_test_link(struct net_device *dev)
  305. {
  306. struct netxen_adapter *adapter = netdev_priv(dev);
  307. u32 val, port;
  308. port = adapter->physical_port;
  309. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  310. val = NXRD32(adapter, CRB_XG_STATE_P3);
  311. val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
  312. return (val == XG_LINK_UP_P3) ? 0 : 1;
  313. } else {
  314. val = NXRD32(adapter, CRB_XG_STATE);
  315. val = (val >> port*8) & 0xff;
  316. return (val == XG_LINK_UP) ? 0 : 1;
  317. }
  318. }
  319. static int
  320. netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  321. u8 *bytes)
  322. {
  323. struct netxen_adapter *adapter = netdev_priv(dev);
  324. int offset;
  325. int ret;
  326. if (eeprom->len == 0)
  327. return -EINVAL;
  328. eeprom->magic = (adapter->pdev)->vendor |
  329. ((adapter->pdev)->device << 16);
  330. offset = eeprom->offset;
  331. ret = netxen_rom_fast_read_words(adapter, offset, bytes,
  332. eeprom->len);
  333. if (ret < 0)
  334. return ret;
  335. return 0;
  336. }
  337. static void
  338. netxen_nic_get_ringparam(struct net_device *dev,
  339. struct ethtool_ringparam *ring)
  340. {
  341. struct netxen_adapter *adapter = netdev_priv(dev);
  342. ring->rx_pending = adapter->num_rxd;
  343. ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
  344. ring->rx_jumbo_pending += adapter->num_lro_rxd;
  345. ring->tx_pending = adapter->num_txd;
  346. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  347. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
  348. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
  349. } else {
  350. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
  351. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  352. }
  353. ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
  354. }
  355. static u32
  356. netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
  357. {
  358. u32 num_desc;
  359. num_desc = max(val, min);
  360. num_desc = min(num_desc, max);
  361. num_desc = roundup_pow_of_two(num_desc);
  362. if (val != num_desc) {
  363. printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
  364. netxen_nic_driver_name, r_name, num_desc, val);
  365. }
  366. return num_desc;
  367. }
  368. static int
  369. netxen_nic_set_ringparam(struct net_device *dev,
  370. struct ethtool_ringparam *ring)
  371. {
  372. struct netxen_adapter *adapter = netdev_priv(dev);
  373. u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
  374. u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  375. u16 num_rxd, num_jumbo_rxd, num_txd;
  376. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  377. return -EOPNOTSUPP;
  378. if (ring->rx_mini_pending)
  379. return -EOPNOTSUPP;
  380. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  381. max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
  382. max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  383. }
  384. num_rxd = netxen_validate_ringparam(ring->rx_pending,
  385. MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
  386. num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
  387. MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
  388. num_txd = netxen_validate_ringparam(ring->tx_pending,
  389. MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
  390. if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
  391. num_jumbo_rxd == adapter->num_jumbo_rxd)
  392. return 0;
  393. adapter->num_rxd = num_rxd;
  394. adapter->num_jumbo_rxd = num_jumbo_rxd;
  395. adapter->num_txd = num_txd;
  396. return netxen_nic_reset_context(adapter);
  397. }
  398. static void
  399. netxen_nic_get_pauseparam(struct net_device *dev,
  400. struct ethtool_pauseparam *pause)
  401. {
  402. struct netxen_adapter *adapter = netdev_priv(dev);
  403. __u32 val;
  404. int port = adapter->physical_port;
  405. pause->autoneg = 0;
  406. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  407. if ((port < 0) || (port >= NETXEN_NIU_MAX_GBE_PORTS))
  408. return;
  409. /* get flow control settings */
  410. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  411. pause->rx_pause = netxen_gb_get_rx_flowctl(val);
  412. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  413. switch (port) {
  414. case 0:
  415. pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
  416. break;
  417. case 1:
  418. pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
  419. break;
  420. case 2:
  421. pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
  422. break;
  423. case 3:
  424. default:
  425. pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
  426. break;
  427. }
  428. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  429. if ((port < 0) || (port >= NETXEN_NIU_MAX_XG_PORTS))
  430. return;
  431. pause->rx_pause = 1;
  432. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  433. if (port == 0)
  434. pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
  435. else
  436. pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
  437. } else {
  438. printk(KERN_ERR"%s: Unknown board type: %x\n",
  439. netxen_nic_driver_name, adapter->ahw.port_type);
  440. }
  441. }
  442. static int
  443. netxen_nic_set_pauseparam(struct net_device *dev,
  444. struct ethtool_pauseparam *pause)
  445. {
  446. struct netxen_adapter *adapter = netdev_priv(dev);
  447. __u32 val;
  448. int port = adapter->physical_port;
  449. /* not supported */
  450. if (pause->autoneg)
  451. return -EINVAL;
  452. /* read mode */
  453. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  454. if ((port < 0) || (port >= NETXEN_NIU_MAX_GBE_PORTS))
  455. return -EIO;
  456. /* set flow control */
  457. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  458. if (pause->rx_pause)
  459. netxen_gb_rx_flowctl(val);
  460. else
  461. netxen_gb_unset_rx_flowctl(val);
  462. NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
  463. val);
  464. /* set autoneg */
  465. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  466. switch (port) {
  467. case 0:
  468. if (pause->tx_pause)
  469. netxen_gb_unset_gb0_mask(val);
  470. else
  471. netxen_gb_set_gb0_mask(val);
  472. break;
  473. case 1:
  474. if (pause->tx_pause)
  475. netxen_gb_unset_gb1_mask(val);
  476. else
  477. netxen_gb_set_gb1_mask(val);
  478. break;
  479. case 2:
  480. if (pause->tx_pause)
  481. netxen_gb_unset_gb2_mask(val);
  482. else
  483. netxen_gb_set_gb2_mask(val);
  484. break;
  485. case 3:
  486. default:
  487. if (pause->tx_pause)
  488. netxen_gb_unset_gb3_mask(val);
  489. else
  490. netxen_gb_set_gb3_mask(val);
  491. break;
  492. }
  493. NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
  494. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  495. if ((port < 0) || (port >= NETXEN_NIU_MAX_XG_PORTS))
  496. return -EIO;
  497. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  498. if (port == 0) {
  499. if (pause->tx_pause)
  500. netxen_xg_unset_xg0_mask(val);
  501. else
  502. netxen_xg_set_xg0_mask(val);
  503. } else {
  504. if (pause->tx_pause)
  505. netxen_xg_unset_xg1_mask(val);
  506. else
  507. netxen_xg_set_xg1_mask(val);
  508. }
  509. NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
  510. } else {
  511. printk(KERN_ERR "%s: Unknown board type: %x\n",
  512. netxen_nic_driver_name,
  513. adapter->ahw.port_type);
  514. }
  515. return 0;
  516. }
  517. static int netxen_nic_reg_test(struct net_device *dev)
  518. {
  519. struct netxen_adapter *adapter = netdev_priv(dev);
  520. u32 data_read, data_written;
  521. data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
  522. if ((data_read & 0xffff) != adapter->pdev->vendor)
  523. return 1;
  524. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  525. return 0;
  526. data_written = (u32)0xa5a5a5a5;
  527. NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
  528. data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
  529. if (data_written != data_read)
  530. return 1;
  531. return 0;
  532. }
  533. static int netxen_get_sset_count(struct net_device *dev, int sset)
  534. {
  535. switch (sset) {
  536. case ETH_SS_TEST:
  537. return NETXEN_NIC_TEST_LEN;
  538. case ETH_SS_STATS:
  539. return NETXEN_NIC_STATS_LEN;
  540. default:
  541. return -EOPNOTSUPP;
  542. }
  543. }
  544. static void
  545. netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
  546. u64 *data)
  547. {
  548. memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
  549. if ((data[0] = netxen_nic_reg_test(dev)))
  550. eth_test->flags |= ETH_TEST_FL_FAILED;
  551. /* link test */
  552. if ((data[1] = (u64) netxen_nic_test_link(dev)))
  553. eth_test->flags |= ETH_TEST_FL_FAILED;
  554. }
  555. static void
  556. netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  557. {
  558. int index;
  559. switch (stringset) {
  560. case ETH_SS_TEST:
  561. memcpy(data, *netxen_nic_gstrings_test,
  562. NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
  563. break;
  564. case ETH_SS_STATS:
  565. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  566. memcpy(data + index * ETH_GSTRING_LEN,
  567. netxen_nic_gstrings_stats[index].stat_string,
  568. ETH_GSTRING_LEN);
  569. }
  570. break;
  571. }
  572. }
  573. static void
  574. netxen_nic_get_ethtool_stats(struct net_device *dev,
  575. struct ethtool_stats *stats, u64 *data)
  576. {
  577. struct netxen_adapter *adapter = netdev_priv(dev);
  578. int index;
  579. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  580. char *p =
  581. (char *)adapter +
  582. netxen_nic_gstrings_stats[index].stat_offset;
  583. data[index] =
  584. (netxen_nic_gstrings_stats[index].sizeof_stat ==
  585. sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
  586. }
  587. }
  588. static void
  589. netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  590. {
  591. struct netxen_adapter *adapter = netdev_priv(dev);
  592. u32 wol_cfg = 0;
  593. wol->supported = 0;
  594. wol->wolopts = 0;
  595. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  596. return;
  597. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  598. if (wol_cfg & (1UL << adapter->portnum))
  599. wol->supported |= WAKE_MAGIC;
  600. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  601. if (wol_cfg & (1UL << adapter->portnum))
  602. wol->wolopts |= WAKE_MAGIC;
  603. }
  604. static int
  605. netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  606. {
  607. struct netxen_adapter *adapter = netdev_priv(dev);
  608. u32 wol_cfg = 0;
  609. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  610. return -EOPNOTSUPP;
  611. if (wol->wolopts & ~WAKE_MAGIC)
  612. return -EOPNOTSUPP;
  613. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  614. if (!(wol_cfg & (1 << adapter->portnum)))
  615. return -EOPNOTSUPP;
  616. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  617. if (wol->wolopts & WAKE_MAGIC)
  618. wol_cfg |= 1UL << adapter->portnum;
  619. else
  620. wol_cfg &= ~(1UL << adapter->portnum);
  621. NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
  622. return 0;
  623. }
  624. /*
  625. * Set the coalescing parameters. Currently only normal is supported.
  626. * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
  627. * firmware coalescing to default.
  628. */
  629. static int netxen_set_intr_coalesce(struct net_device *netdev,
  630. struct ethtool_coalesce *ethcoal)
  631. {
  632. struct netxen_adapter *adapter = netdev_priv(netdev);
  633. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  634. return -EINVAL;
  635. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  636. return -EINVAL;
  637. /*
  638. * Return Error if unsupported values or
  639. * unsupported parameters are set.
  640. */
  641. if (ethcoal->rx_coalesce_usecs > 0xffff ||
  642. ethcoal->rx_max_coalesced_frames > 0xffff ||
  643. ethcoal->tx_coalesce_usecs > 0xffff ||
  644. ethcoal->tx_max_coalesced_frames > 0xffff ||
  645. ethcoal->rx_coalesce_usecs_irq ||
  646. ethcoal->rx_max_coalesced_frames_irq ||
  647. ethcoal->tx_coalesce_usecs_irq ||
  648. ethcoal->tx_max_coalesced_frames_irq ||
  649. ethcoal->stats_block_coalesce_usecs ||
  650. ethcoal->use_adaptive_rx_coalesce ||
  651. ethcoal->use_adaptive_tx_coalesce ||
  652. ethcoal->pkt_rate_low ||
  653. ethcoal->rx_coalesce_usecs_low ||
  654. ethcoal->rx_max_coalesced_frames_low ||
  655. ethcoal->tx_coalesce_usecs_low ||
  656. ethcoal->tx_max_coalesced_frames_low ||
  657. ethcoal->pkt_rate_high ||
  658. ethcoal->rx_coalesce_usecs_high ||
  659. ethcoal->rx_max_coalesced_frames_high ||
  660. ethcoal->tx_coalesce_usecs_high ||
  661. ethcoal->tx_max_coalesced_frames_high)
  662. return -EINVAL;
  663. if (!ethcoal->rx_coalesce_usecs ||
  664. !ethcoal->rx_max_coalesced_frames) {
  665. adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
  666. adapter->coal.normal.data.rx_time_us =
  667. NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
  668. adapter->coal.normal.data.rx_packets =
  669. NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
  670. } else {
  671. adapter->coal.flags = 0;
  672. adapter->coal.normal.data.rx_time_us =
  673. ethcoal->rx_coalesce_usecs;
  674. adapter->coal.normal.data.rx_packets =
  675. ethcoal->rx_max_coalesced_frames;
  676. }
  677. adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
  678. adapter->coal.normal.data.tx_packets =
  679. ethcoal->tx_max_coalesced_frames;
  680. netxen_config_intr_coalesce(adapter);
  681. return 0;
  682. }
  683. static int netxen_get_intr_coalesce(struct net_device *netdev,
  684. struct ethtool_coalesce *ethcoal)
  685. {
  686. struct netxen_adapter *adapter = netdev_priv(netdev);
  687. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  688. return -EINVAL;
  689. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  690. return -EINVAL;
  691. ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
  692. ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
  693. ethcoal->rx_max_coalesced_frames =
  694. adapter->coal.normal.data.rx_packets;
  695. ethcoal->tx_max_coalesced_frames =
  696. adapter->coal.normal.data.tx_packets;
  697. return 0;
  698. }
  699. static int
  700. netxen_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
  701. {
  702. struct netxen_adapter *adapter = netdev_priv(netdev);
  703. struct netxen_minidump *mdump = &adapter->mdump;
  704. if (adapter->fw_mdump_rdy)
  705. dump->len = mdump->md_dump_size;
  706. else
  707. dump->len = 0;
  708. if (!mdump->md_enabled)
  709. dump->flag = ETH_FW_DUMP_DISABLE;
  710. else
  711. dump->flag = mdump->md_capture_mask;
  712. dump->version = adapter->fw_version;
  713. return 0;
  714. }
  715. static int
  716. netxen_set_dump(struct net_device *netdev, struct ethtool_dump *val)
  717. {
  718. int i;
  719. struct netxen_adapter *adapter = netdev_priv(netdev);
  720. struct netxen_minidump *mdump = &adapter->mdump;
  721. switch (val->flag) {
  722. case NX_FORCE_FW_DUMP_KEY:
  723. if (!mdump->md_enabled) {
  724. netdev_info(netdev, "FW dump not enabled\n");
  725. return 0;
  726. }
  727. if (adapter->fw_mdump_rdy) {
  728. netdev_info(netdev, "Previous dump not cleared, not forcing dump\n");
  729. return 0;
  730. }
  731. netdev_info(netdev, "Forcing a fw dump\n");
  732. nx_dev_request_reset(adapter);
  733. break;
  734. case NX_DISABLE_FW_DUMP:
  735. if (mdump->md_enabled) {
  736. netdev_info(netdev, "Disabling FW Dump\n");
  737. mdump->md_enabled = 0;
  738. }
  739. break;
  740. case NX_ENABLE_FW_DUMP:
  741. if (!mdump->md_enabled) {
  742. netdev_info(netdev, "Enabling FW dump\n");
  743. mdump->md_enabled = 1;
  744. }
  745. break;
  746. case NX_FORCE_FW_RESET:
  747. netdev_info(netdev, "Forcing FW reset\n");
  748. nx_dev_request_reset(adapter);
  749. adapter->flags &= ~NETXEN_FW_RESET_OWNER;
  750. break;
  751. default:
  752. for (i = 0; i < ARRAY_SIZE(FW_DUMP_LEVELS); i++) {
  753. if (val->flag == FW_DUMP_LEVELS[i]) {
  754. mdump->md_capture_mask = val->flag;
  755. netdev_info(netdev,
  756. "Driver mask changed to: 0x%x\n",
  757. mdump->md_capture_mask);
  758. return 0;
  759. }
  760. }
  761. netdev_info(netdev,
  762. "Invalid dump level: 0x%x\n", val->flag);
  763. return -EINVAL;
  764. }
  765. return 0;
  766. }
  767. static int
  768. netxen_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
  769. void *buffer)
  770. {
  771. int i, copy_sz;
  772. u32 *hdr_ptr, *data;
  773. struct netxen_adapter *adapter = netdev_priv(netdev);
  774. struct netxen_minidump *mdump = &adapter->mdump;
  775. if (!adapter->fw_mdump_rdy) {
  776. netdev_info(netdev, "Dump not available\n");
  777. return -EINVAL;
  778. }
  779. /* Copy template header first */
  780. copy_sz = mdump->md_template_size;
  781. hdr_ptr = (u32 *) mdump->md_template;
  782. data = buffer;
  783. for (i = 0; i < copy_sz/sizeof(u32); i++)
  784. *data++ = cpu_to_le32(*hdr_ptr++);
  785. /* Copy captured dump data */
  786. memcpy(buffer + copy_sz,
  787. mdump->md_capture_buff + mdump->md_template_size,
  788. mdump->md_capture_size);
  789. dump->len = copy_sz + mdump->md_capture_size;
  790. dump->flag = mdump->md_capture_mask;
  791. /* Free dump area once data has been captured */
  792. vfree(mdump->md_capture_buff);
  793. mdump->md_capture_buff = NULL;
  794. adapter->fw_mdump_rdy = 0;
  795. netdev_info(netdev, "extracted the fw dump Successfully\n");
  796. return 0;
  797. }
  798. const struct ethtool_ops netxen_nic_ethtool_ops = {
  799. .get_settings = netxen_nic_get_settings,
  800. .set_settings = netxen_nic_set_settings,
  801. .get_drvinfo = netxen_nic_get_drvinfo,
  802. .get_regs_len = netxen_nic_get_regs_len,
  803. .get_regs = netxen_nic_get_regs,
  804. .get_link = ethtool_op_get_link,
  805. .get_eeprom_len = netxen_nic_get_eeprom_len,
  806. .get_eeprom = netxen_nic_get_eeprom,
  807. .get_ringparam = netxen_nic_get_ringparam,
  808. .set_ringparam = netxen_nic_set_ringparam,
  809. .get_pauseparam = netxen_nic_get_pauseparam,
  810. .set_pauseparam = netxen_nic_set_pauseparam,
  811. .get_wol = netxen_nic_get_wol,
  812. .set_wol = netxen_nic_set_wol,
  813. .self_test = netxen_nic_diag_test,
  814. .get_strings = netxen_nic_get_strings,
  815. .get_ethtool_stats = netxen_nic_get_ethtool_stats,
  816. .get_sset_count = netxen_get_sset_count,
  817. .get_coalesce = netxen_get_intr_coalesce,
  818. .set_coalesce = netxen_set_intr_coalesce,
  819. .get_dump_flag = netxen_get_dump_flag,
  820. .get_dump_data = netxen_get_dump_data,
  821. .set_dump = netxen_set_dump,
  822. };