15779Sxy150489 /*
25779Sxy150489 * CDDL HEADER START
35779Sxy150489 *
48955SChenlu.Chen@Sun.COM * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
55779Sxy150489 * The contents of this file are subject to the terms of the
65779Sxy150489 * Common Development and Distribution License (the "License").
75779Sxy150489 * You may not use this file except in compliance with the License.
85779Sxy150489 *
9*11878SVenu.Iyer@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*11878SVenu.Iyer@Sun.COM * or http://www.opensolaris.org/os/licensing.
115779Sxy150489 * See the License for the specific language governing permissions
125779Sxy150489 * and limitations under the License.
135779Sxy150489 *
14*11878SVenu.Iyer@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
15*11878SVenu.Iyer@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
165779Sxy150489 * If applicable, add the following below this CDDL HEADER, with the
175779Sxy150489 * fields enclosed by brackets "[]" replaced with your own identifying
185779Sxy150489 * information: Portions Copyright [yyyy] [name of copyright owner]
195779Sxy150489 *
205779Sxy150489 * CDDL HEADER END
215779Sxy150489 */
225779Sxy150489
235779Sxy150489 /*
24*11878SVenu.Iyer@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25*11878SVenu.Iyer@Sun.COM * Use is subject to license terms.
265779Sxy150489 */
275779Sxy150489
285779Sxy150489 #include "igb_sw.h"
295779Sxy150489
305779Sxy150489 /*
315779Sxy150489 * Update driver private statistics.
325779Sxy150489 */
335779Sxy150489 static int
igb_update_stats(kstat_t * ks,int rw)345779Sxy150489 igb_update_stats(kstat_t *ks, int rw)
355779Sxy150489 {
365779Sxy150489 igb_t *igb;
375779Sxy150489 struct e1000_hw *hw;
385779Sxy150489 igb_stat_t *igb_ks;
395779Sxy150489 uint32_t val_low, val_high;
405779Sxy150489 #ifdef IGB_DEBUG
415779Sxy150489 int i;
425779Sxy150489 #endif
435779Sxy150489
445779Sxy150489 if (rw == KSTAT_WRITE)
455779Sxy150489 return (EACCES);
465779Sxy150489
475779Sxy150489 igb = (igb_t *)ks->ks_private;
485779Sxy150489 igb_ks = (igb_stat_t *)ks->ks_data;
495779Sxy150489 hw = &igb->hw;
505779Sxy150489
515779Sxy150489 mutex_enter(&igb->gen_lock);
525779Sxy150489
535779Sxy150489 /*
545779Sxy150489 * Basic information.
555779Sxy150489 */
565779Sxy150489 igb_ks->link_speed.value.ui64 = igb->link_speed;
578955SChenlu.Chen@Sun.COM igb_ks->reset_count.value.ui64 = igb->reset_count;
588955SChenlu.Chen@Sun.COM igb_ks->dout_sync.value.ui64 = igb->dout_sync;
595779Sxy150489
605779Sxy150489 #ifdef IGB_DEBUG
615779Sxy150489 igb_ks->rx_frame_error.value.ui64 = 0;
625779Sxy150489 igb_ks->rx_cksum_error.value.ui64 = 0;
635779Sxy150489 igb_ks->rx_exceed_pkt.value.ui64 = 0;
645779Sxy150489 for (i = 0; i < igb->num_rx_rings; i++) {
655779Sxy150489 igb_ks->rx_frame_error.value.ui64 +=
665779Sxy150489 igb->rx_rings[i].stat_frame_error;
675779Sxy150489 igb_ks->rx_cksum_error.value.ui64 +=
685779Sxy150489 igb->rx_rings[i].stat_cksum_error;
695779Sxy150489 igb_ks->rx_exceed_pkt.value.ui64 +=
705779Sxy150489 igb->rx_rings[i].stat_exceed_pkt;
715779Sxy150489 }
725779Sxy150489
735779Sxy150489 igb_ks->tx_overload.value.ui64 = 0;
745779Sxy150489 igb_ks->tx_fail_no_tbd.value.ui64 = 0;
755779Sxy150489 igb_ks->tx_fail_no_tcb.value.ui64 = 0;
765779Sxy150489 igb_ks->tx_fail_dma_bind.value.ui64 = 0;
775779Sxy150489 igb_ks->tx_reschedule.value.ui64 = 0;
785779Sxy150489 for (i = 0; i < igb->num_tx_rings; i++) {
795779Sxy150489 igb_ks->tx_overload.value.ui64 +=
805779Sxy150489 igb->tx_rings[i].stat_overload;
815779Sxy150489 igb_ks->tx_fail_no_tbd.value.ui64 +=
825779Sxy150489 igb->tx_rings[i].stat_fail_no_tbd;
835779Sxy150489 igb_ks->tx_fail_no_tcb.value.ui64 +=
845779Sxy150489 igb->tx_rings[i].stat_fail_no_tcb;
855779Sxy150489 igb_ks->tx_fail_dma_bind.value.ui64 +=
865779Sxy150489 igb->tx_rings[i].stat_fail_dma_bind;
875779Sxy150489 igb_ks->tx_reschedule.value.ui64 +=
885779Sxy150489 igb->tx_rings[i].stat_reschedule;
895779Sxy150489 }
905779Sxy150489
915779Sxy150489 /*
925779Sxy150489 * Hardware calculated statistics.
935779Sxy150489 */
945779Sxy150489 igb_ks->gprc.value.ul += E1000_READ_REG(hw, E1000_GPRC);
955779Sxy150489 igb_ks->gptc.value.ul += E1000_READ_REG(hw, E1000_GPTC);
965779Sxy150489 igb_ks->prc64.value.ul += E1000_READ_REG(hw, E1000_PRC64);
975779Sxy150489 igb_ks->prc127.value.ul += E1000_READ_REG(hw, E1000_PRC127);
985779Sxy150489 igb_ks->prc255.value.ul += E1000_READ_REG(hw, E1000_PRC255);
995779Sxy150489 igb_ks->prc511.value.ul += E1000_READ_REG(hw, E1000_PRC511);
1005779Sxy150489 igb_ks->prc1023.value.ul += E1000_READ_REG(hw, E1000_PRC1023);
1015779Sxy150489 igb_ks->prc1522.value.ul += E1000_READ_REG(hw, E1000_PRC1522);
1025779Sxy150489 igb_ks->ptc64.value.ul += E1000_READ_REG(hw, E1000_PTC64);
1035779Sxy150489 igb_ks->ptc127.value.ul += E1000_READ_REG(hw, E1000_PTC127);
1045779Sxy150489 igb_ks->ptc255.value.ul += E1000_READ_REG(hw, E1000_PTC255);
1055779Sxy150489 igb_ks->ptc511.value.ul += E1000_READ_REG(hw, E1000_PTC511);
1065779Sxy150489 igb_ks->ptc1023.value.ul += E1000_READ_REG(hw, E1000_PTC1023);
1075779Sxy150489 igb_ks->ptc1522.value.ul += E1000_READ_REG(hw, E1000_PTC1522);
1085779Sxy150489
1095779Sxy150489 /*
1105779Sxy150489 * The 64-bit register will reset whenever the upper
1115779Sxy150489 * 32 bits are read. So we need to read the lower
1125779Sxy150489 * 32 bits first, then read the upper 32 bits.
1135779Sxy150489 */
1145779Sxy150489 val_low = E1000_READ_REG(hw, E1000_GORCL);
1155779Sxy150489 val_high = E1000_READ_REG(hw, E1000_GORCH);
1165779Sxy150489 igb_ks->gor.value.ui64 += (uint64_t)val_high << 32 | (uint64_t)val_low;
1175779Sxy150489
1185779Sxy150489 val_low = E1000_READ_REG(hw, E1000_GOTCL);
1195779Sxy150489 val_high = E1000_READ_REG(hw, E1000_GOTCH);
1205779Sxy150489 igb_ks->got.value.ui64 += (uint64_t)val_high << 32 | (uint64_t)val_low;
1215779Sxy150489 #endif
1225779Sxy150489
1235779Sxy150489 igb_ks->symerrs.value.ui64 += E1000_READ_REG(hw, E1000_SYMERRS);
1245779Sxy150489 igb_ks->mpc.value.ui64 += E1000_READ_REG(hw, E1000_MPC);
1255779Sxy150489 igb_ks->rlec.value.ui64 += E1000_READ_REG(hw, E1000_RLEC);
1265779Sxy150489 igb_ks->fcruc.value.ui64 += E1000_READ_REG(hw, E1000_FCRUC);
1275779Sxy150489 igb_ks->rfc.value.ul += E1000_READ_REG(hw, E1000_RFC);
1285779Sxy150489 igb_ks->tncrs.value.ul += E1000_READ_REG(hw, E1000_TNCRS);
1295779Sxy150489 igb_ks->tsctc.value.ul += E1000_READ_REG(hw, E1000_TSCTC);
1305779Sxy150489 igb_ks->tsctfc.value.ul += E1000_READ_REG(hw, E1000_TSCTFC);
1315779Sxy150489 igb_ks->xonrxc.value.ui64 += E1000_READ_REG(hw, E1000_XONRXC);
1325779Sxy150489 igb_ks->xontxc.value.ui64 += E1000_READ_REG(hw, E1000_XONTXC);
1335779Sxy150489 igb_ks->xoffrxc.value.ui64 += E1000_READ_REG(hw, E1000_XOFFRXC);
1345779Sxy150489 igb_ks->xofftxc.value.ui64 += E1000_READ_REG(hw, E1000_XOFFTXC);
1355779Sxy150489
1365779Sxy150489 mutex_exit(&igb->gen_lock);
1375779Sxy150489
13811367SJason.Xu@Sun.COM if (igb_check_acc_handle(igb->osdep.reg_handle) != DDI_FM_OK) {
13911367SJason.Xu@Sun.COM ddi_fm_service_impact(igb->dip, DDI_SERVICE_DEGRADED);
14011367SJason.Xu@Sun.COM return (EIO);
14111367SJason.Xu@Sun.COM }
1426624Sgl147354
1435779Sxy150489 return (0);
1445779Sxy150489 }
1455779Sxy150489
1465779Sxy150489 /*
1475779Sxy150489 * Create and initialize the driver private statistics.
1485779Sxy150489 */
1495779Sxy150489 int
igb_init_stats(igb_t * igb)1505779Sxy150489 igb_init_stats(igb_t *igb)
1515779Sxy150489 {
1525779Sxy150489 kstat_t *ks;
1535779Sxy150489 igb_stat_t *igb_ks;
1545779Sxy150489
1555779Sxy150489 /*
1565779Sxy150489 * Create and init kstat
1575779Sxy150489 */
1585779Sxy150489 ks = kstat_create(MODULE_NAME, ddi_get_instance(igb->dip),
1595779Sxy150489 "statistics", "net", KSTAT_TYPE_NAMED,
1605779Sxy150489 sizeof (igb_stat_t) / sizeof (kstat_named_t), 0);
1615779Sxy150489
1625779Sxy150489 if (ks == NULL) {
1635779Sxy150489 igb_error(igb,
1645779Sxy150489 "Could not create kernel statistics");
1655779Sxy150489 return (IGB_FAILURE);
1665779Sxy150489 }
1675779Sxy150489
1685779Sxy150489 igb->igb_ks = ks;
1695779Sxy150489
1705779Sxy150489 igb_ks = (igb_stat_t *)ks->ks_data;
1715779Sxy150489
1725779Sxy150489 /*
1735779Sxy150489 * Initialize all the statistics.
1745779Sxy150489 */
1755779Sxy150489 kstat_named_init(&igb_ks->link_speed, "link_speed",
1765779Sxy150489 KSTAT_DATA_UINT64);
1778955SChenlu.Chen@Sun.COM kstat_named_init(&igb_ks->reset_count, "reset_count",
1788955SChenlu.Chen@Sun.COM KSTAT_DATA_UINT64);
1798955SChenlu.Chen@Sun.COM kstat_named_init(&igb_ks->dout_sync, "DMA_out_sync",
1808955SChenlu.Chen@Sun.COM KSTAT_DATA_UINT64);
1815779Sxy150489
1825779Sxy150489 #ifdef IGB_DEBUG
1835779Sxy150489 kstat_named_init(&igb_ks->rx_frame_error, "rx_frame_error",
1845779Sxy150489 KSTAT_DATA_UINT64);
1855779Sxy150489 kstat_named_init(&igb_ks->rx_cksum_error, "rx_cksum_error",
1865779Sxy150489 KSTAT_DATA_UINT64);
1875779Sxy150489 kstat_named_init(&igb_ks->rx_exceed_pkt, "rx_exceed_pkt",
1885779Sxy150489 KSTAT_DATA_UINT64);
1895779Sxy150489 kstat_named_init(&igb_ks->tx_overload, "tx_overload",
1905779Sxy150489 KSTAT_DATA_UINT64);
1915779Sxy150489 kstat_named_init(&igb_ks->tx_fail_no_tbd, "tx_fail_no_tbd",
1925779Sxy150489 KSTAT_DATA_UINT64);
1935779Sxy150489 kstat_named_init(&igb_ks->tx_fail_no_tcb, "tx_fail_no_tcb",
1945779Sxy150489 KSTAT_DATA_UINT64);
1955779Sxy150489 kstat_named_init(&igb_ks->tx_fail_dma_bind, "tx_fail_dma_bind",
1965779Sxy150489 KSTAT_DATA_UINT64);
1975779Sxy150489 kstat_named_init(&igb_ks->tx_reschedule, "tx_reschedule",
1985779Sxy150489 KSTAT_DATA_UINT64);
1995779Sxy150489
2005779Sxy150489 kstat_named_init(&igb_ks->gprc, "good_pkts_recvd",
2015779Sxy150489 KSTAT_DATA_UINT64);
2025779Sxy150489 kstat_named_init(&igb_ks->gptc, "good_pkts_xmitd",
2035779Sxy150489 KSTAT_DATA_UINT64);
2045779Sxy150489 kstat_named_init(&igb_ks->gor, "good_octets_recvd",
2055779Sxy150489 KSTAT_DATA_UINT64);
2065779Sxy150489 kstat_named_init(&igb_ks->got, "good_octets_xmitd",
2075779Sxy150489 KSTAT_DATA_UINT64);
2085779Sxy150489 kstat_named_init(&igb_ks->prc64, "pkts_recvd_( 64b)",
2095779Sxy150489 KSTAT_DATA_UINT64);
2105779Sxy150489 kstat_named_init(&igb_ks->prc127, "pkts_recvd_( 65- 127b)",
2115779Sxy150489 KSTAT_DATA_UINT64);
2125779Sxy150489 kstat_named_init(&igb_ks->prc255, "pkts_recvd_( 127- 255b)",
2135779Sxy150489 KSTAT_DATA_UINT64);
2145779Sxy150489 kstat_named_init(&igb_ks->prc511, "pkts_recvd_( 256- 511b)",
2155779Sxy150489 KSTAT_DATA_UINT64);
2165779Sxy150489 kstat_named_init(&igb_ks->prc1023, "pkts_recvd_( 511-1023b)",
2175779Sxy150489 KSTAT_DATA_UINT64);
2185779Sxy150489 kstat_named_init(&igb_ks->prc1522, "pkts_recvd_(1024-1522b)",
2195779Sxy150489 KSTAT_DATA_UINT64);
2205779Sxy150489 kstat_named_init(&igb_ks->ptc64, "pkts_xmitd_( 64b)",
2215779Sxy150489 KSTAT_DATA_UINT64);
2225779Sxy150489 kstat_named_init(&igb_ks->ptc127, "pkts_xmitd_( 65- 127b)",
2235779Sxy150489 KSTAT_DATA_UINT64);
2245779Sxy150489 kstat_named_init(&igb_ks->ptc255, "pkts_xmitd_( 128- 255b)",
2255779Sxy150489 KSTAT_DATA_UINT64);
2265779Sxy150489 kstat_named_init(&igb_ks->ptc511, "pkts_xmitd_( 255- 511b)",
2275779Sxy150489 KSTAT_DATA_UINT64);
2285779Sxy150489 kstat_named_init(&igb_ks->ptc1023, "pkts_xmitd_( 512-1023b)",
2295779Sxy150489 KSTAT_DATA_UINT64);
2305779Sxy150489 kstat_named_init(&igb_ks->ptc1522, "pkts_xmitd_(1024-1522b)",
2315779Sxy150489 KSTAT_DATA_UINT64);
2325779Sxy150489 #endif
2335779Sxy150489
2345779Sxy150489 kstat_named_init(&igb_ks->symerrs, "recv_symbol_errors",
2355779Sxy150489 KSTAT_DATA_UINT64);
2365779Sxy150489 kstat_named_init(&igb_ks->mpc, "recv_missed_packets",
2375779Sxy150489 KSTAT_DATA_UINT64);
2385779Sxy150489 kstat_named_init(&igb_ks->rlec, "recv_length_errors",
2395779Sxy150489 KSTAT_DATA_UINT64);
2405779Sxy150489 kstat_named_init(&igb_ks->fcruc, "recv_unsupport_FC_pkts",
2415779Sxy150489 KSTAT_DATA_UINT64);
2425779Sxy150489 kstat_named_init(&igb_ks->rfc, "recv_frag",
2435779Sxy150489 KSTAT_DATA_UINT64);
2445779Sxy150489 kstat_named_init(&igb_ks->tncrs, "xmit_with_no_CRS",
2455779Sxy150489 KSTAT_DATA_UINT64);
2465779Sxy150489 kstat_named_init(&igb_ks->tsctc, "xmit_TCP_seg_contexts",
2475779Sxy150489 KSTAT_DATA_UINT64);
2485779Sxy150489 kstat_named_init(&igb_ks->tsctfc, "xmit_TCP_seg_contexts_fail",
2495779Sxy150489 KSTAT_DATA_UINT64);
2505779Sxy150489 kstat_named_init(&igb_ks->xonrxc, "XONs_recvd",
2515779Sxy150489 KSTAT_DATA_UINT64);
2525779Sxy150489 kstat_named_init(&igb_ks->xontxc, "XONs_xmitd",
2535779Sxy150489 KSTAT_DATA_UINT64);
2545779Sxy150489 kstat_named_init(&igb_ks->xoffrxc, "XOFFs_recvd",
2555779Sxy150489 KSTAT_DATA_UINT64);
2565779Sxy150489 kstat_named_init(&igb_ks->xofftxc, "XOFFs_xmitd",
2575779Sxy150489 KSTAT_DATA_UINT64);
2585779Sxy150489
2595779Sxy150489 /*
2605779Sxy150489 * Function to provide kernel stat update on demand
2615779Sxy150489 */
2625779Sxy150489 ks->ks_update = igb_update_stats;
2635779Sxy150489
2645779Sxy150489 ks->ks_private = (void *)igb;
2655779Sxy150489
2665779Sxy150489 /*
2675779Sxy150489 * Add kstat to systems kstat chain
2685779Sxy150489 */
2695779Sxy150489 kstat_install(ks);
2705779Sxy150489
2715779Sxy150489 return (IGB_SUCCESS);
2725779Sxy150489 }
273*11878SVenu.Iyer@Sun.COM
274*11878SVenu.Iyer@Sun.COM /*
275*11878SVenu.Iyer@Sun.COM * Retrieve a value for one of the statistics for a particular rx ring
276*11878SVenu.Iyer@Sun.COM */
277*11878SVenu.Iyer@Sun.COM int
igb_rx_ring_stat(mac_ring_driver_t rh,uint_t stat,uint64_t * val)278*11878SVenu.Iyer@Sun.COM igb_rx_ring_stat(mac_ring_driver_t rh, uint_t stat, uint64_t *val)
279*11878SVenu.Iyer@Sun.COM {
280*11878SVenu.Iyer@Sun.COM igb_rx_ring_t *rx_ring = (igb_rx_ring_t *)rh;
281*11878SVenu.Iyer@Sun.COM
282*11878SVenu.Iyer@Sun.COM switch (stat) {
283*11878SVenu.Iyer@Sun.COM case MAC_STAT_RBYTES:
284*11878SVenu.Iyer@Sun.COM *val = rx_ring->rx_bytes;
285*11878SVenu.Iyer@Sun.COM break;
286*11878SVenu.Iyer@Sun.COM
287*11878SVenu.Iyer@Sun.COM case MAC_STAT_IPACKETS:
288*11878SVenu.Iyer@Sun.COM *val = rx_ring->rx_pkts;
289*11878SVenu.Iyer@Sun.COM break;
290*11878SVenu.Iyer@Sun.COM
291*11878SVenu.Iyer@Sun.COM default:
292*11878SVenu.Iyer@Sun.COM *val = 0;
293*11878SVenu.Iyer@Sun.COM return (ENOTSUP);
294*11878SVenu.Iyer@Sun.COM }
295*11878SVenu.Iyer@Sun.COM
296*11878SVenu.Iyer@Sun.COM return (0);
297*11878SVenu.Iyer@Sun.COM }
298*11878SVenu.Iyer@Sun.COM
299*11878SVenu.Iyer@Sun.COM /*
300*11878SVenu.Iyer@Sun.COM * Retrieve a value for one of the statistics for a particular tx ring
301*11878SVenu.Iyer@Sun.COM */
302*11878SVenu.Iyer@Sun.COM int
igb_tx_ring_stat(mac_ring_driver_t rh,uint_t stat,uint64_t * val)303*11878SVenu.Iyer@Sun.COM igb_tx_ring_stat(mac_ring_driver_t rh, uint_t stat, uint64_t *val)
304*11878SVenu.Iyer@Sun.COM {
305*11878SVenu.Iyer@Sun.COM igb_tx_ring_t *tx_ring = (igb_tx_ring_t *)rh;
306*11878SVenu.Iyer@Sun.COM
307*11878SVenu.Iyer@Sun.COM switch (stat) {
308*11878SVenu.Iyer@Sun.COM case MAC_STAT_OBYTES:
309*11878SVenu.Iyer@Sun.COM *val = tx_ring->tx_bytes;
310*11878SVenu.Iyer@Sun.COM break;
311*11878SVenu.Iyer@Sun.COM
312*11878SVenu.Iyer@Sun.COM case MAC_STAT_OPACKETS:
313*11878SVenu.Iyer@Sun.COM *val = tx_ring->tx_pkts;
314*11878SVenu.Iyer@Sun.COM break;
315*11878SVenu.Iyer@Sun.COM
316*11878SVenu.Iyer@Sun.COM default:
317*11878SVenu.Iyer@Sun.COM *val = 0;
318*11878SVenu.Iyer@Sun.COM return (ENOTSUP);
319*11878SVenu.Iyer@Sun.COM }
320*11878SVenu.Iyer@Sun.COM
321*11878SVenu.Iyer@Sun.COM return (0);
322*11878SVenu.Iyer@Sun.COM }
323