nic3com.c 3.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * This file is part of the flashrom project.
 *
 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <stdlib.h>
#include <string.h>
23 24 25
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
26 27 28 29 30 31
#include <errno.h>
#include "flash.h"

#define BIOS_ROM_ADDR		0x04
#define BIOS_ROM_DATA		0x08
#define INT_STATUS		0x0e
32
#define INTERNAL_CONFIG		0x00
33 34 35 36
#define SELECT_REG_WINDOW	0x800

#define PCI_VENDOR_ID_3COM	0x10b7

37 38 39
uint32_t internal_conf;
uint16_t id;

40
struct pcidev_status nics_3com[] = {
41
	/* 3C90xB */
42
	{0x10b7, 0x9055, PCI_OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
43 44 45 46 47 48
	{0x10b7, 0x9001, PCI_NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
	{0x10b7, 0x9004, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T (TPO)" },
	{0x10b7, 0x9005, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
	{0x10b7, 0x9006, PCI_NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
	{0x10b7, 0x900a, PCI_NT, "3COM", "3C90xB: PCI 10BASE-FL" },
	{0x10b7, 0x905a, PCI_NT, "3COM", "3C90xB: PCI 10BASE-FX" },
49 50

	/* 3C905C */
51
	{0x10b7, 0x9200, PCI_OK, "3COM", "3C905C: EtherLink 10/100 PCI (TX)" },
52 53

	/* 3C980C */
54
	{0x10b7, 0x9805, PCI_NT, "3COM", "3C980C: EtherLink Server 10/100 PCI (TX)" },
55 56 57 58 59 60

	{},
};

int nic3com_init(void)
{
61
	get_io_perms();
62

63
	io_base_addr = pcidev_init(PCI_VENDOR_ID_3COM, nics_3com);
64 65 66 67 68 69 70 71 72 73 74 75
	id = pcidev_dev->device_id;

	/* 3COM 3C90xB cards need a special fixup. */
	if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
	    || id == 0x9006 || id == 0x900a || id == 0x905a) {
		/* Select register window 3 and save the receiver status. */
		OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
		internal_conf = INL(io_base_addr + INTERNAL_CONFIG);

		/* Set receiver type to MII for full BIOS ROM access. */
		OUTL((internal_conf & 0xf00fffff) | 0x00600000, io_base_addr);
	}
76 77 78 79 80 81 82 83

	/*
	 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
	 * cards form a 'register window' into one of multiple (usually 8)
	 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
	 */
	OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);

84 85
	buses_supported = CHIP_BUSTYPE_PARALLEL;

86 87 88 89 90
	return 0;
}

int nic3com_shutdown(void)
{
91 92 93 94 95 96 97 98
	/* 3COM 3C90xB cards need a special fixup. */
	if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
	    || id == 0x9006 || id == 0x900a || id == 0x905a) {
		/* Select register window 3 and restore the receiver status. */
		OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
		OUTL(internal_conf, io_base_addr + INTERNAL_CONFIG);
	}

99
	free(pcidev_bdf);
100
	pci_cleanup(pacc);
101 102 103
#if defined(__FreeBSD__) || defined(__DragonFly__)
	close(io_fd);
#endif
104 105 106
	return 0;
}

107
void nic3com_chip_writeb(uint8_t val, chipaddr addr)
108
{
109
	OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
110 111 112
	OUTB(val, io_base_addr + BIOS_ROM_DATA);
}

113
uint8_t nic3com_chip_readb(const chipaddr addr)
114
{
115
	OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
116
	return INB(io_base_addr + BIOS_ROM_DATA);
117
}