netxen_nic_isr.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. #include <linux/netdevice.h>
  30. #include <linux/delay.h>
  31. #include "netxen_nic.h"
  32. #include "netxen_nic_hw.h"
  33. #include "netxen_nic_phan_reg.h"
  34. /*
  35. * netxen_nic_get_stats - Get System Network Statistics
  36. * @netdev: network interface device structure
  37. */
  38. struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
  39. {
  40. struct netxen_adapter *adapter = netdev_priv(netdev);
  41. struct net_device_stats *stats = &adapter->net_stats;
  42. memset(stats, 0, sizeof(*stats));
  43. /* total packets received */
  44. stats->rx_packets = adapter->stats.no_rcv;
  45. /* total packets transmitted */
  46. stats->tx_packets = adapter->stats.xmitedframes +
  47. adapter->stats.xmitfinished;
  48. /* total bytes received */
  49. stats->rx_bytes = adapter->stats.rxbytes;
  50. /* total bytes transmitted */
  51. stats->tx_bytes = adapter->stats.txbytes;
  52. /* bad packets received */
  53. stats->rx_errors = adapter->stats.rcvdbadskb;
  54. /* packet transmit problems */
  55. stats->tx_errors = adapter->stats.nocmddescriptor;
  56. /* no space in linux buffers */
  57. stats->rx_dropped = adapter->stats.rxdropped;
  58. /* no space available in linux */
  59. stats->tx_dropped = adapter->stats.txdropped;
  60. return stats;
  61. }
  62. static void netxen_indicate_link_status(struct netxen_adapter *adapter,
  63. u32 link)
  64. {
  65. struct net_device *netdev = adapter->netdev;
  66. if (link)
  67. netif_carrier_on(netdev);
  68. else
  69. netif_carrier_off(netdev);
  70. }
  71. #if 0
  72. void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable)
  73. {
  74. __u32 int_src;
  75. /* This should clear the interrupt source */
  76. if (adapter->phy_read)
  77. adapter->phy_read(adapter,
  78. NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
  79. &int_src);
  80. if (int_src == 0) {
  81. DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
  82. return;
  83. }
  84. if (adapter->disable_phy_interrupts)
  85. adapter->disable_phy_interrupts(adapter);
  86. if (netxen_get_phy_int_jabber(int_src))
  87. DPRINTK(INFO, "Jabber interrupt \n");
  88. if (netxen_get_phy_int_polarity_changed(int_src))
  89. DPRINTK(INFO, "POLARITY CHANGED int \n");
  90. if (netxen_get_phy_int_energy_detect(int_src))
  91. DPRINTK(INFO, "ENERGY DETECT INT \n");
  92. if (netxen_get_phy_int_downshift(int_src))
  93. DPRINTK(INFO, "DOWNSHIFT INT \n");
  94. /* write it down later.. */
  95. if ((netxen_get_phy_int_speed_changed(int_src))
  96. || (netxen_get_phy_int_link_status_changed(int_src))) {
  97. __u32 status;
  98. DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
  99. if (adapter->phy_read
  100. && adapter->phy_read(adapter,
  101. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  102. &status) == 0) {
  103. if (netxen_get_phy_int_link_status_changed(int_src)) {
  104. if (netxen_get_phy_link(status)) {
  105. printk(KERN_INFO "%s: %s Link UP\n",
  106. netxen_nic_driver_name,
  107. adapter->netdev->name);
  108. } else {
  109. printk(KERN_INFO "%s: %s Link DOWN\n",
  110. netxen_nic_driver_name,
  111. adapter->netdev->name);
  112. }
  113. netxen_indicate_link_status(adapter,
  114. netxen_get_phy_link
  115. (status));
  116. }
  117. }
  118. }
  119. if (adapter->enable_phy_interrupts)
  120. adapter->enable_phy_interrupts(adapter);
  121. }
  122. #endif /* 0 */
  123. static void netxen_nic_isr_other(struct netxen_adapter *adapter)
  124. {
  125. int portno = adapter->portnum;
  126. u32 val, linkup, qg_linksup;
  127. /* verify the offset */
  128. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  129. val = val >> physical_port[adapter->portnum];
  130. if (val == adapter->ahw.qg_linksup)
  131. return;
  132. qg_linksup = adapter->ahw.qg_linksup;
  133. adapter->ahw.qg_linksup = val;
  134. DPRINTK(INFO, "link update 0x%08x\n", val);
  135. linkup = val & 1;
  136. if (linkup != (qg_linksup & 1)) {
  137. printk(KERN_INFO "%s: %s PORT %d link %s\n",
  138. adapter->netdev->name,
  139. netxen_nic_driver_name, portno,
  140. ((linkup == 0) ? "down" : "up"));
  141. netxen_indicate_link_status(adapter, linkup);
  142. if (linkup)
  143. netxen_nic_set_link_parameters(adapter);
  144. }
  145. }
  146. void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
  147. {
  148. netxen_nic_isr_other(adapter);
  149. }
  150. #if 0
  151. int netxen_nic_link_ok(struct netxen_adapter *adapter)
  152. {
  153. switch (adapter->ahw.board_type) {
  154. case NETXEN_NIC_GBE:
  155. return ((adapter->ahw.qg_linksup) & 1);
  156. case NETXEN_NIC_XGBE:
  157. return ((adapter->ahw.xg_linkup) & 1);
  158. default:
  159. printk(KERN_ERR"%s: Function: %s, Unknown board type\n",
  160. netxen_nic_driver_name, __FUNCTION__);
  161. break;
  162. }
  163. return 0;
  164. }
  165. #endif /* 0 */
  166. void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
  167. {
  168. struct net_device *netdev = adapter->netdev;
  169. u32 val;
  170. /* WINDOW = 1 */
  171. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  172. val >>= (physical_port[adapter->portnum] * 8);
  173. val &= 0xff;
  174. if (adapter->ahw.xg_linkup == 1 && val != XG_LINK_UP) {
  175. printk(KERN_INFO "%s: %s NIC Link is down\n",
  176. netxen_nic_driver_name, netdev->name);
  177. adapter->ahw.xg_linkup = 0;
  178. if (netif_running(netdev)) {
  179. netif_carrier_off(netdev);
  180. netif_stop_queue(netdev);
  181. }
  182. } else if (adapter->ahw.xg_linkup == 0 && val == XG_LINK_UP) {
  183. printk(KERN_INFO "%s: %s NIC Link is up\n",
  184. netxen_nic_driver_name, netdev->name);
  185. adapter->ahw.xg_linkup = 1;
  186. netif_carrier_on(netdev);
  187. netif_wake_queue(netdev);
  188. }
  189. }