netxen_nic_isr.c 5.8 KB

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