Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
| 5 | * Copyright (C) 2010 Idwer Vollering |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 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. |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
Bill Paul | bf8ea49 | 2014-03-17 22:07:29 +0000 | [diff] [blame] | 18 | * Datasheets: |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 19 | * PCI/PCI-X Family of Gigabit Ethernet Controllers Software Developer's Manual |
| 20 | * 82540EP/EM, 82541xx, 82544GC/EI, 82545GM/EM, 82546GB/EB, and 82547xx |
Bill Paul | bf8ea49 | 2014-03-17 22:07:29 +0000 | [diff] [blame] | 21 | * http://www.intel.com/content/www/us/en/ethernet-controllers/pci-pci-x-family-gbe-controllers-software-dev-manual.html |
| 22 | * |
| 23 | * PCIe GbE Controllers Open Source Software Developer's Manual |
| 24 | * http://www.intel.com/content/www/us/en/ethernet-controllers/pcie-gbe-controllers-open-source-manual.html |
| 25 | * |
| 26 | * Intel 82574 Gigabit Ethernet Controller Family Datasheet |
| 27 | * http://www.intel.com/content/www/us/en/ethernet-controllers/82574l-gbe-controller-datasheet.html |
Ed Swierk | 33180df | 2014-12-05 22:56:13 +0000 | [diff] [blame] | 28 | * |
| 29 | * Intel 82599 10 GbE Controller Datasheet (331520) |
| 30 | * http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82599-10-gbe-controller-datasheet.pdf |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <stdlib.h> |
Stefan Tauner | 6745d6f | 2012-08-26 21:50:36 +0000 | [diff] [blame] | 34 | #include <unistd.h> |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 35 | #include "flash.h" |
| 36 | #include "programmer.h" |
Thomas Heijligen | 74b4aa0 | 2021-12-14 17:52:30 +0100 | [diff] [blame] | 37 | #include "hwaccess_physmap.h" |
Thomas Heijligen | d96c97c | 2021-11-02 21:03:00 +0100 | [diff] [blame] | 38 | #include "platform/pci.h" |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 39 | |
| 40 | #define PCI_VENDOR_ID_INTEL 0x8086 |
Stefan Tauner | 6745d6f | 2012-08-26 21:50:36 +0000 | [diff] [blame] | 41 | #define MEMMAP_SIZE getpagesize() |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 42 | |
Stefan Tauner | 8ee180d | 2012-02-27 19:44:16 +0000 | [diff] [blame] | 43 | /* EEPROM/Flash Control & Data Register */ |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 44 | #define EECD 0x10 |
Stefan Tauner | 8ee180d | 2012-02-27 19:44:16 +0000 | [diff] [blame] | 45 | /* Flash Access Register */ |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 46 | #define FLA 0x1c |
| 47 | |
| 48 | /* |
| 49 | * Register bits of EECD. |
Stefan Tauner | 8ee180d | 2012-02-27 19:44:16 +0000 | [diff] [blame] | 50 | * Table 13-6 |
| 51 | * |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 52 | * Bit 04, 05: FWE (Flash Write Enable Control) |
Ed Swierk | 33180df | 2014-12-05 22:56:13 +0000 | [diff] [blame] | 53 | * 00b = not allowed (on some cards this sends an erase command if bit 31 (FL_ER) of FLA is set) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 54 | * 01b = flash writes disabled |
| 55 | * 10b = flash writes enabled |
| 56 | * 11b = not allowed |
| 57 | */ |
| 58 | #define FLASH_WRITES_DISABLED 0x10 /* FWE: 10000b */ |
| 59 | #define FLASH_WRITES_ENABLED 0x20 /* FWE: 100000b */ |
| 60 | |
Stefan Tauner | 8ee180d | 2012-02-27 19:44:16 +0000 | [diff] [blame] | 61 | /* Flash Access register bits |
| 62 | * Table 13-9 |
| 63 | */ |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 64 | #define FL_SCK 0 |
| 65 | #define FL_CS 1 |
| 66 | #define FL_SI 2 |
| 67 | #define FL_SO 3 |
| 68 | #define FL_REQ 4 |
| 69 | #define FL_GNT 5 |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 70 | #define FL_LOCKED 6 |
| 71 | #define FL_ABORT 7 |
| 72 | #define FL_CLR_ERR 8 |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 73 | /* Currently unused */ |
| 74 | // #define FL_BUSY 30 |
| 75 | // #define FL_ER 31 |
| 76 | |
Jacob Garber | afc3ad6 | 2019-06-24 16:05:28 -0600 | [diff] [blame] | 77 | static uint8_t *nicintel_spibar; |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 78 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 79 | static const struct dev_entry nics_intel_spi[] = { |
Idwer Vollering | bdc4827 | 2010-10-05 11:16:14 +0000 | [diff] [blame] | 80 | {PCI_VENDOR_ID_INTEL, 0x105e, OK, "Intel", "82571EB Gigabit Ethernet Controller"}, |
Stefan Tauner | 4b90e6b | 2011-05-18 01:31:24 +0000 | [diff] [blame] | 81 | {PCI_VENDOR_ID_INTEL, 0x1076, OK, "Intel", "82541GI Gigabit Ethernet Controller"}, |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 82 | {PCI_VENDOR_ID_INTEL, 0x107c, OK, "Intel", "82541PI Gigabit Ethernet Controller"}, |
Idwer Vollering | bdc4827 | 2010-10-05 11:16:14 +0000 | [diff] [blame] | 83 | {PCI_VENDOR_ID_INTEL, 0x10b9, OK, "Intel", "82572EI Gigabit Ethernet Controller"}, |
Bill Paul | bf8ea49 | 2014-03-17 22:07:29 +0000 | [diff] [blame] | 84 | {PCI_VENDOR_ID_INTEL, 0x10d3, OK, "Intel", "82574L Gigabit Ethernet Controller"}, |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 85 | |
Ed Swierk | 33180df | 2014-12-05 22:56:13 +0000 | [diff] [blame] | 86 | {PCI_VENDOR_ID_INTEL, 0x10d8, NT, "Intel", "82599 10 Gigabit Unprogrammed Network Controller"}, |
| 87 | {PCI_VENDOR_ID_INTEL, 0x10f7, NT, "Intel", "82599 10 Gigabit KX4 Dual Port Network Controller"}, |
| 88 | {PCI_VENDOR_ID_INTEL, 0x10f8, NT, "Intel", "82599 10 Gigabit Dual Port Backplane Controller"}, |
| 89 | {PCI_VENDOR_ID_INTEL, 0x10f9, NT, "Intel", "82599 10 Gigabit CX4 Dual Port Network Controller"}, |
| 90 | {PCI_VENDOR_ID_INTEL, 0x10fb, NT, "Intel", "82599 10-Gigabit SFI/SFP+ Network Controller"}, |
| 91 | {PCI_VENDOR_ID_INTEL, 0x10fc, OK, "Intel", "82599 10 Gigabit XAUI/BX4 Dual Port Network Controller"}, |
| 92 | {PCI_VENDOR_ID_INTEL, 0x1517, NT, "Intel", "82599 10 Gigabit KR Network Controller"}, |
| 93 | {PCI_VENDOR_ID_INTEL, 0x151c, NT, "Intel", "82599 10 Gigabit TN Network Controller"}, |
| 94 | {PCI_VENDOR_ID_INTEL, 0x1529, NT, "Intel", "82599 10 Gigabit Dual Port Network Controller with FCoE"}, |
| 95 | {PCI_VENDOR_ID_INTEL, 0x152a, NT, "Intel", "82599 10 Gigabit Dual Port Backplane Controller with FCoE"}, |
| 96 | {PCI_VENDOR_ID_INTEL, 0x1557, NT, "Intel", "82599 10 Gigabit SFI Network Controller"}, |
| 97 | |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 98 | {PCI_VENDOR_ID_INTEL, 0x1531, OK, "Intel", "I210 Gigabit Network Connection Unprogrammed"}, |
| 99 | {PCI_VENDOR_ID_INTEL, 0x1532, NT, "Intel", "I211 Gigabit Network Connection Unprogrammed"}, |
| 100 | {PCI_VENDOR_ID_INTEL, 0x1533, NT, "Intel", "I210 Gigabit Network Connection"}, |
| 101 | {PCI_VENDOR_ID_INTEL, 0x1536, NT, "Intel", "I210 Gigabit Network Connection SERDES Fiber"}, |
| 102 | {PCI_VENDOR_ID_INTEL, 0x1537, NT, "Intel", "I210 Gigabit Network Connection SERDES Backplane"}, |
| 103 | {PCI_VENDOR_ID_INTEL, 0x1538, NT, "Intel", "I210 Gigabit Network Connection SGMII"}, |
| 104 | {PCI_VENDOR_ID_INTEL, 0x1539, NT, "Intel", "I211 Gigabit Network Connection"}, |
| 105 | |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 106 | {0}, |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 109 | static void nicintel_request_spibus(void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 110 | { |
| 111 | uint32_t tmp; |
| 112 | |
| 113 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 114 | tmp |= BIT(FL_REQ); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 115 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 116 | |
| 117 | /* Wait until we are allowed to use the SPI bus. */ |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 118 | while (!(pci_mmio_readl(nicintel_spibar + FLA) & BIT(FL_GNT))) ; |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 121 | static void nicintel_release_spibus(void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 122 | { |
| 123 | uint32_t tmp; |
| 124 | |
| 125 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 126 | tmp &= ~BIT(FL_REQ); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 127 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 128 | } |
| 129 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 130 | static void nicintel_bitbang_set_cs(int val, void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 131 | { |
| 132 | uint32_t tmp; |
| 133 | |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 134 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 135 | tmp &= ~BIT(FL_CS); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 136 | tmp |= (val << FL_CS); |
| 137 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 140 | static void nicintel_bitbang_set_sck(int val, void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 141 | { |
| 142 | uint32_t tmp; |
| 143 | |
| 144 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 145 | tmp &= ~BIT(FL_SCK); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 146 | tmp |= (val << FL_SCK); |
| 147 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 148 | } |
| 149 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 150 | static void nicintel_bitbang_set_mosi(int val, void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 151 | { |
| 152 | uint32_t tmp; |
| 153 | |
| 154 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 155 | tmp &= ~BIT(FL_SI); |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 156 | tmp |= (val << FL_SI); |
| 157 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 158 | } |
| 159 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 160 | static void nicintel_bitbang_set_sck_set_mosi(int sck, int mosi, void *spi_data) |
Angel Pons | f0c03fb | 2021-06-21 13:01:45 +0200 | [diff] [blame] | 161 | { |
| 162 | uint32_t tmp; |
| 163 | |
| 164 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
| 165 | tmp &= ~BIT(FL_SCK); |
| 166 | tmp &= ~BIT(FL_SI); |
| 167 | tmp |= (sck << FL_SCK); |
| 168 | tmp |= (mosi << FL_SI); |
| 169 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 170 | } |
| 171 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 172 | static int nicintel_bitbang_get_miso(void *spi_data) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 173 | { |
| 174 | uint32_t tmp; |
| 175 | |
| 176 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
| 177 | tmp = (tmp >> FL_SO) & 0x1; |
| 178 | return tmp; |
| 179 | } |
| 180 | |
Anastasia Klimchuk | 0e78818 | 2021-05-26 09:54:08 +1000 | [diff] [blame] | 181 | static int nicintel_bitbang_set_sck_get_miso(int sck, void *spi_data) |
Angel Pons | f0c03fb | 2021-06-21 13:01:45 +0200 | [diff] [blame] | 182 | { |
| 183 | uint32_t tmp; |
| 184 | |
| 185 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
| 186 | tmp &= ~BIT(FL_SCK); |
| 187 | tmp |= (sck << FL_SCK); |
| 188 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 189 | return (tmp >> FL_SO) & 0x1; |
| 190 | } |
| 191 | |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 192 | static const struct bitbang_spi_master bitbang_spi_master_nicintel = { |
Thomas Heijligen | 43040f2 | 2022-06-23 14:38:35 +0200 | [diff] [blame] | 193 | .set_cs = nicintel_bitbang_set_cs, |
| 194 | .set_sck = nicintel_bitbang_set_sck, |
| 195 | .set_mosi = nicintel_bitbang_set_mosi, |
| 196 | .set_sck_set_mosi = nicintel_bitbang_set_sck_set_mosi, |
| 197 | .set_sck_get_miso = nicintel_bitbang_set_sck_get_miso, |
| 198 | .get_miso = nicintel_bitbang_get_miso, |
| 199 | .request_bus = nicintel_request_spibus, |
| 200 | .release_bus = nicintel_release_spibus, |
| 201 | .half_period = 1, |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 204 | static int nicintel_spi_shutdown(void *data) |
| 205 | { |
| 206 | uint32_t tmp; |
| 207 | |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 208 | /* Disable writes manually. See the comment about EECD in nicintel_spi_init() for details. */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 209 | tmp = pci_mmio_readl(nicintel_spibar + EECD); |
| 210 | tmp &= ~FLASH_WRITES_ENABLED; |
| 211 | tmp |= FLASH_WRITES_DISABLED; |
| 212 | pci_mmio_writel(tmp, nicintel_spibar + EECD); |
| 213 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 217 | static int nicintel_spi_82599_enable_flash(void) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 218 | { |
| 219 | uint32_t tmp; |
| 220 | |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 221 | /* Automatic restore of EECD on shutdown is not possible because EECD |
| 222 | * does not only contain FLASH_WRITES_DISABLED|FLASH_WRITES_ENABLED, |
| 223 | * but other bits with side effects as well. Those other bits must be |
| 224 | * left untouched. |
| 225 | */ |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 226 | tmp = pci_mmio_readl(nicintel_spibar + EECD); |
| 227 | tmp &= ~FLASH_WRITES_DISABLED; |
| 228 | tmp |= FLASH_WRITES_ENABLED; |
| 229 | pci_mmio_writel(tmp, nicintel_spibar + EECD); |
| 230 | |
Stefan Tauner | 8ee180d | 2012-02-27 19:44:16 +0000 | [diff] [blame] | 231 | /* test if FWE is really set to allow writes */ |
| 232 | tmp = pci_mmio_readl(nicintel_spibar + EECD); |
| 233 | if ( (tmp & FLASH_WRITES_DISABLED) || !(tmp & FLASH_WRITES_ENABLED) ) { |
| 234 | msg_perr("Enabling flash write access failed.\n"); |
| 235 | return 1; |
| 236 | } |
| 237 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 238 | if (register_shutdown(nicintel_spi_shutdown, NULL)) |
| 239 | return 1; |
| 240 | |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Richard Hughes | 93e1625 | 2018-12-19 11:54:47 +0000 | [diff] [blame] | 244 | static int nicintel_spi_i210_enable_flash(void) |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 245 | { |
| 246 | uint32_t tmp; |
| 247 | |
| 248 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 249 | if (tmp & BIT(FL_LOCKED)) { |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 250 | msg_perr("Flash is in Secure Mode. Abort.\n"); |
| 251 | return 1; |
| 252 | } |
| 253 | |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 254 | if (!(tmp & BIT(FL_ABORT))) |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 255 | return 0; |
| 256 | |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 257 | tmp |= BIT(FL_CLR_ERR); |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 258 | pci_mmio_writel(tmp, nicintel_spibar + FLA); |
| 259 | tmp = pci_mmio_readl(nicintel_spibar + FLA); |
Ricardo Ribalda Delgado | 75a2a79 | 2017-03-23 23:38:04 +0100 | [diff] [blame] | 260 | if (!(tmp & BIT(FL_ABORT))) { |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 261 | msg_perr("Unable to clear Flash Access Error. Abort\n"); |
| 262 | return 1; |
| 263 | } |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
Nico Huber | e3a2688 | 2023-01-11 21:45:51 +0100 | [diff] [blame] | 268 | static int nicintel_spi_init(struct flashprog_programmer *const prog) |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 269 | { |
| 270 | struct pci_dev *dev = NULL; |
| 271 | |
Ricardo Ribalda Delgado | 26d33d2 | 2017-03-22 14:30:52 +0100 | [diff] [blame] | 272 | dev = pcidev_init(nics_intel_spi, PCI_BASE_ADDRESS_0); |
| 273 | if (!dev) |
| 274 | return 1; |
| 275 | |
| 276 | uint32_t io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
| 277 | if (!io_base_addr) |
| 278 | return 1; |
| 279 | |
| 280 | if ((dev->device_id & 0xfff0) == 0x1530) { |
| 281 | nicintel_spibar = rphysmap("Intel I210 Gigabit w/ SPI flash", io_base_addr + 0x12000, |
| 282 | MEMMAP_SIZE); |
| 283 | if (!nicintel_spibar || nicintel_spi_i210_enable_flash()) |
| 284 | return 1; |
| 285 | } else if (dev->device_id < 0x10d8) { |
| 286 | nicintel_spibar = rphysmap("Intel Gigabit NIC w/ SPI flash", io_base_addr, |
| 287 | MEMMAP_SIZE); |
| 288 | if (!nicintel_spibar || nicintel_spi_82599_enable_flash()) |
| 289 | return 1; |
| 290 | } else { |
| 291 | nicintel_spibar = rphysmap("Intel 10 Gigabit NIC w/ SPI flash", io_base_addr + 0x10000, |
| 292 | MEMMAP_SIZE); |
| 293 | if (!nicintel_spibar || nicintel_spi_82599_enable_flash()) |
| 294 | return 1; |
| 295 | } |
| 296 | |
Anastasia Klimchuk | a447c12 | 2021-05-31 11:20:01 +1000 | [diff] [blame] | 297 | if (register_spi_bitbang_master(&bitbang_spi_master_nicintel, NULL)) |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 298 | return 1; |
| 299 | |
Idwer Vollering | 004f4b7 | 2010-09-03 18:21:21 +0000 | [diff] [blame] | 300 | return 0; |
| 301 | } |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 302 | |
| 303 | const struct programmer_entry programmer_nicintel_spi = { |
| 304 | .name = "nicintel_spi", |
| 305 | .type = PCI, |
| 306 | .devs.dev = nics_intel_spi, |
| 307 | .init = nicintel_spi_init, |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 308 | }; |