xref: /titanic_50/usr/src/uts/common/io/bnxe/bnxe_timer.c (revision 799823bbed51a695d01e13511bbb1369980bb714)
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 2014 QLogic Corporation
24  * The contents of this file are subject to the terms of the
25  * QLogic End User License (the "License").
26  * You may not use this file except in compliance with the License.
27  *
28  * You can obtain a copy of the License at
29  * http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/
30  * QLogic_End_User_Software_License.txt
31  * See the License for the specific language governing permissions
32  * and limitations under the License.
33  */
34 
35 /*
36  * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
37  */
38 
39 #include "bnxe.h"
40 
41 #define BNXE_TIMER_INTERVAL 1000000 /* usecs (once a second for stats) */
42 
43 
44 static void BnxeTimer(void * pArg)
45 {
46     um_device_t * pUM = (um_device_t *)pArg;
47     lm_device_t * pLM = &pUM->lm_dev;
48 
49     BNXE_LOCK_ENTER_TIMER(pUM);
50 
51     if (pUM->timerEnabled != B_TRUE)
52     {
53         BNXE_LOCK_EXIT_TIMER(pUM);
54         return;
55     }
56 
57     lm_stats_on_timer(pLM);
58 
59     if (pUM->fmCapabilities &&
60         BnxeCheckAccHandle(pLM->vars.reg_handle[BAR_0]) != DDI_FM_OK)
61     {
62         ddi_fm_service_impact(pUM->pDev, DDI_SERVICE_UNAFFECTED);
63     }
64 
65     if (pUM->phyInitialized)
66     {
67         BNXE_LOCK_ENTER_PHY(pUM);
68         lm_link_on_timer(pLM);
69         BNXE_LOCK_EXIT_PHY(pUM);
70     }
71 
72     pUM->timerID = timeout(BnxeTimer, (void *)pUM,
73                            drv_usectohz(BNXE_TIMER_INTERVAL));
74 
75     BNXE_LOCK_EXIT_TIMER(pUM);
76 }
77 
78 
79 void BnxeTimerStart(um_device_t * pUM)
80 {
81     atomic_swap_32(&pUM->timerEnabled, B_TRUE);
82 
83     pUM->lm_dev.vars.stats.stats_collect.timer_wakeup = 0; /* reset */
84 
85     pUM->timerID = timeout(BnxeTimer, (void *)pUM,
86                            drv_usectohz(BNXE_TIMER_INTERVAL));
87 }
88 
89 
90 void BnxeTimerStop(um_device_t * pUM)
91 {
92     atomic_swap_32(&pUM->timerEnabled, B_FALSE);
93 
94     BNXE_LOCK_ENTER_TIMER(pUM);
95     BNXE_LOCK_EXIT_TIMER(pUM);
96 
97     untimeout(pUM->timerID);
98     pUM->timerID = 0;
99 }
100 
101