netxen_nic_ethtool.c 26 KB

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