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.
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.
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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
30 #define RGE_DBG RGE_DBG_STATS /* debug flag for this code */
33 * Local datatype for defining tables of (Offset, Name) pairs
40 static const rge_ksindex_t rge_driverinfo
[] = {
41 { 0, "rx_ring_addr" },
45 { 4, "tx_ring_addr" },
49 { 8, "resched_needed" },
62 rge_driverinfo_update(kstat_t
*ksp
, int flag
)
67 if (flag
!= KSTAT_READ
)
70 rgep
= ksp
->ks_private
;
73 (knp
++)->value
.ui64
= rgep
->dma_area_rxdesc
.cookie
.dmac_laddress
;
74 (knp
++)->value
.ui64
= rgep
->rx_next
;
75 (knp
++)->value
.ui64
= rgep
->rx_free
;
76 (knp
++)->value
.ui64
= rgep
->rx_bcopy
;
77 (knp
++)->value
.ui64
= rgep
->dma_area_txdesc
.cookie
.dmac_laddress
;
78 (knp
++)->value
.ui64
= rgep
->tx_next
;
79 (knp
++)->value
.ui64
= rgep
->tx_free
;
80 (knp
++)->value
.ui64
= rgep
->tx_flow
;
81 (knp
++)->value
.ui64
= rgep
->resched_needed
;
82 (knp
++)->value
.ui64
= rgep
->watchdog
;
83 (knp
++)->value
.ui64
= rgep
->chipid
.rxconfig
;
84 (knp
++)->value
.ui64
= rgep
->chipid
.txconfig
;
85 (knp
++)->value
.ui64
= rgep
->chipid
.mac_ver
;
86 (knp
++)->value
.ui64
= rgep
->chipid
.phy_ver
;
87 (knp
++)->value
.ui64
= rgep
->stats
.chip_reset
;
88 (knp
++)->value
.ui64
= rgep
->stats
.phy_reset
;
89 (knp
++)->value
.ui64
= rgep
->param_loop_mode
;
95 rge_setup_named_kstat(rge_t
*rgep
, int instance
, char *name
,
96 const rge_ksindex_t
*ksip
, size_t size
, int (*update
)(kstat_t
*, int))
103 size
/= sizeof (rge_ksindex_t
);
104 ksp
= kstat_create(RGE_DRIVER_NAME
, instance
, name
, "net",
105 KSTAT_TYPE_NAMED
, size
-1, KSTAT_FLAG_PERSISTENT
);
109 ksp
->ks_private
= rgep
;
110 ksp
->ks_update
= update
;
111 for (knp
= ksp
->ks_data
; (np
= ksip
->name
) != NULL
; ++knp
, ++ksip
) {
114 type
= KSTAT_DATA_UINT64
;
118 type
= KSTAT_DATA_UINT32
;
122 type
= KSTAT_DATA_STRING
;
126 type
= KSTAT_DATA_CHAR
;
129 kstat_named_init(knp
, np
, type
);
137 rge_init_kstats(rge_t
*rgep
, int instance
)
139 rgep
->rge_kstats
[RGE_KSTAT_DRIVER
] = rge_setup_named_kstat(rgep
,
140 instance
, "driverinfo", rge_driverinfo
,
141 sizeof (rge_driverinfo
), rge_driverinfo_update
);
145 rge_fini_kstats(rge_t
*rgep
)
149 for (i
= RGE_KSTAT_COUNT
; --i
>= 0; )
150 if (rgep
->rge_kstats
[i
] != NULL
) {
151 kstat_delete(rgep
->rge_kstats
[i
]);
156 rge_m_stat(void *arg
, uint_t stat
, uint64_t *val
)
159 rge_hw_stats_t
*bstp
;
161 mutex_enter(rgep
->genlock
);
162 rge_hw_stats_dump(rgep
);
163 mutex_exit(rgep
->genlock
);
164 bstp
= rgep
->hw_stats
;
167 case MAC_STAT_IFSPEED
:
168 *val
= rgep
->param_link_speed
* 1000000ull;
171 case MAC_STAT_MULTIRCV
:
172 *val
= RGE_BSWAP_32(bstp
->multi_rcv
);
175 case MAC_STAT_BRDCSTRCV
:
176 *val
= RGE_BSWAP_64(bstp
->brdcst_rcv
);
179 case MAC_STAT_NORCVBUF
:
180 *val
= RGE_BSWAP_16(bstp
->in_discards
);
183 case MAC_STAT_IERRORS
:
184 *val
= RGE_BSWAP_32(bstp
->rcv_err
);
187 case MAC_STAT_OERRORS
:
188 *val
= RGE_BSWAP_64(bstp
->xmt_err
);
191 case MAC_STAT_COLLISIONS
:
192 *val
= RGE_BSWAP_32(bstp
->xmt_1col
+ bstp
->xmt_mcol
);
195 case MAC_STAT_RBYTES
:
196 *val
= rgep
->stats
.rbytes
;
199 case MAC_STAT_IPACKETS
:
200 *val
= RGE_BSWAP_64(bstp
->rcv_ok
);
203 case MAC_STAT_OBYTES
:
204 *val
= rgep
->stats
.obytes
;
207 case MAC_STAT_OPACKETS
:
208 *val
= RGE_BSWAP_64(bstp
->xmt_ok
);
211 case ETHER_STAT_ALIGN_ERRORS
:
212 *val
= RGE_BSWAP_16(bstp
->frame_err
);
215 case ETHER_STAT_FIRST_COLLISIONS
:
216 *val
= RGE_BSWAP_32(bstp
->xmt_1col
);
219 case ETHER_STAT_MULTI_COLLISIONS
:
220 *val
= RGE_BSWAP_32(bstp
->xmt_mcol
);
223 case ETHER_STAT_DEFER_XMTS
:
224 *val
= rgep
->stats
.defer
;
227 case ETHER_STAT_XCVR_ADDR
:
228 *val
= rgep
->phy_mii_addr
;
231 case ETHER_STAT_XCVR_ID
:
232 mutex_enter(rgep
->genlock
);
233 *val
= rge_mii_get16(rgep
, MII_PHYIDH
);
235 *val
|= rge_mii_get16(rgep
, MII_PHYIDL
);
236 mutex_exit(rgep
->genlock
);
239 case ETHER_STAT_XCVR_INUSE
:
243 case ETHER_STAT_CAP_1000FDX
:
247 case ETHER_STAT_CAP_1000HDX
:
251 case ETHER_STAT_CAP_100FDX
:
255 case ETHER_STAT_CAP_100HDX
:
259 case ETHER_STAT_CAP_10FDX
:
263 case ETHER_STAT_CAP_10HDX
:
267 case ETHER_STAT_CAP_ASMPAUSE
:
271 case ETHER_STAT_CAP_PAUSE
:
275 case ETHER_STAT_CAP_AUTONEG
:
279 case ETHER_STAT_ADV_CAP_1000FDX
:
280 *val
= rgep
->param_adv_1000fdx
;
283 case ETHER_STAT_ADV_CAP_1000HDX
:
284 *val
= rgep
->param_adv_1000hdx
;
287 case ETHER_STAT_ADV_CAP_100FDX
:
288 *val
= rgep
->param_adv_100fdx
;
291 case ETHER_STAT_ADV_CAP_100HDX
:
292 *val
= rgep
->param_adv_100hdx
;
295 case ETHER_STAT_ADV_CAP_10FDX
:
296 *val
= rgep
->param_adv_10fdx
;
299 case ETHER_STAT_ADV_CAP_10HDX
:
300 *val
= rgep
->param_adv_10hdx
;
303 case ETHER_STAT_ADV_CAP_ASMPAUSE
:
304 *val
= rgep
->param_adv_asym_pause
;
307 case ETHER_STAT_ADV_CAP_PAUSE
:
308 *val
= rgep
->param_adv_pause
;
311 case ETHER_STAT_ADV_CAP_AUTONEG
:
312 *val
= rgep
->param_adv_autoneg
;
315 case ETHER_STAT_LINK_DUPLEX
:
316 *val
= rgep
->param_link_duplex
;