mii_verbose.c revision 1.5
11.5Smsaitoh/*	$NetBSD: mii_verbose.c,v 1.5 2019/03/25 07:34:13 msaitoh Exp $ */
21.1Spgoyette
31.1Spgoyette/*-
41.1Spgoyette * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
51.1Spgoyette * All rights reserved.
61.1Spgoyette *
71.1Spgoyette * This code is derived from software contributed to The NetBSD Foundation
81.1Spgoyette * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
91.1Spgoyette * NASA Ames Research Center, and by Frank van der Linden.
101.1Spgoyette *
111.1Spgoyette * Redistribution and use in source and binary forms, with or without
121.1Spgoyette * modification, are permitted provided that the following conditions
131.1Spgoyette * are met:
141.1Spgoyette * 1. Redistributions of source code must retain the above copyright
151.1Spgoyette *    notice, this list of conditions and the following disclaimer.
161.1Spgoyette * 2. Redistributions in binary form must reproduce the above copyright
171.1Spgoyette *    notice, this list of conditions and the following disclaimer in the
181.1Spgoyette *    documentation and/or other materials provided with the distribution.
191.1Spgoyette *
201.1Spgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
211.1Spgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
221.1Spgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
231.1Spgoyette * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
241.1Spgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
251.1Spgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
261.1Spgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271.1Spgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
281.1Spgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
291.1Spgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
301.1Spgoyette * POSSIBILITY OF SUCH DAMAGE.
311.1Spgoyette */
321.1Spgoyette
331.1Spgoyette/*
341.1Spgoyette * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
351.1Spgoyette *
361.1Spgoyette * Redistribution and use in source and binary forms, with or without
371.1Spgoyette * modification, are permitted provided that the following conditions
381.1Spgoyette * are met:
391.1Spgoyette * 1. Redistributions of source code must retain the above copyright
401.1Spgoyette *    notice, this list of conditions and the following disclaimer.
411.1Spgoyette * 2. Redistributions in binary form must reproduce the above copyright
421.1Spgoyette *    notice, this list of conditions and the following disclaimer in the
431.1Spgoyette *    documentation and/or other materials provided with the distribution.
441.1Spgoyette *
451.1Spgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
461.1Spgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
471.1Spgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
481.1Spgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
491.1Spgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
501.1Spgoyette * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
511.1Spgoyette * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
521.1Spgoyette * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
531.1Spgoyette * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
541.1Spgoyette * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
551.1Spgoyette */
561.1Spgoyette
571.1Spgoyette#include <sys/cdefs.h>
581.5Smsaitoh__KERNEL_RCSID(0, "$NetBSD: mii_verbose.c,v 1.5 2019/03/25 07:34:13 msaitoh Exp $");
591.1Spgoyette
601.1Spgoyette#include <sys/module.h>
611.5Smsaitoh#include <dev/mii/miidevs.h>
621.5Smsaitoh#include <dev/mii/miidevs_data.h>
631.1Spgoyette#include <dev/mii/mii_verbose.h>
641.1Spgoyette
651.1Spgoyettestruct mii_knowndev {
661.1Spgoyette	int oui;
671.1Spgoyette	int model;
681.1Spgoyette	const char *descr;
691.1Spgoyette};
701.1Spgoyette
711.1Spgoyetteconst char * mii_get_descr_real(int, int);
721.1Spgoyette
731.1SpgoyetteMODULE(MODULE_CLASS_MISC, miiverbose, NULL);
741.1Spgoyette
751.1Spgoyettestatic int
761.1Spgoyettemiiverbose_modcmd(modcmd_t cmd, void *arg)
771.1Spgoyette{
781.2Spgoyette	static const char *(*saved_mii_get_descr)(int, int);
791.2Spgoyette
801.1Spgoyette	switch (cmd) {
811.1Spgoyette	case MODULE_CMD_INIT:
821.2Spgoyette		saved_mii_get_descr = mii_get_descr;
831.1Spgoyette		mii_get_descr = mii_get_descr_real;
841.3Spgoyette		mii_verbose_loaded = 1;
851.1Spgoyette		return 0;
861.1Spgoyette	case MODULE_CMD_FINI:
871.2Spgoyette		mii_get_descr = saved_mii_get_descr;
881.2Spgoyette		mii_verbose_loaded = 0;
891.1Spgoyette		return 0;
901.1Spgoyette	default:
911.1Spgoyette		return ENOTTY;
921.1Spgoyette	}
931.4Smsaitoh}
941.1Spgoyette
951.1Spgoyetteconst char *
961.5Smsaitohmii_get_descr_real(int oui, int model)
971.5Smsaitoh{
981.1Spgoyette	int i;
991.1Spgoyette
1001.1Spgoyette	for (i = 0; mii_knowndevs[i].descr != NULL; i++)
1011.1Spgoyette		if (mii_knowndevs[i].oui == oui &&
1021.1Spgoyette		    mii_knowndevs[i].model == model)
1031.1Spgoyette			break;
1041.5Smsaitoh	return mii_knowndevs[i].descr;
1051.1Spgoyette}
106