netxen_nic_ethtool.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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 LICENSE.
  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 42
  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. ecmd->speed = 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. ecmd->speed = 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. ecmd->speed = P3_LINK_SPEED_MHZ *
  125. P3_LINK_SPEED_VAL(pcifn, val);
  126. } else
  127. ecmd->speed = 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->autoneg = AUTONEG_ENABLE;
  189. ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
  190. ecmd->advertising |=
  191. (ADVERTISED_TP | ADVERTISED_Autoneg);
  192. ecmd->port = PORT_TP;
  193. }
  194. break;
  195. default:
  196. printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
  197. adapter->ahw.board_type);
  198. return -EIO;
  199. }
  200. if (check_sfp_module) {
  201. switch (adapter->module_type) {
  202. case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
  203. case LINKEVENT_MODULE_OPTICAL_SRLR:
  204. case LINKEVENT_MODULE_OPTICAL_LRM:
  205. case LINKEVENT_MODULE_OPTICAL_SFP_1G:
  206. ecmd->port = PORT_FIBRE;
  207. break;
  208. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
  209. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
  210. case LINKEVENT_MODULE_TWINAX:
  211. ecmd->port = PORT_TP;
  212. break;
  213. default:
  214. ecmd->port = -1;
  215. }
  216. }
  217. return 0;
  218. }
  219. static int
  220. netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  221. {
  222. struct netxen_adapter *adapter = netdev_priv(dev);
  223. __u32 status;
  224. /* read which mode */
  225. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  226. /* autonegotiation */
  227. if (adapter->phy_write
  228. && adapter->phy_write(adapter,
  229. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  230. ecmd->autoneg) != 0)
  231. return -EIO;
  232. else
  233. adapter->link_autoneg = ecmd->autoneg;
  234. if (adapter->phy_read
  235. && adapter->phy_read(adapter,
  236. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  237. &status) != 0)
  238. return -EIO;
  239. /* speed */
  240. switch (ecmd->speed) {
  241. case SPEED_10:
  242. netxen_set_phy_speed(status, 0);
  243. break;
  244. case SPEED_100:
  245. netxen_set_phy_speed(status, 1);
  246. break;
  247. case SPEED_1000:
  248. netxen_set_phy_speed(status, 2);
  249. break;
  250. }
  251. /* set duplex mode */
  252. if (ecmd->duplex == DUPLEX_HALF)
  253. netxen_clear_phy_duplex(status);
  254. if (ecmd->duplex == DUPLEX_FULL)
  255. netxen_set_phy_duplex(status);
  256. if (adapter->phy_write
  257. && adapter->phy_write(adapter,
  258. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  259. *((int *)&status)) != 0)
  260. return -EIO;
  261. else {
  262. adapter->link_speed = ecmd->speed;
  263. adapter->link_duplex = ecmd->duplex;
  264. }
  265. } else
  266. return -EOPNOTSUPP;
  267. if (!netif_running(dev))
  268. return 0;
  269. dev->netdev_ops->ndo_stop(dev);
  270. return dev->netdev_ops->ndo_open(dev);
  271. }
  272. static int netxen_nic_get_regs_len(struct net_device *dev)
  273. {
  274. return NETXEN_NIC_REGS_LEN;
  275. }
  276. struct netxen_niu_regs {
  277. __u32 reg[NETXEN_NIC_REGS_COUNT];
  278. };
  279. static struct netxen_niu_regs niu_registers[] = {
  280. {
  281. /* GB Mode */
  282. {
  283. NETXEN_NIU_GB_SERDES_RESET,
  284. NETXEN_NIU_GB0_MII_MODE,
  285. NETXEN_NIU_GB1_MII_MODE,
  286. NETXEN_NIU_GB2_MII_MODE,
  287. NETXEN_NIU_GB3_MII_MODE,
  288. NETXEN_NIU_GB0_GMII_MODE,
  289. NETXEN_NIU_GB1_GMII_MODE,
  290. NETXEN_NIU_GB2_GMII_MODE,
  291. NETXEN_NIU_GB3_GMII_MODE,
  292. NETXEN_NIU_REMOTE_LOOPBACK,
  293. NETXEN_NIU_GB0_HALF_DUPLEX,
  294. NETXEN_NIU_GB1_HALF_DUPLEX,
  295. NETXEN_NIU_RESET_SYS_FIFOS,
  296. NETXEN_NIU_GB_CRC_DROP,
  297. NETXEN_NIU_GB_DROP_WRONGADDR,
  298. NETXEN_NIU_TEST_MUX_CTL,
  299. NETXEN_NIU_GB_MAC_CONFIG_0(0),
  300. NETXEN_NIU_GB_MAC_CONFIG_1(0),
  301. NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
  302. NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
  303. NETXEN_NIU_GB_TEST_REG(0),
  304. NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
  305. NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
  306. NETXEN_NIU_GB_MII_MGMT_ADDR(0),
  307. NETXEN_NIU_GB_MII_MGMT_CTRL(0),
  308. NETXEN_NIU_GB_MII_MGMT_STATUS(0),
  309. NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
  310. NETXEN_NIU_GB_INTERFACE_CTRL(0),
  311. NETXEN_NIU_GB_INTERFACE_STATUS(0),
  312. NETXEN_NIU_GB_STATION_ADDR_0(0),
  313. NETXEN_NIU_GB_STATION_ADDR_1(0),
  314. -1,
  315. }
  316. },
  317. {
  318. /* XG Mode */
  319. {
  320. NETXEN_NIU_XG_SINGLE_TERM,
  321. NETXEN_NIU_XG_DRIVE_HI,
  322. NETXEN_NIU_XG_DRIVE_LO,
  323. NETXEN_NIU_XG_DTX,
  324. NETXEN_NIU_XG_DEQ,
  325. NETXEN_NIU_XG_WORD_ALIGN,
  326. NETXEN_NIU_XG_RESET,
  327. NETXEN_NIU_XG_POWER_DOWN,
  328. NETXEN_NIU_XG_RESET_PLL,
  329. NETXEN_NIU_XG_SERDES_LOOPBACK,
  330. NETXEN_NIU_XG_DO_BYTE_ALIGN,
  331. NETXEN_NIU_XG_TX_ENABLE,
  332. NETXEN_NIU_XG_RX_ENABLE,
  333. NETXEN_NIU_XG_STATUS,
  334. NETXEN_NIU_XG_PAUSE_THRESHOLD,
  335. NETXEN_NIU_XGE_CONFIG_0,
  336. NETXEN_NIU_XGE_CONFIG_1,
  337. NETXEN_NIU_XGE_IPG,
  338. NETXEN_NIU_XGE_STATION_ADDR_0_HI,
  339. NETXEN_NIU_XGE_STATION_ADDR_0_1,
  340. NETXEN_NIU_XGE_STATION_ADDR_1_LO,
  341. NETXEN_NIU_XGE_STATUS,
  342. NETXEN_NIU_XGE_MAX_FRAME_SIZE,
  343. NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
  344. NETXEN_NIU_XGE_TX_BYTE_CNT,
  345. NETXEN_NIU_XGE_TX_FRAME_CNT,
  346. NETXEN_NIU_XGE_RX_BYTE_CNT,
  347. NETXEN_NIU_XGE_RX_FRAME_CNT,
  348. NETXEN_NIU_XGE_AGGR_ERROR_CNT,
  349. NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
  350. NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
  351. NETXEN_NIU_XGE_CRC_ERROR_CNT,
  352. NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
  353. NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
  354. NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
  355. NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
  356. NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
  357. NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
  358. -1,
  359. }
  360. }
  361. };
  362. static void
  363. netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  364. {
  365. struct netxen_adapter *adapter = netdev_priv(dev);
  366. __u32 mode, *regs_buff = p;
  367. int i, window;
  368. memset(p, 0, NETXEN_NIC_REGS_LEN);
  369. regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
  370. (adapter->pdev)->device;
  371. /* which mode */
  372. regs_buff[0] = NXRD32(adapter, NETXEN_NIU_MODE);
  373. mode = regs_buff[0];
  374. /* Common registers to all the modes */
  375. regs_buff[2] = NXRD32(adapter, NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER);
  376. /* GB/XGB Mode */
  377. mode = (mode / 2) - 1;
  378. window = 0;
  379. if (mode <= 1) {
  380. for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
  381. /* GB: port specific registers */
  382. if (mode == 0 && i >= 19)
  383. window = adapter->physical_port *
  384. NETXEN_NIC_PORT_WINDOW;
  385. regs_buff[i] = NXRD32(adapter,
  386. niu_registers[mode].reg[i - 3] + window);
  387. }
  388. }
  389. }
  390. static u32 netxen_nic_test_link(struct net_device *dev)
  391. {
  392. struct netxen_adapter *adapter = netdev_priv(dev);
  393. __u32 status;
  394. int val;
  395. /* read which mode */
  396. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  397. if (adapter->phy_read
  398. && adapter->phy_read(adapter,
  399. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  400. &status) != 0)
  401. return -EIO;
  402. else {
  403. val = netxen_get_phy_link(status);
  404. return !val;
  405. }
  406. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  407. val = NXRD32(adapter, CRB_XG_STATE);
  408. return (val == XG_LINK_UP) ? 0 : 1;
  409. }
  410. return -EIO;
  411. }
  412. static int
  413. netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  414. u8 * bytes)
  415. {
  416. struct netxen_adapter *adapter = netdev_priv(dev);
  417. int offset;
  418. int ret;
  419. if (eeprom->len == 0)
  420. return -EINVAL;
  421. eeprom->magic = (adapter->pdev)->vendor |
  422. ((adapter->pdev)->device << 16);
  423. offset = eeprom->offset;
  424. ret = netxen_rom_fast_read_words(adapter, offset, bytes,
  425. eeprom->len);
  426. if (ret < 0)
  427. return ret;
  428. return 0;
  429. }
  430. static void
  431. netxen_nic_get_ringparam(struct net_device *dev,
  432. struct ethtool_ringparam *ring)
  433. {
  434. struct netxen_adapter *adapter = netdev_priv(dev);
  435. ring->rx_pending = adapter->num_rxd;
  436. ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
  437. ring->rx_jumbo_pending += adapter->num_lro_rxd;
  438. ring->tx_pending = adapter->num_txd;
  439. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  440. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
  441. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
  442. } else {
  443. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
  444. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  445. }
  446. ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
  447. ring->rx_mini_max_pending = 0;
  448. ring->rx_mini_pending = 0;
  449. }
  450. static u32
  451. netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
  452. {
  453. u32 num_desc;
  454. num_desc = max(val, min);
  455. num_desc = min(num_desc, max);
  456. num_desc = roundup_pow_of_two(num_desc);
  457. if (val != num_desc) {
  458. printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
  459. netxen_nic_driver_name, r_name, num_desc, val);
  460. }
  461. return num_desc;
  462. }
  463. static int
  464. netxen_nic_set_ringparam(struct net_device *dev,
  465. struct ethtool_ringparam *ring)
  466. {
  467. struct netxen_adapter *adapter = netdev_priv(dev);
  468. u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
  469. u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  470. u16 num_rxd, num_jumbo_rxd, num_txd;
  471. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  472. return -EOPNOTSUPP;
  473. if (ring->rx_mini_pending)
  474. return -EOPNOTSUPP;
  475. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  476. max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
  477. max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  478. }
  479. num_rxd = netxen_validate_ringparam(ring->rx_pending,
  480. MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
  481. num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
  482. MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
  483. num_txd = netxen_validate_ringparam(ring->tx_pending,
  484. MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
  485. if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
  486. num_jumbo_rxd == adapter->num_jumbo_rxd)
  487. return 0;
  488. adapter->num_rxd = num_rxd;
  489. adapter->num_jumbo_rxd = num_jumbo_rxd;
  490. adapter->num_txd = num_txd;
  491. return netxen_nic_reset_context(adapter);
  492. }
  493. static void
  494. netxen_nic_get_pauseparam(struct net_device *dev,
  495. struct ethtool_pauseparam *pause)
  496. {
  497. struct netxen_adapter *adapter = netdev_priv(dev);
  498. __u32 val;
  499. int port = adapter->physical_port;
  500. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  501. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  502. return;
  503. /* get flow control settings */
  504. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  505. pause->rx_pause = netxen_gb_get_rx_flowctl(val);
  506. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  507. switch (port) {
  508. case 0:
  509. pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
  510. break;
  511. case 1:
  512. pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
  513. break;
  514. case 2:
  515. pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
  516. break;
  517. case 3:
  518. default:
  519. pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
  520. break;
  521. }
  522. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  523. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  524. return;
  525. pause->rx_pause = 1;
  526. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  527. if (port == 0)
  528. pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
  529. else
  530. pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
  531. } else {
  532. printk(KERN_ERR"%s: Unknown board type: %x\n",
  533. netxen_nic_driver_name, adapter->ahw.port_type);
  534. }
  535. }
  536. static int
  537. netxen_nic_set_pauseparam(struct net_device *dev,
  538. struct ethtool_pauseparam *pause)
  539. {
  540. struct netxen_adapter *adapter = netdev_priv(dev);
  541. __u32 val;
  542. int port = adapter->physical_port;
  543. /* read mode */
  544. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  545. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  546. return -EIO;
  547. /* set flow control */
  548. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  549. if (pause->rx_pause)
  550. netxen_gb_rx_flowctl(val);
  551. else
  552. netxen_gb_unset_rx_flowctl(val);
  553. NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
  554. val);
  555. /* set autoneg */
  556. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  557. switch (port) {
  558. case 0:
  559. if (pause->tx_pause)
  560. netxen_gb_unset_gb0_mask(val);
  561. else
  562. netxen_gb_set_gb0_mask(val);
  563. break;
  564. case 1:
  565. if (pause->tx_pause)
  566. netxen_gb_unset_gb1_mask(val);
  567. else
  568. netxen_gb_set_gb1_mask(val);
  569. break;
  570. case 2:
  571. if (pause->tx_pause)
  572. netxen_gb_unset_gb2_mask(val);
  573. else
  574. netxen_gb_set_gb2_mask(val);
  575. break;
  576. case 3:
  577. default:
  578. if (pause->tx_pause)
  579. netxen_gb_unset_gb3_mask(val);
  580. else
  581. netxen_gb_set_gb3_mask(val);
  582. break;
  583. }
  584. NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
  585. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  586. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  587. return -EIO;
  588. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  589. if (port == 0) {
  590. if (pause->tx_pause)
  591. netxen_xg_unset_xg0_mask(val);
  592. else
  593. netxen_xg_set_xg0_mask(val);
  594. } else {
  595. if (pause->tx_pause)
  596. netxen_xg_unset_xg1_mask(val);
  597. else
  598. netxen_xg_set_xg1_mask(val);
  599. }
  600. NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
  601. } else {
  602. printk(KERN_ERR "%s: Unknown board type: %x\n",
  603. netxen_nic_driver_name,
  604. adapter->ahw.port_type);
  605. }
  606. return 0;
  607. }
  608. static int netxen_nic_reg_test(struct net_device *dev)
  609. {
  610. struct netxen_adapter *adapter = netdev_priv(dev);
  611. u32 data_read, data_written;
  612. data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
  613. if ((data_read & 0xffff) != PHAN_VENDOR_ID)
  614. return 1;
  615. data_written = (u32)0xa5a5a5a5;
  616. NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
  617. data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
  618. if (data_written != data_read)
  619. return 1;
  620. return 0;
  621. }
  622. static int netxen_get_sset_count(struct net_device *dev, int sset)
  623. {
  624. switch (sset) {
  625. case ETH_SS_TEST:
  626. return NETXEN_NIC_TEST_LEN;
  627. case ETH_SS_STATS:
  628. return NETXEN_NIC_STATS_LEN;
  629. default:
  630. return -EOPNOTSUPP;
  631. }
  632. }
  633. static void
  634. netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
  635. u64 * data)
  636. {
  637. memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
  638. if ((data[0] = netxen_nic_reg_test(dev)))
  639. eth_test->flags |= ETH_TEST_FL_FAILED;
  640. /* link test */
  641. if ((data[1] = (u64) netxen_nic_test_link(dev)))
  642. eth_test->flags |= ETH_TEST_FL_FAILED;
  643. }
  644. static void
  645. netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
  646. {
  647. int index;
  648. switch (stringset) {
  649. case ETH_SS_TEST:
  650. memcpy(data, *netxen_nic_gstrings_test,
  651. NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
  652. break;
  653. case ETH_SS_STATS:
  654. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  655. memcpy(data + index * ETH_GSTRING_LEN,
  656. netxen_nic_gstrings_stats[index].stat_string,
  657. ETH_GSTRING_LEN);
  658. }
  659. break;
  660. }
  661. }
  662. static void
  663. netxen_nic_get_ethtool_stats(struct net_device *dev,
  664. struct ethtool_stats *stats, u64 * data)
  665. {
  666. struct netxen_adapter *adapter = netdev_priv(dev);
  667. int index;
  668. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  669. char *p =
  670. (char *)adapter +
  671. netxen_nic_gstrings_stats[index].stat_offset;
  672. data[index] =
  673. (netxen_nic_gstrings_stats[index].sizeof_stat ==
  674. sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
  675. }
  676. }
  677. static u32 netxen_nic_get_rx_csum(struct net_device *dev)
  678. {
  679. struct netxen_adapter *adapter = netdev_priv(dev);
  680. return adapter->rx_csum;
  681. }
  682. static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
  683. {
  684. struct netxen_adapter *adapter = netdev_priv(dev);
  685. adapter->rx_csum = !!data;
  686. return 0;
  687. }
  688. static u32 netxen_nic_get_tso(struct net_device *dev)
  689. {
  690. struct netxen_adapter *adapter = netdev_priv(dev);
  691. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  692. return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
  693. return (dev->features & NETIF_F_TSO) != 0;
  694. }
  695. static int netxen_nic_set_tso(struct net_device *dev, u32 data)
  696. {
  697. if (data) {
  698. struct netxen_adapter *adapter = netdev_priv(dev);
  699. dev->features |= NETIF_F_TSO;
  700. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  701. dev->features |= NETIF_F_TSO6;
  702. } else
  703. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
  704. return 0;
  705. }
  706. static void
  707. netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  708. {
  709. struct netxen_adapter *adapter = netdev_priv(dev);
  710. u32 wol_cfg = 0;
  711. wol->supported = 0;
  712. wol->wolopts = 0;
  713. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  714. return;
  715. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  716. if (wol_cfg & (1UL << adapter->portnum))
  717. wol->supported |= WAKE_MAGIC;
  718. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  719. if (wol_cfg & (1UL << adapter->portnum))
  720. wol->wolopts |= WAKE_MAGIC;
  721. }
  722. static int
  723. netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  724. {
  725. struct netxen_adapter *adapter = netdev_priv(dev);
  726. u32 wol_cfg = 0;
  727. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  728. return -EOPNOTSUPP;
  729. if (wol->wolopts & ~WAKE_MAGIC)
  730. return -EOPNOTSUPP;
  731. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  732. if (!(wol_cfg & (1 << adapter->portnum)))
  733. return -EOPNOTSUPP;
  734. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  735. if (wol->wolopts & WAKE_MAGIC)
  736. wol_cfg |= 1UL << adapter->portnum;
  737. else
  738. wol_cfg &= ~(1UL << adapter->portnum);
  739. NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
  740. return 0;
  741. }
  742. /*
  743. * Set the coalescing parameters. Currently only normal is supported.
  744. * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
  745. * firmware coalescing to default.
  746. */
  747. static int netxen_set_intr_coalesce(struct net_device *netdev,
  748. struct ethtool_coalesce *ethcoal)
  749. {
  750. struct netxen_adapter *adapter = netdev_priv(netdev);
  751. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  752. return -EINVAL;
  753. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  754. return -EINVAL;
  755. /*
  756. * Return Error if unsupported values or
  757. * unsupported parameters are set.
  758. */
  759. if (ethcoal->rx_coalesce_usecs > 0xffff ||
  760. ethcoal->rx_max_coalesced_frames > 0xffff ||
  761. ethcoal->tx_coalesce_usecs > 0xffff ||
  762. ethcoal->tx_max_coalesced_frames > 0xffff ||
  763. ethcoal->rx_coalesce_usecs_irq ||
  764. ethcoal->rx_max_coalesced_frames_irq ||
  765. ethcoal->tx_coalesce_usecs_irq ||
  766. ethcoal->tx_max_coalesced_frames_irq ||
  767. ethcoal->stats_block_coalesce_usecs ||
  768. ethcoal->use_adaptive_rx_coalesce ||
  769. ethcoal->use_adaptive_tx_coalesce ||
  770. ethcoal->pkt_rate_low ||
  771. ethcoal->rx_coalesce_usecs_low ||
  772. ethcoal->rx_max_coalesced_frames_low ||
  773. ethcoal->tx_coalesce_usecs_low ||
  774. ethcoal->tx_max_coalesced_frames_low ||
  775. ethcoal->pkt_rate_high ||
  776. ethcoal->rx_coalesce_usecs_high ||
  777. ethcoal->rx_max_coalesced_frames_high ||
  778. ethcoal->tx_coalesce_usecs_high ||
  779. ethcoal->tx_max_coalesced_frames_high)
  780. return -EINVAL;
  781. if (!ethcoal->rx_coalesce_usecs ||
  782. !ethcoal->rx_max_coalesced_frames) {
  783. adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
  784. adapter->coal.normal.data.rx_time_us =
  785. NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
  786. adapter->coal.normal.data.rx_packets =
  787. NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
  788. } else {
  789. adapter->coal.flags = 0;
  790. adapter->coal.normal.data.rx_time_us =
  791. ethcoal->rx_coalesce_usecs;
  792. adapter->coal.normal.data.rx_packets =
  793. ethcoal->rx_max_coalesced_frames;
  794. }
  795. adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
  796. adapter->coal.normal.data.tx_packets =
  797. ethcoal->tx_max_coalesced_frames;
  798. netxen_config_intr_coalesce(adapter);
  799. return 0;
  800. }
  801. static int netxen_get_intr_coalesce(struct net_device *netdev,
  802. struct ethtool_coalesce *ethcoal)
  803. {
  804. struct netxen_adapter *adapter = netdev_priv(netdev);
  805. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  806. return -EINVAL;
  807. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  808. return -EINVAL;
  809. ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
  810. ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
  811. ethcoal->rx_max_coalesced_frames =
  812. adapter->coal.normal.data.rx_packets;
  813. ethcoal->tx_max_coalesced_frames =
  814. adapter->coal.normal.data.tx_packets;
  815. return 0;
  816. }
  817. static int netxen_nic_set_flags(struct net_device *netdev, u32 data)
  818. {
  819. struct netxen_adapter *adapter = netdev_priv(netdev);
  820. int hw_lro;
  821. if (!(adapter->capabilities & NX_FW_CAPABILITY_HW_LRO))
  822. return -EINVAL;
  823. ethtool_op_set_flags(netdev, data);
  824. hw_lro = (data & ETH_FLAG_LRO) ? NETXEN_NIC_LRO_ENABLED : 0;
  825. if (netxen_config_hw_lro(adapter, hw_lro))
  826. return -EIO;
  827. if ((hw_lro == 0) && netxen_send_lro_cleanup(adapter))
  828. return -EIO;
  829. return 0;
  830. }
  831. const struct ethtool_ops netxen_nic_ethtool_ops = {
  832. .get_settings = netxen_nic_get_settings,
  833. .set_settings = netxen_nic_set_settings,
  834. .get_drvinfo = netxen_nic_get_drvinfo,
  835. .get_regs_len = netxen_nic_get_regs_len,
  836. .get_regs = netxen_nic_get_regs,
  837. .get_link = ethtool_op_get_link,
  838. .get_eeprom_len = netxen_nic_get_eeprom_len,
  839. .get_eeprom = netxen_nic_get_eeprom,
  840. .get_ringparam = netxen_nic_get_ringparam,
  841. .set_ringparam = netxen_nic_set_ringparam,
  842. .get_pauseparam = netxen_nic_get_pauseparam,
  843. .set_pauseparam = netxen_nic_set_pauseparam,
  844. .set_tx_csum = ethtool_op_set_tx_csum,
  845. .set_sg = ethtool_op_set_sg,
  846. .get_tso = netxen_nic_get_tso,
  847. .set_tso = netxen_nic_set_tso,
  848. .get_wol = netxen_nic_get_wol,
  849. .set_wol = netxen_nic_set_wol,
  850. .self_test = netxen_nic_diag_test,
  851. .get_strings = netxen_nic_get_strings,
  852. .get_ethtool_stats = netxen_nic_get_ethtool_stats,
  853. .get_sset_count = netxen_get_sset_count,
  854. .get_rx_csum = netxen_nic_get_rx_csum,
  855. .set_rx_csum = netxen_nic_set_rx_csum,
  856. .get_coalesce = netxen_get_intr_coalesce,
  857. .set_coalesce = netxen_set_intr_coalesce,
  858. .get_flags = ethtool_op_get_flags,
  859. .set_flags = netxen_nic_set_flags,
  860. };