blob: 4240122bac314e021a3235809714dfdbc131eeef [file] [log] [blame]
Uwe Hermannb4dcb712009-05-13 11:36:06 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Uwe Hermannb4dcb712009-05-13 11:36:06 +000015 */
16
17#include <stdlib.h>
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000018#include "programmer.h"
Thomas Heijligena0655202021-12-14 16:36:05 +010019#include "hwaccess_x86_io.h"
Thomas Heijligend96c97c2021-11-02 21:03:00 +010020#include "platform/pci.h"
Uwe Hermannb4dcb712009-05-13 11:36:06 +000021
22#define BIOS_ROM_ADDR 0x04
23#define BIOS_ROM_DATA 0x08
24#define INT_STATUS 0x0e
Uwe Hermann8403ccb2009-05-16 21:39:19 +000025#define INTERNAL_CONFIG 0x00
Uwe Hermannb4dcb712009-05-13 11:36:06 +000026#define SELECT_REG_WINDOW 0x800
27
Uwe Hermannb4dcb712009-05-13 11:36:06 +000028#define PCI_VENDOR_ID_3COM 0x10b7
29
Stefan Tauner0ccec8f2014-06-01 23:49:03 +000030static uint32_t io_base_addr = 0;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000031static uint32_t internal_conf;
32static uint16_t id;
Uwe Hermann8403ccb2009-05-16 21:39:19 +000033
Thomas Heijligencc853d82021-05-04 15:32:17 +020034static const struct dev_entry nics_3com[] = {
Uwe Hermannb4dcb712009-05-13 11:36:06 +000035 /* 3C90xB */
Michael Karcher84486392010-02-24 00:04:40 +000036 {0x10b7, 0x9055, OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
37 {0x10b7, 0x9001, NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
38 {0x10b7, 0x9004, OK, "3COM", "3C90xB: PCI 10BASE-T (TPO)" },
39 {0x10b7, 0x9005, NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
Adrien Destuguesd42f1f62021-08-10 11:48:18 +020040 {0x10b7, 0x9006, OK, "3COM", "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
Michael Karcher84486392010-02-24 00:04:40 +000041 {0x10b7, 0x900a, NT, "3COM", "3C90xB: PCI 10BASE-FL" },
42 {0x10b7, 0x905a, NT, "3COM", "3C90xB: PCI 10BASE-FX" },
43 {0x10b7, 0x9058, OK, "3COM", "3C905B: Cyclone 10/100/BNC" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000044
45 /* 3C905C */
Michael Karcher84486392010-02-24 00:04:40 +000046 {0x10b7, 0x9200, OK, "3COM", "3C905C: EtherLink 10/100 PCI (TX)" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000047
48 /* 3C980C */
Michael Karcher84486392010-02-24 00:04:40 +000049 {0x10b7, 0x9805, NT, "3COM", "3C980C: EtherLink Server 10/100 PCI (TX)" },
Uwe Hermannb4dcb712009-05-13 11:36:06 +000050
Carl-Daniel Hailfinger1c6d2ff2012-08-27 00:44:42 +000051 {0},
Uwe Hermannb4dcb712009-05-13 11:36:06 +000052};
53
Nico Huberdd6e07a2026-02-21 17:55:26 +010054static void nic3com_chip_writeb(const struct par_master *, uint8_t val, chipaddr);
55static uint8_t nic3com_chip_readb(const struct par_master *, chipaddr);
Anastasia Klimchukd66dded2021-08-27 15:42:46 +100056static int nic3com_shutdown(void *data);
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000057static const struct par_master par_master_nic3com = {
Thomas Heijligen43040f22022-06-23 14:38:35 +020058 .chip_readb = nic3com_chip_readb,
59 .chip_readw = fallback_chip_readw,
60 .chip_readl = fallback_chip_readl,
61 .chip_readn = fallback_chip_readn,
62 .chip_writeb = nic3com_chip_writeb,
63 .chip_writew = fallback_chip_writew,
64 .chip_writel = fallback_chip_writel,
65 .chip_writen = fallback_chip_writen,
Anastasia Klimchukd66dded2021-08-27 15:42:46 +100066 .shutdown = nic3com_shutdown,
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000067};
68
David Hendricks8bb20212011-06-14 01:35:36 +000069static int nic3com_shutdown(void *data)
70{
71 /* 3COM 3C90xB cards need a special fixup. */
72 if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
73 || id == 0x9006 || id == 0x900a || id == 0x905a || id == 0x9058) {
74 /* Select register window 3 and restore the receiver status. */
75 OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
76 OUTL(internal_conf, io_base_addr + INTERNAL_CONFIG);
77 }
78
David Hendricks8bb20212011-06-14 01:35:36 +000079 return 0;
80}
81
Nico Hubere3a26882023-01-11 21:45:51 +010082static int nic3com_init(struct flashprog_programmer *const prog)
Uwe Hermannb4dcb712009-05-13 11:36:06 +000083{
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000084 struct pci_dev *dev = NULL;
85
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +000086 if (rget_io_perms())
87 return 1;
Uwe Hermannb4dcb712009-05-13 11:36:06 +000088
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000089 dev = pcidev_init(nics_3com, PCI_BASE_ADDRESS_0);
90 if (!dev)
91 return 1;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000092
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000093 io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
Niklas Söderlund89edf362013-08-23 23:29:23 +000094 if (!io_base_addr)
95 return 1;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +000096
97 id = dev->device_id;
Uwe Hermann8403ccb2009-05-16 21:39:19 +000098
99 /* 3COM 3C90xB cards need a special fixup. */
100 if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
Maciej Pijankabc2bbd22009-06-02 16:45:59 +0000101 || id == 0x9006 || id == 0x900a || id == 0x905a || id == 0x9058) {
Uwe Hermann8403ccb2009-05-16 21:39:19 +0000102 /* Select register window 3 and save the receiver status. */
103 OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
104 internal_conf = INL(io_base_addr + INTERNAL_CONFIG);
105
106 /* Set receiver type to MII for full BIOS ROM access. */
107 OUTL((internal_conf & 0xf00fffff) | 0x00600000, io_base_addr);
108 }
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000109
110 /*
111 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
112 * cards form a 'register window' into one of multiple (usually 8)
113 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
114 */
115 OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
116
Nico Huber47aa85c2026-02-21 14:57:20 +0100117 return register_par_master(&par_master_nic3com, BUS_PARALLEL, 0, 128*KiB, NULL);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000118}
119
Nico Huberdd6e07a2026-02-21 17:55:26 +0100120static void nic3com_chip_writeb(const struct par_master *par, uint8_t val, chipaddr addr)
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000121{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000122 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000123 OUTB(val, io_base_addr + BIOS_ROM_DATA);
124}
125
Nico Huberdd6e07a2026-02-21 17:55:26 +0100126static uint8_t nic3com_chip_readb(const struct par_master *par, const chipaddr addr)
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000127{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000128 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
Uwe Hermannc7e8a0c2009-05-19 14:14:21 +0000129 return INB(io_base_addr + BIOS_ROM_DATA);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000130}
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +0000131
Thomas Heijligencc853d82021-05-04 15:32:17 +0200132const struct programmer_entry programmer_nic3com = {
133 .name = "nic3com",
134 .type = PCI,
135 .devs.dev = nics_3com,
136 .init = nic3com_init,
Thomas Heijligencc853d82021-05-04 15:32:17 +0200137};