netxen_nic_isr.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.updropped;
  58. /* no space available in linux */
  59. stats->tx_dropped = adapter->stats.txdropped;
  60. return stats;
  61. }
  62. void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 link)
  63. {
  64. struct net_device *netdev = adapter->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 enable)
  71. {
  72. __u32 int_src;
  73. /* This should clear the interrupt source */
  74. if (adapter->phy_read)
  75. adapter->phy_read(adapter,
  76. NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
  77. &int_src);
  78. if (int_src == 0) {
  79. DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
  80. return;
  81. }
  82. if (adapter->disable_phy_interrupts)
  83. adapter->disable_phy_interrupts(adapter);
  84. if (netxen_get_phy_int_jabber(int_src))
  85. DPRINTK(INFO, "Jabber interrupt \n");
  86. if (netxen_get_phy_int_polarity_changed(int_src))
  87. DPRINTK(INFO, "POLARITY CHANGED int \n");
  88. if (netxen_get_phy_int_energy_detect(int_src))
  89. DPRINTK(INFO, "ENERGY DETECT INT \n");
  90. if (netxen_get_phy_int_downshift(int_src))
  91. DPRINTK(INFO, "DOWNSHIFT INT \n");
  92. /* write it down later.. */
  93. if ((netxen_get_phy_int_speed_changed(int_src))
  94. || (netxen_get_phy_int_link_status_changed(int_src))) {
  95. __u32 status;
  96. DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
  97. if (adapter->phy_read
  98. && adapter->phy_read(adapter,
  99. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  100. &status) == 0) {
  101. if (netxen_get_phy_int_link_status_changed(int_src)) {
  102. if (netxen_get_phy_link(status)) {
  103. printk(KERN_INFO "%s: %s Link UP\n",
  104. netxen_nic_driver_name,
  105. adapter->netdev->name);
  106. } else {
  107. printk(KERN_INFO "%s: %s Link DOWN\n",
  108. netxen_nic_driver_name,
  109. adapter->netdev->name);
  110. }
  111. netxen_indicate_link_status(adapter,
  112. netxen_get_phy_link
  113. (status));
  114. }
  115. }
  116. }
  117. if (adapter->enable_phy_interrupts)
  118. adapter->enable_phy_interrupts(adapter);
  119. }
  120. void netxen_nic_isr_other(struct netxen_adapter *adapter)
  121. {
  122. int portno = adapter->portnum;
  123. u32 val, linkup, qg_linksup;
  124. /* verify the offset */
  125. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  126. val = val >> physical_port[adapter->portnum];
  127. if (val == adapter->ahw.qg_linksup)
  128. return;
  129. qg_linksup = adapter->ahw.qg_linksup;
  130. adapter->ahw.qg_linksup = val;
  131. DPRINTK(INFO, "link update 0x%08x\n", val);
  132. linkup = val & 1;
  133. if (linkup != (qg_linksup & 1)) {
  134. printk(KERN_INFO "%s: %s PORT %d link %s\n",
  135. adapter->netdev->name,
  136. netxen_nic_driver_name, portno,
  137. ((linkup == 0) ? "down" : "up"));
  138. netxen_indicate_link_status(adapter, linkup);
  139. if (linkup)
  140. netxen_nic_set_link_parameters(adapter);
  141. }
  142. }
  143. void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
  144. {
  145. netxen_nic_isr_other(adapter);
  146. }
  147. void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
  148. {
  149. struct net_device *netdev = adapter->netdev;
  150. u32 val, val1;
  151. /* WINDOW = 1 */
  152. val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
  153. val >>= (physical_port[adapter->portnum] * 8);
  154. val1 = val & 0xff;
  155. if (adapter->ahw.xg_linkup == 1 && val1 != XG_LINK_UP) {
  156. printk(KERN_INFO "%s: %s NIC Link is down\n",
  157. netxen_nic_driver_name, netdev->name);
  158. adapter->ahw.xg_linkup = 0;
  159. /* read twice to clear sticky bits */
  160. /* WINDOW = 0 */
  161. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
  162. netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
  163. if ((val & 0xffb) != 0xffb) {
  164. printk(KERN_INFO "%s ISR: Sync/Align BAD: 0x%08x\n",
  165. netxen_nic_driver_name, val1);
  166. }
  167. } else if (adapter->ahw.xg_linkup == 0 && val1 == XG_LINK_UP) {
  168. printk(KERN_INFO "%s: %s NIC Link is up\n",
  169. netxen_nic_driver_name, netdev->name);
  170. adapter->ahw.xg_linkup = 1;
  171. }
  172. }