netxen_nic_isr.c 6.3 KB

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