xref: /illumos-gate/usr/src/uts/common/io/ntxn/unm_nic_isr.c (revision 07a48826732249fcd3aa8dd53c8389595e9f1fbc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 NetXen, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/types.h>
28 #include <sys/conf.h>
29 #include <sys/debug.h>
30 #include <sys/stropts.h>
31 #include <sys/stream.h>
32 #include <sys/strlog.h>
33 #include <sys/kmem.h>
34 #include <sys/stat.h>
35 #include <sys/kstat.h>
36 #include <sys/vtrace.h>
37 #include <sys/dlpi.h>
38 #include <sys/strsun.h>
39 #include <sys/ethernet.h>
40 #include <sys/modctl.h>
41 #include <sys/errno.h>
42 #include <sys/dditypes.h>
43 #include <sys/ddi.h>
44 #include <sys/sunddi.h>
45 #include <sys/sysmacros.h>
46 
47 #include <sys/pci.h>
48 
49 #include "unm_nic.h"
50 #include "unm_nic_hw.h"
51 #include "nic_cmn.h"
52 #include "nic_phan_reg.h"
53 
54 static void
55 unm_nic_isr_other(struct unm_adapter_s *adapter)
56 {
57 	u32 portno = adapter->portnum;
58 	u32 val, linkup, qg_linksup = adapter->ahw.linkup;
59 
60 	UNM_READ_LOCK(&adapter->adapter_lock);
61 	adapter->unm_nic_hw_read_wx(adapter, CRB_XG_STATE, &val, 4);
62 	UNM_READ_UNLOCK(&adapter->adapter_lock);
63 
64 	linkup = 1 & (val >> adapter->physical_port);
65 	adapter->ahw.linkup = linkup;
66 
67 	if (linkup != qg_linksup) {
68 		cmn_err(CE_WARN, "%s: PORT %d link %s\n", unm_nic_driver_name,
69 		    portno, ((linkup == 0) ? "down" : "up"));
70 		mac_link_update(adapter->mach, linkup);
71 		if (linkup)
72 			unm_nic_set_link_parameters(adapter);
73 	}
74 }
75 
76 void
77 unm_nic_handle_phy_intr(struct unm_adapter_s *adapter)
78 {
79 	uint32_t	val, val1, linkupval;
80 
81 	switch (adapter->ahw.board_type) {
82 		case UNM_NIC_GBE:
83 			if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
84 				unm_nic_isr_other(adapter);
85 				break;
86 			}
87 		/* FALLTHROUGH */
88 
89 		case UNM_NIC_XGBE:
90 			/* WINDOW = 1 */
91 		UNM_READ_LOCK(&adapter->adapter_lock);
92 		if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
93 			adapter->unm_nic_hw_read_wx(adapter, CRB_XG_STATE_P3,
94 			    &val, 4);
95 			val1 = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
96 			linkupval = XG_LINK_UP_P3;
97 		} else {
98 			adapter->unm_nic_hw_read_wx(adapter, CRB_XG_STATE,
99 			    &val, 4);
100 			val >>= (adapter->portnum * 8);
101 			val1 = val & 0xff;
102 			linkupval = XG_LINK_UP;
103 		}
104 		UNM_READ_UNLOCK(&adapter->adapter_lock);
105 
106 		if (adapter->ahw.linkup && (val1 != linkupval)) {
107 			if (verbmsg != 0)
108 				cmn_err(CE_NOTE, "%s%d: NIC Link is down\n",
109 				    adapter->name, adapter->portnum);
110 			mac_link_update(adapter->mach, LINK_STATE_DOWN);
111 			adapter->ahw.linkup = 0;
112 		} else if ((adapter->ahw.linkup == 0) && (val1 == linkupval)) {
113 			if (verbmsg != 0)
114 				cmn_err(CE_NOTE, "%s%d: NIC Link is up\n",
115 				    adapter->name, adapter->portnum);
116 			mac_link_update(adapter->mach, LINK_STATE_UP);
117 			adapter->ahw.linkup = 1;
118 
119 			if (adapter->ahw.board_type == UNM_NIC_GBE)
120 				unm_nic_set_link_parameters(adapter);
121 		}
122 
123 		break;
124 
125 		default:
126 		DPRINTF(0, (CE_WARN, "%s%d ISR: Unknown board type\n",
127 		    unm_nic_driver_name, adapter->portnum));
128 	}
129 }
130