11.6Syamaguch/*	$NetBSD: ieee8023ad_lacp_timer.c,v 1.6 2021/11/30 01:17:02 yamaguchi Exp $	*/
21.1Syamt
31.1Syamt/*-
41.1Syamt * Copyright (c)2005 YAMAMOTO Takashi,
51.1Syamt * All rights reserved.
61.1Syamt *
71.1Syamt * Redistribution and use in source and binary forms, with or without
81.1Syamt * modification, are permitted provided that the following conditions
91.1Syamt * are met:
101.1Syamt * 1. Redistributions of source code must retain the above copyright
111.1Syamt *    notice, this list of conditions and the following disclaimer.
121.1Syamt * 2. Redistributions in binary form must reproduce the above copyright
131.1Syamt *    notice, this list of conditions and the following disclaimer in the
141.1Syamt *    documentation and/or other materials provided with the distribution.
151.1Syamt *
161.1Syamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171.1Syamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181.1Syamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191.1Syamt * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201.1Syamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211.1Syamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221.1Syamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231.1Syamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241.1Syamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251.1Syamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261.1Syamt * SUCH DAMAGE.
271.1Syamt */
281.1Syamt
291.1Syamt#include <sys/cdefs.h>
301.6Syamaguch__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp_timer.c,v 1.6 2021/11/30 01:17:02 yamaguchi Exp $");
311.1Syamt
321.1Syamt#include <sys/param.h>
331.3Syamt#include <sys/callout.h>
341.1Syamt#include <sys/systm.h>
351.1Syamt
361.1Syamt#include <net/if.h>
371.1Syamt#include <net/if_ether.h>
381.6Syamaguch#include <net/ether_slowprotocols.h>
391.1Syamt
401.1Syamt#include <net/agr/ieee8023_tlv.h>
411.1Syamt#include <net/agr/ieee8023ad_lacp.h>
421.1Syamt#include <net/agr/ieee8023ad_lacp_impl.h>
431.1Syamt#include <net/agr/ieee8023ad_lacp_sm.h>
441.1Syamt
451.2Syamttypedef void (*lacp_timer_func_t)(struct lacp_port *);
461.2Syamt
471.5Suebayasistatic const lacp_timer_func_t lacp_timer_funcs[LACP_NTIMER] = {
481.1Syamt	[LACP_TIMER_CURRENT_WHILE] = lacp_sm_rx_timer,
491.1Syamt	[LACP_TIMER_PERIODIC] = lacp_sm_ptx_timer,
501.1Syamt	[LACP_TIMER_WAIT_WHILE] = lacp_sm_mux_timer,
511.1Syamt};
521.1Syamt
531.1Syamtvoid
541.1Syamtlacp_run_timers(struct lacp_port *lp)
551.1Syamt{
561.1Syamt	int i;
571.1Syamt
581.1Syamt	for (i = 0; i < LACP_NTIMER; i++) {
591.1Syamt		KASSERT(lp->lp_timer[i] >= 0);
601.1Syamt		if (lp->lp_timer[i] == 0) {
611.1Syamt			continue;
621.1Syamt		} else if (--lp->lp_timer[i] <= 0) {
631.1Syamt			if (lacp_timer_funcs[i]) {
641.1Syamt				(*lacp_timer_funcs[i])(lp);
651.1Syamt			}
661.1Syamt		}
671.1Syamt	}
681.1Syamt}
69