netxen_nic_isr.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_port *port = netdev_priv(netdev);
  41. struct net_device_stats *stats = &port->net_stats;
  42. memset(stats, 0, sizeof(*stats));
  43. /* total packets received */
  44. stats->rx_packets = port->stats.no_rcv;
  45. /* total packets transmitted */
  46. stats->tx_packets = port->stats.xmitedframes + port->stats.xmitfinished;
  47. /* total bytes received */
  48. stats->rx_bytes = port->stats.rxbytes;
  49. /* total bytes transmitted */
  50. stats->tx_bytes = port->stats.txbytes;
  51. /* bad packets received */
  52. stats->rx_errors = port->stats.rcvdbadskb;
  53. /* packet transmit problems */
  54. stats->tx_errors = port->stats.nocmddescriptor;
  55. /* no space in linux buffers */
  56. stats->rx_dropped = port->stats.updropped;
  57. /* no space available in linux */
  58. stats->tx_dropped = port->stats.txdropped;
  59. return stats;
  60. }
  61. void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 portno,
  62. u32 link)
  63. {
  64. struct net_device *netdev = (adapter->port[portno])->netdev;
  65. if (link)
  66. netif_carrier_on(netdev);
  67. else
  68. netif_carrier_off(netdev);
  69. }
  70. void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno,
  71. u32 enable)
  72. {
  73. __le32 int_src;
  74. struct netxen_port *port;
  75. /* This should clear the interrupt source */
  76. if (adapter->phy_read)
  77. adapter->phy_read(adapter, portno,
  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, portno);
  86. port = adapter->port[portno];
  87. if (netxen_get_phy_int_jabber(int_src))
  88. DPRINTK(INFO, "Jabber interrupt \n");
  89. if (netxen_get_phy_int_polarity_changed(int_src))
  90. DPRINTK(INFO, "POLARITY CHANGED int \n");
  91. if (netxen_get_phy_int_energy_detect(int_src))
  92. DPRINTK(INFO, "ENERGY DETECT INT \n");
  93. if (netxen_get_phy_int_downshift(int_src))
  94. DPRINTK(INFO, "DOWNSHIFT INT \n");
  95. /* write it down later.. */
  96. if ((netxen_get_phy_int_speed_changed(int_src))
  97. || (netxen_get_phy_int_link_status_changed(int_src))) {
  98. __le32 status;
  99. DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
  100. if (adapter->phy_read
  101. && adapter->phy_read(adapter, portno,
  102. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  103. &status) == 0) {
  104. if (netxen_get_phy_int_link_status_changed(int_src)) {
  105. if (netxen_get_phy_link(status)) {
  106. netxen_niu_gbe_init_port(adapter,
  107. portno);
  108. printk("%s: %s Link UP\n",
  109. netxen_nic_driver_name,
  110. port->netdev->name);
  111. } else {
  112. printk("%s: %s Link DOWN\n",
  113. netxen_nic_driver_name,
  114. port->netdev->name);
  115. }
  116. netxen_indicate_link_status(adapter, portno,
  117. netxen_get_phy_link
  118. (status));
  119. }
  120. }
  121. }
  122. if (adapter->enable_phy_interrupts)
  123. adapter->enable_phy_interrupts(adapter, portno);
  124. }
  125. void netxen_nic_isr_other(struct netxen_adapter *adapter)
  126. {
  127. u32 portno;
  128. u32 val, linkup, qg_linksup;
  129. /* verify the offset */
  130. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  131. if (val == adapter->ahw.qg_linksup)
  132. return;
  133. qg_linksup = adapter->ahw.qg_linksup;
  134. adapter->ahw.qg_linksup = val;
  135. DPRINTK(INFO, "link update 0x%08x\n", val);
  136. for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) {
  137. linkup = val & 1;
  138. if (linkup != (qg_linksup & 1)) {
  139. printk(KERN_INFO "%s: %s PORT %d link %s\n",
  140. adapter->port[portno]->netdev->name,
  141. netxen_nic_driver_name, portno,
  142. ((linkup == 0) ? "down" : "up"));
  143. netxen_indicate_link_status(adapter, portno, linkup);
  144. if (linkup)
  145. netxen_nic_set_link_parameters(adapter->
  146. port[portno]);
  147. }
  148. val = val >> 1;
  149. qg_linksup = qg_linksup >> 1;
  150. }
  151. adapter->stats.otherints++;
  152. }
  153. void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
  154. {
  155. netxen_nic_isr_other(adapter);
  156. }
  157. void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
  158. {
  159. struct net_device *netdev = adapter->port[0]->netdev;
  160. u32 val;
  161. /* WINDOW = 1 */
  162. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  163. if (adapter->ahw.xg_linkup == 1 && val != XG_LINK_UP) {
  164. printk(KERN_INFO "%s: %s NIC Link is down\n",
  165. netxen_nic_driver_name, netdev->name);
  166. adapter->ahw.xg_linkup = 0;
  167. /* read twice to clear sticky bits */
  168. /* WINDOW = 0 */
  169. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val);
  170. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val);
  171. if ((val & 0xffb) != 0xffb) {
  172. printk(KERN_INFO "%s ISR: Sync/Align BAD: 0x%08x\n",
  173. netxen_nic_driver_name, val);
  174. }
  175. } else if (adapter->ahw.xg_linkup == 0 && val == XG_LINK_UP) {
  176. printk(KERN_INFO "%s: %s NIC Link is up\n",
  177. netxen_nic_driver_name, netdev->name);
  178. adapter->ahw.xg_linkup = 1;
  179. }
  180. }