.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | | - * |
---|
| 3 | + * Copyright (c) 2003-2020, Intel Corporation. All rights reserved. |
---|
3 | 4 | * Intel Management Engine Interface (Intel MEI) Linux driver |
---|
4 | | - * Copyright (c) 2003-2012, Intel Corporation. |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify it |
---|
7 | | - * under the terms and conditions of the GNU General Public License, |
---|
8 | | - * version 2, as published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
---|
11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
13 | | - * more details. |
---|
14 | | - * |
---|
15 | 5 | */ |
---|
16 | 6 | |
---|
17 | 7 | #include <linux/pci.h> |
---|
.. | .. |
---|
183 | 173 | } |
---|
184 | 174 | |
---|
185 | 175 | /** |
---|
| 176 | + * mei_me_trc_status - read trc status register |
---|
| 177 | + * |
---|
| 178 | + * @dev: mei device |
---|
| 179 | + * @trc: trc status register value |
---|
| 180 | + * |
---|
| 181 | + * Return: 0 on success, error otherwise |
---|
| 182 | + */ |
---|
| 183 | +static int mei_me_trc_status(struct mei_device *dev, u32 *trc) |
---|
| 184 | +{ |
---|
| 185 | + struct mei_me_hw *hw = to_me_hw(dev); |
---|
| 186 | + |
---|
| 187 | + if (!hw->cfg->hw_trc_supported) |
---|
| 188 | + return -EOPNOTSUPP; |
---|
| 189 | + |
---|
| 190 | + *trc = mei_me_reg_read(hw, ME_TRC); |
---|
| 191 | + trace_mei_reg_read(dev->dev, "ME_TRC", ME_TRC, *trc); |
---|
| 192 | + |
---|
| 193 | + return 0; |
---|
| 194 | +} |
---|
| 195 | + |
---|
| 196 | +/** |
---|
186 | 197 | * mei_me_fw_status - read fw status register from pci config space |
---|
187 | 198 | * |
---|
188 | 199 | * @dev: mei device |
---|
.. | .. |
---|
193 | 204 | static int mei_me_fw_status(struct mei_device *dev, |
---|
194 | 205 | struct mei_fw_status *fw_status) |
---|
195 | 206 | { |
---|
196 | | - struct pci_dev *pdev = to_pci_dev(dev->dev); |
---|
197 | 207 | struct mei_me_hw *hw = to_me_hw(dev); |
---|
198 | 208 | const struct mei_fw_status *fw_src = &hw->cfg->fw_status; |
---|
199 | 209 | int ret; |
---|
200 | 210 | int i; |
---|
201 | 211 | |
---|
202 | | - if (!fw_status) |
---|
| 212 | + if (!fw_status || !hw->read_fws) |
---|
203 | 213 | return -EINVAL; |
---|
204 | 214 | |
---|
205 | 215 | fw_status->count = fw_src->count; |
---|
206 | 216 | for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) { |
---|
207 | | - ret = pci_read_config_dword(pdev, fw_src->status[i], |
---|
208 | | - &fw_status->status[i]); |
---|
209 | | - trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HSF_X", |
---|
| 217 | + ret = hw->read_fws(dev, fw_src->status[i], |
---|
| 218 | + &fw_status->status[i]); |
---|
| 219 | + trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_X", |
---|
210 | 220 | fw_src->status[i], |
---|
211 | 221 | fw_status->status[i]); |
---|
212 | 222 | if (ret) |
---|
.. | .. |
---|
220 | 230 | * mei_me_hw_config - configure hw dependent settings |
---|
221 | 231 | * |
---|
222 | 232 | * @dev: mei device |
---|
| 233 | + * |
---|
| 234 | + * Return: |
---|
| 235 | + * * -EINVAL when read_fws is not set |
---|
| 236 | + * * 0 on success |
---|
| 237 | + * |
---|
223 | 238 | */ |
---|
224 | | -static void mei_me_hw_config(struct mei_device *dev) |
---|
| 239 | +static int mei_me_hw_config(struct mei_device *dev) |
---|
225 | 240 | { |
---|
226 | | - struct pci_dev *pdev = to_pci_dev(dev->dev); |
---|
227 | 241 | struct mei_me_hw *hw = to_me_hw(dev); |
---|
228 | 242 | u32 hcsr, reg; |
---|
| 243 | + |
---|
| 244 | + if (WARN_ON(!hw->read_fws)) |
---|
| 245 | + return -EINVAL; |
---|
229 | 246 | |
---|
230 | 247 | /* Doesn't change in runtime */ |
---|
231 | 248 | hcsr = mei_hcsr_read(dev); |
---|
232 | 249 | hw->hbuf_depth = (hcsr & H_CBD) >> 24; |
---|
233 | 250 | |
---|
234 | 251 | reg = 0; |
---|
235 | | - pci_read_config_dword(pdev, PCI_CFG_HFS_1, ®); |
---|
| 252 | + hw->read_fws(dev, PCI_CFG_HFS_1, ®); |
---|
236 | 253 | trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg); |
---|
237 | 254 | hw->d0i3_supported = |
---|
238 | 255 | ((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK); |
---|
.. | .. |
---|
243 | 260 | if (reg & H_D0I3C_I3) |
---|
244 | 261 | hw->pg_state = MEI_PG_ON; |
---|
245 | 262 | } |
---|
| 263 | + |
---|
| 264 | + return 0; |
---|
246 | 265 | } |
---|
247 | 266 | |
---|
248 | 267 | /** |
---|
.. | .. |
---|
279 | 298 | } |
---|
280 | 299 | |
---|
281 | 300 | /** |
---|
282 | | - * mei_me_intr_clear - clear and stop interrupts |
---|
| 301 | + * me_intr_clear - clear and stop interrupts |
---|
283 | 302 | * |
---|
284 | 303 | * @dev: the device structure |
---|
285 | 304 | * @hcsr: supplied hcsr register value |
---|
.. | .. |
---|
333 | 352 | */ |
---|
334 | 353 | static void mei_me_synchronize_irq(struct mei_device *dev) |
---|
335 | 354 | { |
---|
336 | | - struct pci_dev *pdev = to_pci_dev(dev->dev); |
---|
| 355 | + struct mei_me_hw *hw = to_me_hw(dev); |
---|
337 | 356 | |
---|
338 | | - synchronize_irq(pdev->irq); |
---|
| 357 | + synchronize_irq(hw->irq); |
---|
339 | 358 | } |
---|
340 | 359 | |
---|
341 | 360 | /** |
---|
.. | .. |
---|
350 | 369 | hcsr |= H_IG; |
---|
351 | 370 | hcsr &= ~H_RST; |
---|
352 | 371 | mei_hcsr_set(dev, hcsr); |
---|
353 | | - |
---|
354 | | - /* complete this write before we set host ready on another CPU */ |
---|
355 | | - mmiowb(); |
---|
356 | 372 | } |
---|
357 | 373 | |
---|
358 | 374 | /** |
---|
.. | .. |
---|
1307 | 1323 | |
---|
1308 | 1324 | static const struct mei_hw_ops mei_me_hw_ops = { |
---|
1309 | 1325 | |
---|
| 1326 | + .trc_status = mei_me_trc_status, |
---|
1310 | 1327 | .fw_status = mei_me_fw_status, |
---|
1311 | 1328 | .pg_state = mei_me_pg_state, |
---|
1312 | 1329 | |
---|
.. | .. |
---|
1336 | 1353 | .read = mei_me_read_slots |
---|
1337 | 1354 | }; |
---|
1338 | 1355 | |
---|
1339 | | -static bool mei_me_fw_type_nm(struct pci_dev *pdev) |
---|
| 1356 | +/** |
---|
| 1357 | + * mei_me_fw_type_nm() - check for nm sku |
---|
| 1358 | + * |
---|
| 1359 | + * Read ME FW Status register to check for the Node Manager (NM) Firmware. |
---|
| 1360 | + * The NM FW is only signaled in PCI function 0. |
---|
| 1361 | + * __Note__: Deprecated by PCH8 and newer. |
---|
| 1362 | + * |
---|
| 1363 | + * @pdev: pci device |
---|
| 1364 | + * |
---|
| 1365 | + * Return: true in case of NM firmware |
---|
| 1366 | + */ |
---|
| 1367 | +static bool mei_me_fw_type_nm(const struct pci_dev *pdev) |
---|
1340 | 1368 | { |
---|
1341 | 1369 | u32 reg; |
---|
| 1370 | + unsigned int devfn; |
---|
1342 | 1371 | |
---|
1343 | | - pci_read_config_dword(pdev, PCI_CFG_HFS_2, ®); |
---|
| 1372 | + devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); |
---|
| 1373 | + pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_2, ®); |
---|
1344 | 1374 | trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg); |
---|
1345 | 1375 | /* make sure that bit 9 (NM) is up and bit 10 (DM) is down */ |
---|
1346 | 1376 | return (reg & 0x600) == 0x200; |
---|
.. | .. |
---|
1349 | 1379 | #define MEI_CFG_FW_NM \ |
---|
1350 | 1380 | .quirk_probe = mei_me_fw_type_nm |
---|
1351 | 1381 | |
---|
1352 | | -static bool mei_me_fw_type_sps(struct pci_dev *pdev) |
---|
| 1382 | +/** |
---|
| 1383 | + * mei_me_fw_sku_sps_4() - check for sps 4.0 sku |
---|
| 1384 | + * |
---|
| 1385 | + * Read ME FW Status register to check for SPS Firmware. |
---|
| 1386 | + * The SPS FW is only signaled in the PCI function 0. |
---|
| 1387 | + * __Note__: Deprecated by SPS 5.0 and newer. |
---|
| 1388 | + * |
---|
| 1389 | + * @pdev: pci device |
---|
| 1390 | + * |
---|
| 1391 | + * Return: true in case of SPS firmware |
---|
| 1392 | + */ |
---|
| 1393 | +static bool mei_me_fw_type_sps_4(const struct pci_dev *pdev) |
---|
1353 | 1394 | { |
---|
1354 | 1395 | u32 reg; |
---|
1355 | 1396 | unsigned int devfn; |
---|
1356 | 1397 | |
---|
1357 | | - /* |
---|
1358 | | - * Read ME FW Status register to check for SPS Firmware |
---|
1359 | | - * The SPS FW is only signaled in pci function 0 |
---|
1360 | | - */ |
---|
1361 | 1398 | devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); |
---|
1362 | 1399 | pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_1, ®); |
---|
1363 | 1400 | trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg); |
---|
1364 | | - /* if bits [19:16] = 15, running SPS Firmware */ |
---|
1365 | | - return (reg & 0xf0000) == 0xf0000; |
---|
| 1401 | + return (reg & PCI_CFG_HFS_1_OPMODE_MSK) == PCI_CFG_HFS_1_OPMODE_SPS; |
---|
1366 | 1402 | } |
---|
1367 | 1403 | |
---|
1368 | | -#define MEI_CFG_FW_SPS \ |
---|
| 1404 | +#define MEI_CFG_FW_SPS_4 \ |
---|
| 1405 | + .quirk_probe = mei_me_fw_type_sps_4 |
---|
| 1406 | + |
---|
| 1407 | +/** |
---|
| 1408 | + * mei_me_fw_sku_sps() - check for sps sku |
---|
| 1409 | + * |
---|
| 1410 | + * Read ME FW Status register to check for SPS Firmware. |
---|
| 1411 | + * The SPS FW is only signaled in pci function 0 |
---|
| 1412 | + * |
---|
| 1413 | + * @pdev: pci device |
---|
| 1414 | + * |
---|
| 1415 | + * Return: true in case of SPS firmware |
---|
| 1416 | + */ |
---|
| 1417 | +static bool mei_me_fw_type_sps(const struct pci_dev *pdev) |
---|
| 1418 | +{ |
---|
| 1419 | + u32 reg; |
---|
| 1420 | + u32 fw_type; |
---|
| 1421 | + unsigned int devfn; |
---|
| 1422 | + |
---|
| 1423 | + devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); |
---|
| 1424 | + pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_3, ®); |
---|
| 1425 | + trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_3", PCI_CFG_HFS_3, reg); |
---|
| 1426 | + fw_type = (reg & PCI_CFG_HFS_3_FW_SKU_MSK); |
---|
| 1427 | + |
---|
| 1428 | + dev_dbg(&pdev->dev, "fw type is %d\n", fw_type); |
---|
| 1429 | + |
---|
| 1430 | + return fw_type == PCI_CFG_HFS_3_FW_SKU_SPS; |
---|
| 1431 | +} |
---|
| 1432 | + |
---|
| 1433 | +#define MEI_CFG_KIND_ITOUCH \ |
---|
| 1434 | + .kind = "itouch" |
---|
| 1435 | + |
---|
| 1436 | +#define MEI_CFG_FW_SPS \ |
---|
1369 | 1437 | .quirk_probe = mei_me_fw_type_sps |
---|
1370 | 1438 | |
---|
1371 | 1439 | #define MEI_CFG_FW_VER_SUPP \ |
---|
.. | .. |
---|
1396 | 1464 | .dma_size[DMA_DSCR_HOST] = SZ_128K, \ |
---|
1397 | 1465 | .dma_size[DMA_DSCR_DEVICE] = SZ_128K, \ |
---|
1398 | 1466 | .dma_size[DMA_DSCR_CTRL] = PAGE_SIZE |
---|
| 1467 | + |
---|
| 1468 | +#define MEI_CFG_TRC \ |
---|
| 1469 | + .hw_trc_supported = 1 |
---|
1399 | 1470 | |
---|
1400 | 1471 | /* ICH Legacy devices */ |
---|
1401 | 1472 | static const struct mei_cfg mei_me_ich_cfg = { |
---|
.. | .. |
---|
1431 | 1502 | MEI_CFG_FW_VER_SUPP, |
---|
1432 | 1503 | }; |
---|
1433 | 1504 | |
---|
1434 | | -/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */ |
---|
1435 | | -static const struct mei_cfg mei_me_pch8_sps_cfg = { |
---|
| 1505 | +/* PCH8 Lynx Point and newer devices - iTouch */ |
---|
| 1506 | +static const struct mei_cfg mei_me_pch8_itouch_cfg = { |
---|
| 1507 | + MEI_CFG_KIND_ITOUCH, |
---|
1436 | 1508 | MEI_CFG_PCH8_HFS, |
---|
1437 | 1509 | MEI_CFG_FW_VER_SUPP, |
---|
1438 | | - MEI_CFG_FW_SPS, |
---|
| 1510 | +}; |
---|
| 1511 | + |
---|
| 1512 | +/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */ |
---|
| 1513 | +static const struct mei_cfg mei_me_pch8_sps_4_cfg = { |
---|
| 1514 | + MEI_CFG_PCH8_HFS, |
---|
| 1515 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1516 | + MEI_CFG_FW_SPS_4, |
---|
| 1517 | +}; |
---|
| 1518 | + |
---|
| 1519 | +/* LBG with quirk for SPS (4.0) Firmware exclusion */ |
---|
| 1520 | +static const struct mei_cfg mei_me_pch12_sps_4_cfg = { |
---|
| 1521 | + MEI_CFG_PCH8_HFS, |
---|
| 1522 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1523 | + MEI_CFG_FW_SPS_4, |
---|
1439 | 1524 | }; |
---|
1440 | 1525 | |
---|
1441 | 1526 | /* Cannon Lake and newer devices */ |
---|
.. | .. |
---|
1443 | 1528 | MEI_CFG_PCH8_HFS, |
---|
1444 | 1529 | MEI_CFG_FW_VER_SUPP, |
---|
1445 | 1530 | MEI_CFG_DMA_128, |
---|
| 1531 | +}; |
---|
| 1532 | + |
---|
| 1533 | +/* Cannon Lake with quirk for SPS 5.0 and newer Firmware exclusion */ |
---|
| 1534 | +static const struct mei_cfg mei_me_pch12_sps_cfg = { |
---|
| 1535 | + MEI_CFG_PCH8_HFS, |
---|
| 1536 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1537 | + MEI_CFG_DMA_128, |
---|
| 1538 | + MEI_CFG_FW_SPS, |
---|
| 1539 | +}; |
---|
| 1540 | + |
---|
| 1541 | +/* Cannon Lake itouch with quirk for SPS 5.0 and newer Firmware exclusion |
---|
| 1542 | + * w/o DMA support. |
---|
| 1543 | + */ |
---|
| 1544 | +static const struct mei_cfg mei_me_pch12_itouch_sps_cfg = { |
---|
| 1545 | + MEI_CFG_KIND_ITOUCH, |
---|
| 1546 | + MEI_CFG_PCH8_HFS, |
---|
| 1547 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1548 | + MEI_CFG_FW_SPS, |
---|
| 1549 | +}; |
---|
| 1550 | + |
---|
| 1551 | +/* Tiger Lake and newer devices */ |
---|
| 1552 | +static const struct mei_cfg mei_me_pch15_cfg = { |
---|
| 1553 | + MEI_CFG_PCH8_HFS, |
---|
| 1554 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1555 | + MEI_CFG_DMA_128, |
---|
| 1556 | + MEI_CFG_TRC, |
---|
| 1557 | +}; |
---|
| 1558 | + |
---|
| 1559 | +/* Tiger Lake with quirk for SPS 5.0 and newer Firmware exclusion */ |
---|
| 1560 | +static const struct mei_cfg mei_me_pch15_sps_cfg = { |
---|
| 1561 | + MEI_CFG_PCH8_HFS, |
---|
| 1562 | + MEI_CFG_FW_VER_SUPP, |
---|
| 1563 | + MEI_CFG_DMA_128, |
---|
| 1564 | + MEI_CFG_TRC, |
---|
| 1565 | + MEI_CFG_FW_SPS, |
---|
1446 | 1566 | }; |
---|
1447 | 1567 | |
---|
1448 | 1568 | /* |
---|
.. | .. |
---|
1457 | 1577 | [MEI_ME_PCH7_CFG] = &mei_me_pch7_cfg, |
---|
1458 | 1578 | [MEI_ME_PCH_CPT_PBG_CFG] = &mei_me_pch_cpt_pbg_cfg, |
---|
1459 | 1579 | [MEI_ME_PCH8_CFG] = &mei_me_pch8_cfg, |
---|
1460 | | - [MEI_ME_PCH8_SPS_CFG] = &mei_me_pch8_sps_cfg, |
---|
| 1580 | + [MEI_ME_PCH8_ITOUCH_CFG] = &mei_me_pch8_itouch_cfg, |
---|
| 1581 | + [MEI_ME_PCH8_SPS_4_CFG] = &mei_me_pch8_sps_4_cfg, |
---|
1461 | 1582 | [MEI_ME_PCH12_CFG] = &mei_me_pch12_cfg, |
---|
| 1583 | + [MEI_ME_PCH12_SPS_4_CFG] = &mei_me_pch12_sps_4_cfg, |
---|
| 1584 | + [MEI_ME_PCH12_SPS_CFG] = &mei_me_pch12_sps_cfg, |
---|
| 1585 | + [MEI_ME_PCH12_SPS_ITOUCH_CFG] = &mei_me_pch12_itouch_sps_cfg, |
---|
| 1586 | + [MEI_ME_PCH15_CFG] = &mei_me_pch15_cfg, |
---|
| 1587 | + [MEI_ME_PCH15_SPS_CFG] = &mei_me_pch15_sps_cfg, |
---|
1462 | 1588 | }; |
---|
1463 | 1589 | |
---|
1464 | 1590 | const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx) |
---|
.. | .. |
---|
1474 | 1600 | /** |
---|
1475 | 1601 | * mei_me_dev_init - allocates and initializes the mei device structure |
---|
1476 | 1602 | * |
---|
1477 | | - * @pdev: The pci device structure |
---|
| 1603 | + * @parent: device associated with physical device (pci/platform) |
---|
1478 | 1604 | * @cfg: per device generation config |
---|
1479 | 1605 | * |
---|
1480 | 1606 | * Return: The mei_device pointer on success, NULL on failure. |
---|
1481 | 1607 | */ |
---|
1482 | | -struct mei_device *mei_me_dev_init(struct pci_dev *pdev, |
---|
| 1608 | +struct mei_device *mei_me_dev_init(struct device *parent, |
---|
1483 | 1609 | const struct mei_cfg *cfg) |
---|
1484 | 1610 | { |
---|
1485 | 1611 | struct mei_device *dev; |
---|
1486 | 1612 | struct mei_me_hw *hw; |
---|
| 1613 | + int i; |
---|
1487 | 1614 | |
---|
1488 | | - dev = devm_kzalloc(&pdev->dev, sizeof(struct mei_device) + |
---|
1489 | | - sizeof(struct mei_me_hw), GFP_KERNEL); |
---|
| 1615 | + dev = devm_kzalloc(parent, sizeof(*dev) + sizeof(*hw), GFP_KERNEL); |
---|
1490 | 1616 | if (!dev) |
---|
1491 | 1617 | return NULL; |
---|
| 1618 | + |
---|
1492 | 1619 | hw = to_me_hw(dev); |
---|
1493 | 1620 | |
---|
1494 | | - mei_device_init(dev, &pdev->dev, &mei_me_hw_ops); |
---|
| 1621 | + for (i = 0; i < DMA_DSCR_NUM; i++) |
---|
| 1622 | + dev->dr_dscr[i].size = cfg->dma_size[i]; |
---|
| 1623 | + |
---|
| 1624 | + mei_device_init(dev, parent, &mei_me_hw_ops); |
---|
1495 | 1625 | hw->cfg = cfg; |
---|
| 1626 | + |
---|
1496 | 1627 | dev->fw_f_fw_ver_supported = cfg->fw_ver_supported; |
---|
1497 | 1628 | |
---|
| 1629 | + dev->kind = cfg->kind; |
---|
| 1630 | + |
---|
1498 | 1631 | return dev; |
---|
1499 | 1632 | } |
---|
1500 | 1633 | |
---|