netxen_nic_ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * Copyright (C) 2003 - 2006 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,
  26. * 3965 Freedom Circle, Fourth floor,
  27. * Santa Clara, CA 95054
  28. *
  29. *
  30. * ethtool support for netxen nic
  31. *
  32. */
  33. #include <linux/types.h>
  34. #include <linux/delay.h>
  35. #include <asm/uaccess.h>
  36. #include <linux/pci.h>
  37. #include <asm/io.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/version.h>
  41. #include "netxen_nic.h"
  42. #include "netxen_nic_hw.h"
  43. #include "netxen_nic_phan_reg.h"
  44. struct netxen_nic_stats {
  45. char stat_string[ETH_GSTRING_LEN];
  46. int sizeof_stat;
  47. int stat_offset;
  48. };
  49. #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
  50. offsetof(struct netxen_adapter, m)
  51. #define NETXEN_NIC_PORT_WINDOW 0x10000
  52. #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
  53. static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
  54. {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
  55. {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
  56. {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
  57. {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
  58. {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
  59. {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
  60. {"polled", NETXEN_NIC_STAT(stats.polled)},
  61. {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
  62. {"csummed", NETXEN_NIC_STAT(stats.csummed)},
  63. {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
  64. {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
  65. {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
  66. };
  67. #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
  68. static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
  69. "Register_Test_on_offline",
  70. "Link_Test_on_offline"
  71. };
  72. #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
  73. #define NETXEN_NIC_REGS_COUNT 42
  74. #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
  75. #define NETXEN_MAX_EEPROM_LEN 1024
  76. static int netxen_nic_get_eeprom_len(struct net_device *dev)
  77. {
  78. return NETXEN_FLASH_TOTAL_SIZE;
  79. }
  80. static void
  81. netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  82. {
  83. struct netxen_adapter *adapter = netdev_priv(dev);
  84. u32 fw_major = 0;
  85. u32 fw_minor = 0;
  86. u32 fw_build = 0;
  87. strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
  88. strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
  89. fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
  90. NETXEN_FW_VERSION_MAJOR));
  91. fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
  92. NETXEN_FW_VERSION_MINOR));
  93. fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
  94. sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
  95. strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  96. drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
  97. drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
  98. }
  99. static int
  100. netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  101. {
  102. struct netxen_adapter *adapter = netdev_priv(dev);
  103. struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
  104. /* read which mode */
  105. if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
  106. ecmd->supported = (SUPPORTED_10baseT_Half |
  107. SUPPORTED_10baseT_Full |
  108. SUPPORTED_100baseT_Half |
  109. SUPPORTED_100baseT_Full |
  110. SUPPORTED_1000baseT_Half |
  111. SUPPORTED_1000baseT_Full);
  112. ecmd->advertising = (ADVERTISED_100baseT_Half |
  113. ADVERTISED_100baseT_Full |
  114. ADVERTISED_1000baseT_Half |
  115. ADVERTISED_1000baseT_Full);
  116. ecmd->port = PORT_TP;
  117. if (netif_running(dev)) {
  118. ecmd->speed = adapter->link_speed;
  119. ecmd->duplex = adapter->link_duplex;
  120. } else
  121. return -EIO; /* link absent */
  122. } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
  123. ecmd->supported = (SUPPORTED_TP |
  124. SUPPORTED_1000baseT_Full |
  125. SUPPORTED_10000baseT_Full);
  126. ecmd->advertising = (ADVERTISED_TP |
  127. ADVERTISED_1000baseT_Full |
  128. ADVERTISED_10000baseT_Full);
  129. ecmd->port = PORT_TP;
  130. ecmd->speed = SPEED_10000;
  131. ecmd->duplex = DUPLEX_FULL;
  132. ecmd->autoneg = AUTONEG_DISABLE;
  133. } else
  134. return -EIO;
  135. ecmd->phy_address = adapter->portnum;
  136. ecmd->transceiver = XCVR_EXTERNAL;
  137. switch ((netxen_brdtype_t) boardinfo->board_type) {
  138. case NETXEN_BRDTYPE_P2_SB35_4G:
  139. case NETXEN_BRDTYPE_P2_SB31_2G:
  140. ecmd->supported |= SUPPORTED_Autoneg;
  141. ecmd->advertising |= ADVERTISED_Autoneg;
  142. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  143. ecmd->supported |= SUPPORTED_TP;
  144. ecmd->advertising |= ADVERTISED_TP;
  145. ecmd->port = PORT_TP;
  146. ecmd->autoneg = (boardinfo->board_type ==
  147. NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
  148. (AUTONEG_DISABLE) : (adapter->link_autoneg);
  149. break;
  150. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  151. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  152. ecmd->supported |= SUPPORTED_MII;
  153. ecmd->advertising |= ADVERTISED_MII;
  154. ecmd->port = PORT_FIBRE;
  155. ecmd->autoneg = AUTONEG_DISABLE;
  156. break;
  157. case NETXEN_BRDTYPE_P2_SB31_10G:
  158. ecmd->supported |= SUPPORTED_FIBRE;
  159. ecmd->advertising |= ADVERTISED_FIBRE;
  160. ecmd->port = PORT_FIBRE;
  161. ecmd->autoneg = AUTONEG_DISABLE;
  162. break;
  163. default:
  164. printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
  165. (netxen_brdtype_t) boardinfo->board_type);
  166. return -EIO;
  167. }
  168. return 0;
  169. }
  170. static int
  171. netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  172. {
  173. struct netxen_adapter *adapter = netdev_priv(dev);
  174. __u32 status;
  175. /* read which mode */
  176. if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
  177. /* autonegotiation */
  178. if (adapter->phy_write
  179. && adapter->phy_write(adapter,
  180. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  181. ecmd->autoneg) != 0)
  182. return -EIO;
  183. else
  184. adapter->link_autoneg = ecmd->autoneg;
  185. if (adapter->phy_read
  186. && adapter->phy_read(adapter,
  187. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  188. &status) != 0)
  189. return -EIO;
  190. /* speed */
  191. switch (ecmd->speed) {
  192. case SPEED_10:
  193. netxen_set_phy_speed(status, 0);
  194. break;
  195. case SPEED_100:
  196. netxen_set_phy_speed(status, 1);
  197. break;
  198. case SPEED_1000:
  199. netxen_set_phy_speed(status, 2);
  200. break;
  201. }
  202. /* set duplex mode */
  203. if (ecmd->duplex == DUPLEX_HALF)
  204. netxen_clear_phy_duplex(status);
  205. if (ecmd->duplex == DUPLEX_FULL)
  206. netxen_set_phy_duplex(status);
  207. if (adapter->phy_write
  208. && adapter->phy_write(adapter,
  209. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  210. *((int *)&status)) != 0)
  211. return -EIO;
  212. else {
  213. adapter->link_speed = ecmd->speed;
  214. adapter->link_duplex = ecmd->duplex;
  215. }
  216. } else
  217. return -EOPNOTSUPP;
  218. if (netif_running(dev)) {
  219. dev->stop(dev);
  220. dev->open(dev);
  221. }
  222. return 0;
  223. }
  224. static int netxen_nic_get_regs_len(struct net_device *dev)
  225. {
  226. return NETXEN_NIC_REGS_LEN;
  227. }
  228. struct netxen_niu_regs {
  229. __u32 reg[NETXEN_NIC_REGS_COUNT];
  230. };
  231. static struct netxen_niu_regs niu_registers[] = {
  232. {
  233. /* GB Mode */
  234. {
  235. NETXEN_NIU_GB_SERDES_RESET,
  236. NETXEN_NIU_GB0_MII_MODE,
  237. NETXEN_NIU_GB1_MII_MODE,
  238. NETXEN_NIU_GB2_MII_MODE,
  239. NETXEN_NIU_GB3_MII_MODE,
  240. NETXEN_NIU_GB0_GMII_MODE,
  241. NETXEN_NIU_GB1_GMII_MODE,
  242. NETXEN_NIU_GB2_GMII_MODE,
  243. NETXEN_NIU_GB3_GMII_MODE,
  244. NETXEN_NIU_REMOTE_LOOPBACK,
  245. NETXEN_NIU_GB0_HALF_DUPLEX,
  246. NETXEN_NIU_GB1_HALF_DUPLEX,
  247. NETXEN_NIU_RESET_SYS_FIFOS,
  248. NETXEN_NIU_GB_CRC_DROP,
  249. NETXEN_NIU_GB_DROP_WRONGADDR,
  250. NETXEN_NIU_TEST_MUX_CTL,
  251. NETXEN_NIU_GB_MAC_CONFIG_0(0),
  252. NETXEN_NIU_GB_MAC_CONFIG_1(0),
  253. NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
  254. NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
  255. NETXEN_NIU_GB_TEST_REG(0),
  256. NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
  257. NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
  258. NETXEN_NIU_GB_MII_MGMT_ADDR(0),
  259. NETXEN_NIU_GB_MII_MGMT_CTRL(0),
  260. NETXEN_NIU_GB_MII_MGMT_STATUS(0),
  261. NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
  262. NETXEN_NIU_GB_INTERFACE_CTRL(0),
  263. NETXEN_NIU_GB_INTERFACE_STATUS(0),
  264. NETXEN_NIU_GB_STATION_ADDR_0(0),
  265. NETXEN_NIU_GB_STATION_ADDR_1(0),
  266. -1,
  267. }
  268. },
  269. {
  270. /* XG Mode */
  271. {
  272. NETXEN_NIU_XG_SINGLE_TERM,
  273. NETXEN_NIU_XG_DRIVE_HI,
  274. NETXEN_NIU_XG_DRIVE_LO,
  275. NETXEN_NIU_XG_DTX,
  276. NETXEN_NIU_XG_DEQ,
  277. NETXEN_NIU_XG_WORD_ALIGN,
  278. NETXEN_NIU_XG_RESET,
  279. NETXEN_NIU_XG_POWER_DOWN,
  280. NETXEN_NIU_XG_RESET_PLL,
  281. NETXEN_NIU_XG_SERDES_LOOPBACK,
  282. NETXEN_NIU_XG_DO_BYTE_ALIGN,
  283. NETXEN_NIU_XG_TX_ENABLE,
  284. NETXEN_NIU_XG_RX_ENABLE,
  285. NETXEN_NIU_XG_STATUS,
  286. NETXEN_NIU_XG_PAUSE_THRESHOLD,
  287. NETXEN_NIU_XGE_CONFIG_0,
  288. NETXEN_NIU_XGE_CONFIG_1,
  289. NETXEN_NIU_XGE_IPG,
  290. NETXEN_NIU_XGE_STATION_ADDR_0_HI,
  291. NETXEN_NIU_XGE_STATION_ADDR_0_1,
  292. NETXEN_NIU_XGE_STATION_ADDR_1_LO,
  293. NETXEN_NIU_XGE_STATUS,
  294. NETXEN_NIU_XGE_MAX_FRAME_SIZE,
  295. NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
  296. NETXEN_NIU_XGE_TX_BYTE_CNT,
  297. NETXEN_NIU_XGE_TX_FRAME_CNT,
  298. NETXEN_NIU_XGE_RX_BYTE_CNT,
  299. NETXEN_NIU_XGE_RX_FRAME_CNT,
  300. NETXEN_NIU_XGE_AGGR_ERROR_CNT,
  301. NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
  302. NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
  303. NETXEN_NIU_XGE_CRC_ERROR_CNT,
  304. NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
  305. NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
  306. NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
  307. NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
  308. NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
  309. NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
  310. -1,
  311. }
  312. }
  313. };
  314. static void
  315. netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
  316. {
  317. struct netxen_adapter *adapter = netdev_priv(dev);
  318. __u32 mode, *regs_buff = p;
  319. void __iomem *addr;
  320. int i, window;
  321. memset(p, 0, NETXEN_NIC_REGS_LEN);
  322. regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
  323. (adapter->pdev)->device;
  324. /* which mode */
  325. NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, &regs_buff[0]);
  326. mode = regs_buff[0];
  327. /* Common registers to all the modes */
  328. NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER,
  329. &regs_buff[2]);
  330. /* GB/XGB Mode */
  331. mode = (mode / 2) - 1;
  332. window = 0;
  333. if (mode <= 1) {
  334. for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
  335. /* GB: port specific registers */
  336. if (mode == 0 && i >= 19)
  337. window = physical_port[adapter->portnum] *
  338. NETXEN_NIC_PORT_WINDOW;
  339. NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode].
  340. reg[i - 3] + window,
  341. &regs_buff[i]);
  342. }
  343. }
  344. }
  345. static u32 netxen_nic_test_link(struct net_device *dev)
  346. {
  347. struct netxen_adapter *adapter = netdev_priv(dev);
  348. __u32 status;
  349. int val;
  350. /* read which mode */
  351. if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
  352. if (adapter->phy_read
  353. && adapter->phy_read(adapter,
  354. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  355. &status) != 0)
  356. return -EIO;
  357. else {
  358. val = netxen_get_phy_link(status);
  359. return !val;
  360. }
  361. } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
  362. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  363. return (val == XG_LINK_UP) ? 0 : 1;
  364. }
  365. return -EIO;
  366. }
  367. static int
  368. netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  369. u8 * bytes)
  370. {
  371. struct netxen_adapter *adapter = netdev_priv(dev);
  372. int offset;
  373. int ret;
  374. if (eeprom->len == 0)
  375. return -EINVAL;
  376. eeprom->magic = (adapter->pdev)->vendor |
  377. ((adapter->pdev)->device << 16);
  378. offset = eeprom->offset;
  379. ret = netxen_rom_fast_read_words(adapter, offset, bytes,
  380. eeprom->len);
  381. if (ret < 0)
  382. return ret;
  383. return 0;
  384. }
  385. static int
  386. netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  387. u8 * bytes)
  388. {
  389. struct netxen_adapter *adapter = netdev_priv(dev);
  390. int offset = eeprom->offset;
  391. static int flash_start;
  392. static int ready_to_flash;
  393. int ret;
  394. if (flash_start == 0) {
  395. netxen_halt_pegs(adapter);
  396. ret = netxen_flash_unlock(adapter);
  397. if (ret < 0) {
  398. printk(KERN_ERR "%s: Flash unlock failed.\n",
  399. netxen_nic_driver_name);
  400. return ret;
  401. }
  402. printk(KERN_INFO "%s: flash unlocked. \n",
  403. netxen_nic_driver_name);
  404. last_schedule_time = jiffies;
  405. ret = netxen_flash_erase_secondary(adapter);
  406. if (ret != FLASH_SUCCESS) {
  407. printk(KERN_ERR "%s: Flash erase failed.\n",
  408. netxen_nic_driver_name);
  409. return ret;
  410. }
  411. printk(KERN_INFO "%s: secondary flash erased successfully.\n",
  412. netxen_nic_driver_name);
  413. flash_start = 1;
  414. return 0;
  415. }
  416. if (offset == NETXEN_BOOTLD_START) {
  417. ret = netxen_flash_erase_primary(adapter);
  418. if (ret != FLASH_SUCCESS) {
  419. printk(KERN_ERR "%s: Flash erase failed.\n",
  420. netxen_nic_driver_name);
  421. return ret;
  422. }
  423. ret = netxen_rom_se(adapter, NETXEN_USER_START);
  424. if (ret != FLASH_SUCCESS)
  425. return ret;
  426. ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
  427. if (ret != FLASH_SUCCESS)
  428. return ret;
  429. printk(KERN_INFO "%s: primary flash erased successfully\n",
  430. netxen_nic_driver_name);
  431. ret = netxen_backup_crbinit(adapter);
  432. if (ret != FLASH_SUCCESS) {
  433. printk(KERN_ERR "%s: CRBinit backup failed.\n",
  434. netxen_nic_driver_name);
  435. return ret;
  436. }
  437. printk(KERN_INFO "%s: CRBinit backup done.\n",
  438. netxen_nic_driver_name);
  439. ready_to_flash = 1;
  440. }
  441. if (!ready_to_flash) {
  442. printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
  443. netxen_nic_driver_name);
  444. return -EINVAL;
  445. }
  446. return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
  447. }
  448. static void
  449. netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
  450. {
  451. struct netxen_adapter *adapter = netdev_priv(dev);
  452. int i;
  453. ring->rx_pending = 0;
  454. ring->rx_jumbo_pending = 0;
  455. for (i = 0; i < MAX_RCV_CTX; ++i) {
  456. ring->rx_pending += adapter->recv_ctx[i].
  457. rcv_desc[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
  458. ring->rx_jumbo_pending += adapter->recv_ctx[i].
  459. rcv_desc[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
  460. }
  461. ring->tx_pending = adapter->max_tx_desc_count;
  462. ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
  463. ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
  464. ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
  465. ring->rx_mini_max_pending = 0;
  466. ring->rx_mini_pending = 0;
  467. }
  468. static void
  469. netxen_nic_get_pauseparam(struct net_device *dev,
  470. struct ethtool_pauseparam *pause)
  471. {
  472. struct netxen_adapter *adapter = netdev_priv(dev);
  473. __u32 val;
  474. int port = physical_port[adapter->portnum];
  475. if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
  476. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  477. return;
  478. /* get flow control settings */
  479. netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
  480. &val);
  481. pause->rx_pause = netxen_gb_get_rx_flowctl(val);
  482. netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
  483. switch (port) {
  484. case 0:
  485. pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
  486. break;
  487. case 1:
  488. pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
  489. break;
  490. case 2:
  491. pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
  492. break;
  493. case 3:
  494. default:
  495. pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
  496. break;
  497. }
  498. } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
  499. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  500. return;
  501. pause->rx_pause = 1;
  502. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
  503. if (port == 0)
  504. pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
  505. else
  506. pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
  507. } else {
  508. printk(KERN_ERR"%s: Unknown board type: %x\n",
  509. netxen_nic_driver_name, adapter->ahw.board_type);
  510. }
  511. }
  512. static int
  513. netxen_nic_set_pauseparam(struct net_device *dev,
  514. struct ethtool_pauseparam *pause)
  515. {
  516. struct netxen_adapter *adapter = netdev_priv(dev);
  517. __u32 val;
  518. int port = physical_port[adapter->portnum];
  519. /* read mode */
  520. if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
  521. if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
  522. return -EIO;
  523. /* set flow control */
  524. netxen_nic_read_w0(adapter,
  525. NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
  526. if (pause->rx_pause)
  527. netxen_gb_rx_flowctl(val);
  528. else
  529. netxen_gb_unset_rx_flowctl(val);
  530. netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
  531. val);
  532. /* set autoneg */
  533. netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
  534. switch (port) {
  535. case 0:
  536. if (pause->tx_pause)
  537. netxen_gb_unset_gb0_mask(val);
  538. else
  539. netxen_gb_set_gb0_mask(val);
  540. break;
  541. case 1:
  542. if (pause->tx_pause)
  543. netxen_gb_unset_gb1_mask(val);
  544. else
  545. netxen_gb_set_gb1_mask(val);
  546. break;
  547. case 2:
  548. if (pause->tx_pause)
  549. netxen_gb_unset_gb2_mask(val);
  550. else
  551. netxen_gb_set_gb2_mask(val);
  552. break;
  553. case 3:
  554. default:
  555. if (pause->tx_pause)
  556. netxen_gb_unset_gb3_mask(val);
  557. else
  558. netxen_gb_set_gb3_mask(val);
  559. break;
  560. }
  561. netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
  562. } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
  563. if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
  564. return -EIO;
  565. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
  566. if (port == 0) {
  567. if (pause->tx_pause)
  568. netxen_xg_unset_xg0_mask(val);
  569. else
  570. netxen_xg_set_xg0_mask(val);
  571. } else {
  572. if (pause->tx_pause)
  573. netxen_xg_unset_xg1_mask(val);
  574. else
  575. netxen_xg_set_xg1_mask(val);
  576. }
  577. netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
  578. } else {
  579. printk(KERN_ERR "%s: Unknown board type: %x\n",
  580. netxen_nic_driver_name,
  581. adapter->ahw.board_type);
  582. }
  583. return 0;
  584. }
  585. static int netxen_nic_reg_test(struct net_device *dev)
  586. {
  587. struct netxen_adapter *adapter = netdev_priv(dev);
  588. u32 data_read, data_written;
  589. netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
  590. if ((data_read & 0xffff) != PHAN_VENDOR_ID)
  591. return 1;
  592. data_written = (u32)0xa5a5a5a5;
  593. netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
  594. data_read = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_SCRATCHPAD_TEST));
  595. if (data_written != data_read)
  596. return 1;
  597. return 0;
  598. }
  599. static int netxen_get_sset_count(struct net_device *dev, int sset)
  600. {
  601. switch (sset) {
  602. case ETH_SS_TEST:
  603. return NETXEN_NIC_TEST_LEN;
  604. case ETH_SS_STATS:
  605. return NETXEN_NIC_STATS_LEN;
  606. default:
  607. return -EOPNOTSUPP;
  608. }
  609. }
  610. static void
  611. netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
  612. u64 * data)
  613. {
  614. memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
  615. if ((data[0] = netxen_nic_reg_test(dev)))
  616. eth_test->flags |= ETH_TEST_FL_FAILED;
  617. /* link test */
  618. if ((data[1] = (u64) netxen_nic_test_link(dev)))
  619. eth_test->flags |= ETH_TEST_FL_FAILED;
  620. }
  621. static void
  622. netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
  623. {
  624. int index;
  625. switch (stringset) {
  626. case ETH_SS_TEST:
  627. memcpy(data, *netxen_nic_gstrings_test,
  628. NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
  629. break;
  630. case ETH_SS_STATS:
  631. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  632. memcpy(data + index * ETH_GSTRING_LEN,
  633. netxen_nic_gstrings_stats[index].stat_string,
  634. ETH_GSTRING_LEN);
  635. }
  636. break;
  637. }
  638. }
  639. static void
  640. netxen_nic_get_ethtool_stats(struct net_device *dev,
  641. struct ethtool_stats *stats, u64 * data)
  642. {
  643. struct netxen_adapter *adapter = netdev_priv(dev);
  644. int index;
  645. for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
  646. char *p =
  647. (char *)adapter +
  648. netxen_nic_gstrings_stats[index].stat_offset;
  649. data[index] =
  650. (netxen_nic_gstrings_stats[index].sizeof_stat ==
  651. sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
  652. }
  653. }
  654. static u32 netxen_nic_get_rx_csum(struct net_device *dev)
  655. {
  656. struct netxen_adapter *adapter = netdev_priv(dev);
  657. return adapter->rx_csum;
  658. }
  659. static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
  660. {
  661. struct netxen_adapter *adapter = netdev_priv(dev);
  662. adapter->rx_csum = !!data;
  663. return 0;
  664. }
  665. struct ethtool_ops netxen_nic_ethtool_ops = {
  666. .get_settings = netxen_nic_get_settings,
  667. .set_settings = netxen_nic_set_settings,
  668. .get_drvinfo = netxen_nic_get_drvinfo,
  669. .get_regs_len = netxen_nic_get_regs_len,
  670. .get_regs = netxen_nic_get_regs,
  671. .get_link = ethtool_op_get_link,
  672. .get_eeprom_len = netxen_nic_get_eeprom_len,
  673. .get_eeprom = netxen_nic_get_eeprom,
  674. .set_eeprom = netxen_nic_set_eeprom,
  675. .get_ringparam = netxen_nic_get_ringparam,
  676. .get_pauseparam = netxen_nic_get_pauseparam,
  677. .set_pauseparam = netxen_nic_set_pauseparam,
  678. .set_tx_csum = ethtool_op_set_tx_csum,
  679. .set_sg = ethtool_op_set_sg,
  680. .set_tso = ethtool_op_set_tso,
  681. .self_test = netxen_nic_diag_test,
  682. .get_strings = netxen_nic_get_strings,
  683. .get_ethtool_stats = netxen_nic_get_ethtool_stats,
  684. .get_sset_count = netxen_get_sset_count,
  685. .get_rx_csum = netxen_nic_get_rx_csum,
  686. .set_rx_csum = netxen_nic_set_rx_csum,
  687. };