netxen_nic_ethtool.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /*
  2. * Copyright (C) 2003 - 2009 NetXen, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  18. * MA 02111-1307, USA.
  19. *
  20. * The full GNU General Public License is included in this distribution
  21. * in the file called LICENSE.
  22. *
  23. * Contact Information:
  24. * info@netxen.com
  25. * NetXen Inc,
  26. * 18922 Forge Drive
  27. * Cupertino, CA 95014-0701
  28. *
  29. */
  30. #include <linux/types.h>
  31. #include <linux/delay.h>
  32. #include <linux/pci.h>
  33. #include <asm/io.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/ethtool.h>
  36. #include "netxen_nic.h"
  37. #include "netxen_nic_hw.h"
  38. struct netxen_nic_stats {
  39. char stat_string[ETH_GSTRING_LEN];
  40. int sizeof_stat;
  41. int stat_offset;
  42. };
  43. #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
  44. offsetof(struct netxen_adapter, m)
  45. #define NETXEN_NIC_PORT_WINDOW 0x10000
  46. #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
  47. static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
  48. {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
  49. {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
  50. {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
  51. {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
  52. {"csummed", NETXEN_NIC_STAT(stats.csummed)},
  53. {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
  54. {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
  55. {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
  56. {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
  57. };
  58. #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
  59. static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
  60. "Register_Test_on_offline",
  61. "Link_Test_on_offline"
  62. };
  63. #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
  64. #define NETXEN_NIC_REGS_COUNT 42
  65. #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
  66. #define NETXEN_MAX_EEPROM_LEN 1024
  67. static int netxen_nic_get_eeprom_len(struct net_device *dev)
  68. {
  69. return NETXEN_FLASH_TOTAL_SIZE;
  70. }
  71. static void
  72. netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  73. {
  74. struct netxen_adapter *adapter = netdev_priv(dev);
  75. unsigned long flags;
  76. u32 fw_major = 0;
  77. u32 fw_minor = 0;
  78. u32 fw_build = 0;
  79. strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
  80. strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
  81. write_lock_irqsave(&adapter->adapter_lock, flags);
  82. fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
  83. fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
  84. fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
  85. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  86. sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
  87. strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  88. drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
  89. drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
  90. }
  91. static int
  92. netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  93. {
  94. struct netxen_adapter *adapter = netdev_priv(dev);
  95. int check_sfp_module = 0;
  96. /* read which mode */
  97. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  98. ecmd->supported = (SUPPORTED_10baseT_Half |
  99. SUPPORTED_10baseT_Full |
  100. SUPPORTED_100baseT_Half |
  101. SUPPORTED_100baseT_Full |
  102. SUPPORTED_1000baseT_Half |
  103. SUPPORTED_1000baseT_Full);
  104. ecmd->advertising = (ADVERTISED_100baseT_Half |
  105. ADVERTISED_100baseT_Full |
  106. ADVERTISED_1000baseT_Half |
  107. ADVERTISED_1000baseT_Full);
  108. ecmd->port = PORT_TP;
  109. ecmd->speed = adapter->link_speed;
  110. ecmd->duplex = adapter->link_duplex;
  111. ecmd->autoneg = adapter->link_autoneg;
  112. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  113. u32 val;
  114. val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
  115. if (val == NETXEN_PORT_MODE_802_3_AP) {
  116. ecmd->supported = SUPPORTED_1000baseT_Full;
  117. ecmd->advertising = ADVERTISED_1000baseT_Full;
  118. } else {
  119. ecmd->supported = SUPPORTED_10000baseT_Full;
  120. ecmd->advertising = ADVERTISED_10000baseT_Full;
  121. }
  122. if (netif_running(dev) && adapter->has_link_events) {
  123. ecmd->speed = adapter->link_speed;
  124. ecmd->autoneg = adapter->link_autoneg;
  125. ecmd->duplex = adapter->link_duplex;
  126. goto skip;
  127. }
  128. ecmd->port = PORT_TP;
  129. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  130. u16 pcifn = adapter->ahw.pci_func;
  131. val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
  132. ecmd->speed = P3_LINK_SPEED_MHZ *
  133. P3_LINK_SPEED_VAL(pcifn, val);
  134. } else
  135. ecmd->speed = SPEED_10000;
  136. ecmd->duplex = DUPLEX_FULL;
  137. ecmd->autoneg = AUTONEG_DISABLE;
  138. } else
  139. return -EIO;
  140. skip:
  141. ecmd->phy_address = adapter->physical_port;
  142. ecmd->transceiver = XCVR_EXTERNAL;
  143. switch (adapter->ahw.board_type) {
  144. case NETXEN_BRDTYPE_P2_SB35_4G:
  145. case NETXEN_BRDTYPE_P2_SB31_2G:
  146. case NETXEN_BRDTYPE_P3_REF_QG:
  147. case NETXEN_BRDTYPE_P3_4_GB:
  148. case NETXEN_BRDTYPE_P3_4_GB_MM:
  149. ecmd->supported |= SUPPORTED_Autoneg;
  150. ecmd->advertising |= ADVERTISED_Autoneg;
  151. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  152. case NETXEN_BRDTYPE_P3_10G_CX4:
  153. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  154. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  155. ecmd->supported |= SUPPORTED_TP;
  156. ecmd->advertising |= ADVERTISED_TP;
  157. ecmd->port = PORT_TP;
  158. ecmd->autoneg = (adapter->ahw.board_type ==
  159. NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
  160. (AUTONEG_DISABLE) : (adapter->link_autoneg);
  161. break;
  162. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  163. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  164. case NETXEN_BRDTYPE_P3_IMEZ:
  165. case NETXEN_BRDTYPE_P3_XG_LOM:
  166. case NETXEN_BRDTYPE_P3_HMEZ:
  167. ecmd->supported |= SUPPORTED_MII;
  168. ecmd->advertising |= ADVERTISED_MII;
  169. ecmd->port = PORT_MII;
  170. ecmd->autoneg = AUTONEG_DISABLE;
  171. break;
  172. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  173. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  174. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  175. ecmd->advertising |= ADVERTISED_TP;
  176. ecmd->supported |= SUPPORTED_TP;
  177. check_sfp_module = netif_running(dev) &&
  178. adapter->has_link_events;
  179. case NETXEN_BRDTYPE_P2_SB31_10G:
  180. case NETXEN_BRDTYPE_P3_10G_XFP:
  181. ecmd->supported |= SUPPORTED_FIBRE;
  182. ecmd->advertising |= ADVERTISED_FIBRE;
  183. ecmd->port = PORT_FIBRE;
  184. ecmd->autoneg = AUTONEG_DISABLE;
  185. break;
  186. case NETXEN_BRDTYPE_P3_10G_TP:
  187. if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  188. ecmd->autoneg = AUTONEG_DISABLE;
  189. ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
  190. ecmd->advertising |=
  191. (ADVERTISED_FIBRE | ADVERTISED_TP);
  192. ecmd->port = PORT_FIBRE;
  193. check_sfp_module = netif_running(dev) &&
  194. adapter->has_link_events;
  195. } else {
  196. ecmd->autoneg = AUTONEG_ENABLE;
  197. ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
  198. ecmd->advertising |=
  199. (ADVERTISED_TP | ADVERTISED_Autoneg);
  200. ecmd->port = PORT_TP;
  201. }
  202. break;
  203. default:
  204. printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
  205. adapter->ahw.board_type);
  206. return -EIO;
  207. }
  208. if (check_sfp_module) {
  209. switch (adapter->module_type) {
  210. case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
  211. case LINKEVENT_MODULE_OPTICAL_SRLR:
  212. case LINKEVENT_MODULE_OPTICAL_LRM:
  213. case LINKEVENT_MODULE_OPTICAL_SFP_1G:
  214. ecmd->port = PORT_FIBRE;
  215. break;
  216. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
  217. case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
  218. case LINKEVENT_MODULE_TWINAX:
  219. ecmd->port = PORT_TP;
  220. break;
  221. default:
  222. ecmd->port = -1;
  223. }
  224. }
  225. return 0;
  226. }
  227. static int
  228. netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  229. {
  230. struct netxen_adapter *adapter = netdev_priv(dev);
  231. __u32 status;
  232. /* read which mode */
  233. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  234. /* autonegotiation */
  235. if (adapter->phy_write
  236. && adapter->phy_write(adapter,
  237. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  238. ecmd->autoneg) != 0)
  239. return -EIO;
  240. else
  241. adapter->link_autoneg = ecmd->autoneg;
  242. if (adapter->phy_read
  243. && adapter->phy_read(adapter,
  244. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  245. &status) != 0)
  246. return -EIO;
  247. /* speed */
  248. switch (ecmd->speed) {
  249. case SPEED_10:
  250. netxen_set_phy_speed(status, 0);
  251. break;
  252. case SPEED_100:
  253. netxen_set_phy_speed(status, 1);
  254. break;
  255. case SPEED_1000:
  256. netxen_set_phy_speed(status, 2);
  257. break;
  258. }
  259. /* set duplex mode */
  260. if (ecmd->duplex == DUPLEX_HALF)
  261. netxen_clear_phy_duplex(status);
  262. if (ecmd->duplex == DUPLEX_FULL)
  263. netxen_set_phy_duplex(status);
  264. if (adapter->phy_write
  265. && adapter->phy_write(adapter,
  266. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  267. *((int *)&status)) != 0)
  268. return -EIO;
  269. else {
  270. adapter->link_speed = ecmd->speed;
  271. adapter->link_duplex = ecmd->duplex;
  272. }
  273. } else
  274. return -EOPNOTSUPP;
  275. if (!netif_running(dev))
  276. return 0;
  277. dev->netdev_ops->ndo_stop(dev);
  278. return dev->netdev_ops->ndo_open(dev);
  279. }
  280. static int netxen_nic_get_regs_len(struct net_device *dev)
  281. {
  282. return NETXEN_NIC_REGS_LEN;
  283. }
  284. struct netxen_niu_regs {
  285. __u32 reg[NETXEN_NIC_REGS_COUNT];
  286. };
  287. static struct netxen_niu_regs niu_registers[] = {
  288. {
  289. /* GB Mode */
  290. {
  291. NETXEN_NIU_GB_SERDES_RESET,
  292. NETXEN_NIU_GB0_MII_MODE,
  293. NETXEN_NIU_GB1_MII_MODE,
  294. NETXEN_NIU_GB2_MII_MODE,
  295. NETXEN_NIU_GB3_MII_MODE,
  296. NETXEN_NIU_GB0_GMII_MODE,
  297. NETXEN_NIU_GB1_GMII_MODE,
  298. NETXEN_NIU_GB2_GMII_MODE,
  299. NETXEN_NIU_GB3_GMII_MODE,
  300. NETXEN_NIU_REMOTE_LOOPBACK,
  301. NETXEN_NIU_GB0_HALF_DUPLEX,
  302. NETXEN_NIU_GB1_HALF_DUPLEX,
  303. NETXEN_NIU_RESET_SYS_FIFOS,
  304. NETXEN_NIU_GB_CRC_DROP,
  305. NETXEN_NIU_GB_DROP_WRONGADDR,
  306. NETXEN_NIU_TEST_MUX_CTL,
  307. NETXEN_NIU_GB_MAC_CONFIG_0(0),
  308. NETXEN_NIU_GB_MAC_CONFIG_1(0),
  309. NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
  310. NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
  311. NETXEN_NIU_GB_TEST_REG(0),
  312. NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
  313. NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
  314. NETXEN_NIU_GB_MII_MGMT_ADDR(0),
  315. NETXEN_NIU_GB_MII_MGMT_CTRL(0),
  316. NETXEN_NIU_GB_MII_MGMT_STATUS(0),
  317. NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
  318. NETXEN_NIU_GB_INTERFACE_CTRL(0),
  319. NETXEN_NIU_GB_INTERFACE_STATUS(0),
  320. NETXEN_NIU_GB_STATION_ADDR_0(0),
  321. NETXEN_NIU_GB_STATION_ADDR_1(0),
  322. -1,
  323. }
  324. },
  325. {
  326. /* XG Mode */
  327. {
  328. NETXEN_NIU_XG_SINGLE_TERM,
  329. NETXEN_NIU_XG_DRIVE_HI,
  330. NETXEN_NIU_XG_DRIVE_LO,
  331. NETXEN_NIU_XG_DTX,
  332. NETXEN_NIU_XG_DEQ,
  333. NETXEN_NIU_XG_WORD_ALIGN,
  334. NETXEN_NIU_XG_RESET,
  335. NETXEN_NIU_XG_POWER_DOWN,
  336. NETXEN_NIU_XG_RESET_PLL,
  337. NETXEN_NIU_XG_SERDES_LOOPBACK,
  338. NETXEN_NIU_XG_DO_BYTE_ALIGN,
  339. NETXEN_NIU_XG_TX_ENABLE,
  340. NETXEN_NIU_XG_RX_ENABLE,
  341. NETXEN_NIU_XG_STATUS,
  342. NETXEN_NIU_XG_PAUSE_THRESHOLD,
  343. NETXEN_NIU_XGE_CONFIG_0,
  344. NETXEN_NIU_XGE_CONFIG_1,
  345. NETXEN_NIU_XGE_IPG,
  346. NETXEN_NIU_XGE_STATION_ADDR_0_HI,
  347. NETXEN_NIU_XGE_STATION_ADDR_0_1,
  348. NETXEN_NIU_XGE_STATION_ADDR_1_LO,
  349. NETXEN_NIU_XGE_STATUS,
  350. NETXEN_NIU_XGE_MAX_FRAME_SIZE,
  351. NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
  352. NETXEN_NIU_XGE_TX_BYTE_CNT,
  353. NETXEN_NIU_XGE_TX_FRAME_CNT,
  354. NETXEN_NIU_XGE_RX_BYTE_CNT,
  355. NETXEN_NIU_XGE_RX_FRAME_CNT,
  356. NETXEN_NIU_XGE_AGGR_ERROR_CNT,
  357. NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
  358. NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
  359. NETXEN_NIU_XGE_CRC_ERROR_CNT,
  360. NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
  361. NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
  362. NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
  363. NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
  364. NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
  365. NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
  366. -1,
  367. }
  368. }
  369. };
  370. static void
  371. netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  372. {
  373. struct netxen_adapter *adapter = netdev_priv(dev);
  374. __u32 mode, *regs_buff = p;
  375. int i, window;
  376. memset(p, 0, NETXEN_NIC_REGS_LEN);
  377. regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
  378. (adapter->pdev)->device;
  379. /* which mode */
  380. regs_buff[0] = NXRD32(adapter, NETXEN_NIU_MODE);
  381. mode = regs_buff[0];
  382. /* Common registers to all the modes */
  383. regs_buff[2] = NXRD32(adapter, NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER);
  384. /* GB/XGB Mode */
  385. mode = (mode / 2) - 1;
  386. window = 0;
  387. if (mode <= 1) {
  388. for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
  389. /* GB: port specific registers */
  390. if (mode == 0 && i >= 19)
  391. window = adapter->physical_port *
  392. NETXEN_NIC_PORT_WINDOW;
  393. regs_buff[i] = NXRD32(adapter,
  394. niu_registers[mode].reg[i - 3] + window);
  395. }
  396. }
  397. }
  398. static u32 netxen_nic_test_link(struct net_device *dev)
  399. {
  400. struct netxen_adapter *adapter = netdev_priv(dev);
  401. __u32 status;
  402. int val;
  403. /* read which mode */
  404. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  405. if (adapter->phy_read
  406. && adapter->phy_read(adapter,
  407. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  408. &status) != 0)
  409. return -EIO;
  410. else {
  411. val = netxen_get_phy_link(status);
  412. return !val;
  413. }
  414. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  415. val = NXRD32(adapter, CRB_XG_STATE);
  416. return (val == XG_LINK_UP) ? 0 : 1;
  417. }
  418. return -EIO;
  419. }
  420. static int
  421. netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  422. u8 * bytes)
  423. {
  424. struct netxen_adapter *adapter = netdev_priv(dev);
  425. int offset;
  426. int ret;
  427. if (eeprom->len == 0)
  428. return -EINVAL;
  429. eeprom->magic = (adapter->pdev)->vendor |
  430. ((adapter->pdev)->device << 16);
  431. offset = eeprom->offset;
  432. ret = netxen_rom_fast_read_words(adapter, offset, bytes,
  433. eeprom->len);
  434. if (ret < 0)
  435. return ret;
  436. return 0;
  437. }
  438. static void
  439. netxen_nic_get_ringparam(struct net_device *dev,
  440. struct ethtool_ringparam *ring)
  441. {
  442. struct netxen_adapter *adapter = netdev_priv(dev);
  443. ring->rx_pending = adapter->num_rxd;
  444. ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
  445. ring->rx_jumbo_pending += adapter->num_lro_rxd;
  446. ring->tx_pending = adapter->num_txd;
  447. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  448. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
  449. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
  450. } else {
  451. ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
  452. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  453. }
  454. ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
  455. ring->rx_mini_max_pending = 0;
  456. ring->rx_mini_pending = 0;
  457. }
  458. static u32
  459. netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
  460. {
  461. u32 num_desc;
  462. num_desc = max(val, min);
  463. num_desc = min(num_desc, max);
  464. num_desc = roundup_pow_of_two(num_desc);
  465. if (val != num_desc) {
  466. printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
  467. netxen_nic_driver_name, r_name, num_desc, val);
  468. }
  469. return num_desc;
  470. }
  471. static int
  472. netxen_nic_set_ringparam(struct net_device *dev,
  473. struct ethtool_ringparam *ring)
  474. {
  475. struct netxen_adapter *adapter = netdev_priv(dev);
  476. u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
  477. u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  478. u16 num_rxd, num_jumbo_rxd, num_txd;
  479. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  480. return -EOPNOTSUPP;
  481. if (ring->rx_mini_pending)
  482. return -EOPNOTSUPP;
  483. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  484. max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
  485. max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
  486. }
  487. num_rxd = netxen_validate_ringparam(ring->rx_pending,
  488. MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
  489. num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
  490. MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
  491. num_txd = netxen_validate_ringparam(ring->tx_pending,
  492. MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
  493. if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
  494. num_jumbo_rxd == adapter->num_jumbo_rxd)
  495. return 0;
  496. adapter->num_rxd = num_rxd;
  497. adapter->num_jumbo_rxd = num_jumbo_rxd;
  498. adapter->num_txd = num_txd;
  499. return netxen_nic_reset_context(adapter);
  500. }
  501. static void
  502. netxen_nic_get_pauseparam(struct net_device *dev,
  503. struct ethtool_pauseparam *pause)
  504. {
  505. struct netxen_adapter *adapter = netdev_priv(dev);
  506. __u32 val;
  507. int port = adapter->physical_port;
  508. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  509. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  510. return;
  511. /* get flow control settings */
  512. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  513. pause->rx_pause = netxen_gb_get_rx_flowctl(val);
  514. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  515. switch (port) {
  516. case 0:
  517. pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
  518. break;
  519. case 1:
  520. pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
  521. break;
  522. case 2:
  523. pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
  524. break;
  525. case 3:
  526. default:
  527. pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
  528. break;
  529. }
  530. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  531. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  532. return;
  533. pause->rx_pause = 1;
  534. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  535. if (port == 0)
  536. pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
  537. else
  538. pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
  539. } else {
  540. printk(KERN_ERR"%s: Unknown board type: %x\n",
  541. netxen_nic_driver_name, adapter->ahw.port_type);
  542. }
  543. }
  544. static int
  545. netxen_nic_set_pauseparam(struct net_device *dev,
  546. struct ethtool_pauseparam *pause)
  547. {
  548. struct netxen_adapter *adapter = netdev_priv(dev);
  549. __u32 val;
  550. int port = adapter->physical_port;
  551. /* read mode */
  552. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  553. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  554. return -EIO;
  555. /* set flow control */
  556. val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
  557. if (pause->rx_pause)
  558. netxen_gb_rx_flowctl(val);
  559. else
  560. netxen_gb_unset_rx_flowctl(val);
  561. NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
  562. val);
  563. /* set autoneg */
  564. val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
  565. switch (port) {
  566. case 0:
  567. if (pause->tx_pause)
  568. netxen_gb_unset_gb0_mask(val);
  569. else
  570. netxen_gb_set_gb0_mask(val);
  571. break;
  572. case 1:
  573. if (pause->tx_pause)
  574. netxen_gb_unset_gb1_mask(val);
  575. else
  576. netxen_gb_set_gb1_mask(val);
  577. break;
  578. case 2:
  579. if (pause->tx_pause)
  580. netxen_gb_unset_gb2_mask(val);
  581. else
  582. netxen_gb_set_gb2_mask(val);
  583. break;
  584. case 3:
  585. default:
  586. if (pause->tx_pause)
  587. netxen_gb_unset_gb3_mask(val);
  588. else
  589. netxen_gb_set_gb3_mask(val);
  590. break;
  591. }
  592. NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
  593. } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
  594. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  595. return -EIO;
  596. val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
  597. if (port == 0) {
  598. if (pause->tx_pause)
  599. netxen_xg_unset_xg0_mask(val);
  600. else
  601. netxen_xg_set_xg0_mask(val);
  602. } else {
  603. if (pause->tx_pause)
  604. netxen_xg_unset_xg1_mask(val);
  605. else
  606. netxen_xg_set_xg1_mask(val);
  607. }
  608. NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
  609. } else {
  610. printk(KERN_ERR "%s: Unknown board type: %x\n",
  611. netxen_nic_driver_name,
  612. adapter->ahw.port_type);
  613. }
  614. return 0;
  615. }
  616. static int netxen_nic_reg_test(struct net_device *dev)
  617. {
  618. struct netxen_adapter *adapter = netdev_priv(dev);
  619. u32 data_read, data_written;
  620. data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
  621. if ((data_read & 0xffff) != PHAN_VENDOR_ID)
  622. return 1;
  623. data_written = (u32)0xa5a5a5a5;
  624. NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
  625. data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
  626. if (data_written != data_read)
  627. return 1;
  628. return 0;
  629. }
  630. static int netxen_get_sset_count(struct net_device *dev, int sset)
  631. {
  632. switch (sset) {
  633. case ETH_SS_TEST:
  634. return NETXEN_NIC_TEST_LEN;
  635. case ETH_SS_STATS:
  636. return NETXEN_NIC_STATS_LEN;
  637. default:
  638. return -EOPNOTSUPP;
  639. }
  640. }
  641. static void
  642. netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
  643. u64 * data)
  644. {
  645. memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
  646. if ((data[0] = netxen_nic_reg_test(dev)))
  647. eth_test->flags |= ETH_TEST_FL_FAILED;
  648. /* link test */
  649. if ((data[1] = (u64) netxen_nic_test_link(dev)))
  650. eth_test->flags |= ETH_TEST_FL_FAILED;
  651. }
  652. static void
  653. netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
  654. {
  655. int index;
  656. switch (stringset) {
  657. case ETH_SS_TEST:
  658. memcpy(data, *netxen_nic_gstrings_test,
  659. NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
  660. break;
  661. case ETH_SS_STATS:
  662. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  663. memcpy(data + index * ETH_GSTRING_LEN,
  664. netxen_nic_gstrings_stats[index].stat_string,
  665. ETH_GSTRING_LEN);
  666. }
  667. break;
  668. }
  669. }
  670. static void
  671. netxen_nic_get_ethtool_stats(struct net_device *dev,
  672. struct ethtool_stats *stats, u64 * data)
  673. {
  674. struct netxen_adapter *adapter = netdev_priv(dev);
  675. int index;
  676. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  677. char *p =
  678. (char *)adapter +
  679. netxen_nic_gstrings_stats[index].stat_offset;
  680. data[index] =
  681. (netxen_nic_gstrings_stats[index].sizeof_stat ==
  682. sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
  683. }
  684. }
  685. static u32 netxen_nic_get_rx_csum(struct net_device *dev)
  686. {
  687. struct netxen_adapter *adapter = netdev_priv(dev);
  688. return adapter->rx_csum;
  689. }
  690. static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
  691. {
  692. struct netxen_adapter *adapter = netdev_priv(dev);
  693. adapter->rx_csum = !!data;
  694. return 0;
  695. }
  696. static u32 netxen_nic_get_tso(struct net_device *dev)
  697. {
  698. struct netxen_adapter *adapter = netdev_priv(dev);
  699. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  700. return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
  701. return (dev->features & NETIF_F_TSO) != 0;
  702. }
  703. static int netxen_nic_set_tso(struct net_device *dev, u32 data)
  704. {
  705. if (data) {
  706. struct netxen_adapter *adapter = netdev_priv(dev);
  707. dev->features |= NETIF_F_TSO;
  708. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  709. dev->features |= NETIF_F_TSO6;
  710. } else
  711. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
  712. return 0;
  713. }
  714. static void
  715. netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  716. {
  717. struct netxen_adapter *adapter = netdev_priv(dev);
  718. u32 wol_cfg = 0;
  719. wol->supported = 0;
  720. wol->wolopts = 0;
  721. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  722. return;
  723. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  724. if (wol_cfg & (1UL << adapter->portnum))
  725. wol->supported |= WAKE_MAGIC;
  726. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  727. if (wol_cfg & (1UL << adapter->portnum))
  728. wol->wolopts |= WAKE_MAGIC;
  729. }
  730. static int
  731. netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  732. {
  733. struct netxen_adapter *adapter = netdev_priv(dev);
  734. u32 wol_cfg = 0;
  735. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  736. return -EOPNOTSUPP;
  737. if (wol->wolopts & ~WAKE_MAGIC)
  738. return -EOPNOTSUPP;
  739. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  740. if (!(wol_cfg & (1 << adapter->portnum)))
  741. return -EOPNOTSUPP;
  742. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  743. if (wol->wolopts & WAKE_MAGIC)
  744. wol_cfg |= 1UL << adapter->portnum;
  745. else
  746. wol_cfg &= ~(1UL << adapter->portnum);
  747. NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
  748. return 0;
  749. }
  750. /*
  751. * Set the coalescing parameters. Currently only normal is supported.
  752. * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
  753. * firmware coalescing to default.
  754. */
  755. static int netxen_set_intr_coalesce(struct net_device *netdev,
  756. struct ethtool_coalesce *ethcoal)
  757. {
  758. struct netxen_adapter *adapter = netdev_priv(netdev);
  759. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  760. return -EINVAL;
  761. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  762. return -EINVAL;
  763. /*
  764. * Return Error if unsupported values or
  765. * unsupported parameters are set.
  766. */
  767. if (ethcoal->rx_coalesce_usecs > 0xffff ||
  768. ethcoal->rx_max_coalesced_frames > 0xffff ||
  769. ethcoal->tx_coalesce_usecs > 0xffff ||
  770. ethcoal->tx_max_coalesced_frames > 0xffff ||
  771. ethcoal->rx_coalesce_usecs_irq ||
  772. ethcoal->rx_max_coalesced_frames_irq ||
  773. ethcoal->tx_coalesce_usecs_irq ||
  774. ethcoal->tx_max_coalesced_frames_irq ||
  775. ethcoal->stats_block_coalesce_usecs ||
  776. ethcoal->use_adaptive_rx_coalesce ||
  777. ethcoal->use_adaptive_tx_coalesce ||
  778. ethcoal->pkt_rate_low ||
  779. ethcoal->rx_coalesce_usecs_low ||
  780. ethcoal->rx_max_coalesced_frames_low ||
  781. ethcoal->tx_coalesce_usecs_low ||
  782. ethcoal->tx_max_coalesced_frames_low ||
  783. ethcoal->pkt_rate_high ||
  784. ethcoal->rx_coalesce_usecs_high ||
  785. ethcoal->rx_max_coalesced_frames_high ||
  786. ethcoal->tx_coalesce_usecs_high ||
  787. ethcoal->tx_max_coalesced_frames_high)
  788. return -EINVAL;
  789. if (!ethcoal->rx_coalesce_usecs ||
  790. !ethcoal->rx_max_coalesced_frames) {
  791. adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
  792. adapter->coal.normal.data.rx_time_us =
  793. NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
  794. adapter->coal.normal.data.rx_packets =
  795. NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
  796. } else {
  797. adapter->coal.flags = 0;
  798. adapter->coal.normal.data.rx_time_us =
  799. ethcoal->rx_coalesce_usecs;
  800. adapter->coal.normal.data.rx_packets =
  801. ethcoal->rx_max_coalesced_frames;
  802. }
  803. adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
  804. adapter->coal.normal.data.tx_packets =
  805. ethcoal->tx_max_coalesced_frames;
  806. netxen_config_intr_coalesce(adapter);
  807. return 0;
  808. }
  809. static int netxen_get_intr_coalesce(struct net_device *netdev,
  810. struct ethtool_coalesce *ethcoal)
  811. {
  812. struct netxen_adapter *adapter = netdev_priv(netdev);
  813. if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
  814. return -EINVAL;
  815. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  816. return -EINVAL;
  817. ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
  818. ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
  819. ethcoal->rx_max_coalesced_frames =
  820. adapter->coal.normal.data.rx_packets;
  821. ethcoal->tx_max_coalesced_frames =
  822. adapter->coal.normal.data.tx_packets;
  823. return 0;
  824. }
  825. static int netxen_nic_set_flags(struct net_device *netdev, u32 data)
  826. {
  827. struct netxen_adapter *adapter = netdev_priv(netdev);
  828. int hw_lro;
  829. if (!(adapter->capabilities & NX_FW_CAPABILITY_HW_LRO))
  830. return -EINVAL;
  831. ethtool_op_set_flags(netdev, data);
  832. hw_lro = (data & ETH_FLAG_LRO) ? NETXEN_NIC_LRO_ENABLED : 0;
  833. if (netxen_config_hw_lro(adapter, hw_lro))
  834. return -EIO;
  835. if ((hw_lro == 0) && netxen_send_lro_cleanup(adapter))
  836. return -EIO;
  837. return 0;
  838. }
  839. struct ethtool_ops netxen_nic_ethtool_ops = {
  840. .get_settings = netxen_nic_get_settings,
  841. .set_settings = netxen_nic_set_settings,
  842. .get_drvinfo = netxen_nic_get_drvinfo,
  843. .get_regs_len = netxen_nic_get_regs_len,
  844. .get_regs = netxen_nic_get_regs,
  845. .get_link = ethtool_op_get_link,
  846. .get_eeprom_len = netxen_nic_get_eeprom_len,
  847. .get_eeprom = netxen_nic_get_eeprom,
  848. .get_ringparam = netxen_nic_get_ringparam,
  849. .set_ringparam = netxen_nic_set_ringparam,
  850. .get_pauseparam = netxen_nic_get_pauseparam,
  851. .set_pauseparam = netxen_nic_set_pauseparam,
  852. .set_tx_csum = ethtool_op_set_tx_csum,
  853. .set_sg = ethtool_op_set_sg,
  854. .get_tso = netxen_nic_get_tso,
  855. .set_tso = netxen_nic_set_tso,
  856. .get_wol = netxen_nic_get_wol,
  857. .set_wol = netxen_nic_set_wol,
  858. .self_test = netxen_nic_diag_test,
  859. .get_strings = netxen_nic_get_strings,
  860. .get_ethtool_stats = netxen_nic_get_ethtool_stats,
  861. .get_sset_count = netxen_get_sset_count,
  862. .get_rx_csum = netxen_nic_get_rx_csum,
  863. .set_rx_csum = netxen_nic_set_rx_csum,
  864. .get_coalesce = netxen_get_intr_coalesce,
  865. .set_coalesce = netxen_set_intr_coalesce,
  866. .get_flags = ethtool_op_get_flags,
  867. .set_flags = netxen_nic_set_flags,
  868. };