Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright IBM Corp. 2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Jan Glauber <jang@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define KMSG_COMPONENT "zpci"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/pci_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "pci_bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* Content Code Description for PCI Function Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct zpci_ccdf_err {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	u32 reserved1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	u32 fh;				/* function handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u32 fid;			/* function id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u32 ett		:  4;		/* expected table type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	u32 mvn		: 12;		/* MSI vector number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u32 dmaas	:  8;		/* DMA address space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	u32		:  6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	u32 q		:  1;		/* event qualifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	u32 rw		:  1;		/* read/write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u64 faddr;			/* failing address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	u32 reserved3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u16 reserved4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u16 pec;			/* PCI event code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* Content Code Description for PCI Function Availability */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) struct zpci_ccdf_avail {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u32 reserved1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u32 fh;				/* function handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u32 fid;			/* function id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u32 reserved2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u32 reserved3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	u32 reserved4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	u32 reserved5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u16 reserved6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u16 pec;			/* PCI event code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct pci_dev *pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	zpci_err("error CCDF:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	zpci_err_hex(ccdf, sizeof(*ccdf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	       pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	pdev->error_state = pci_channel_io_perm_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	pci_dev_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) void zpci_event_error(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (zpci_is_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		__zpci_event_error(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	enum zpci_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	zpci_err("avail CCDF:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	zpci_err_hex(ccdf, sizeof(*ccdf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	switch (ccdf->pec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	case 0x0301: /* Reserved|Standby -> Configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (!zdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_CONFIGURED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		/* the configuration request may be stale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (zdev->state != ZPCI_FN_STATE_STANDBY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		zdev->fh = ccdf->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		zdev->state = ZPCI_FN_STATE_CONFIGURED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ret = zpci_enable_device(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		/* the PCI function will be scanned once function 0 appears */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (!zdev->zbus->bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		pci_bus_add_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		pci_bus_add_devices(zdev->zbus->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case 0x0302: /* Reserved -> Standby */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (!zdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		zdev->fh = ccdf->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case 0x0303: /* Deconfiguration requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (!zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		zpci_remove_device(zdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		ret = zpci_disable_device(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		ret = sclp_pci_deconfigure(zdev->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			zdev->state = ZPCI_FN_STATE_STANDBY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	case 0x0304: /* Configured -> Standby|Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (!zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		/* Give the driver a hint that the function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		 * already unusable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		zpci_remove_device(zdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		zdev->fh = ccdf->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		zpci_disable_device(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		zdev->state = ZPCI_FN_STATE_STANDBY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (!clp_get_state(ccdf->fid, &state) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		    state == ZPCI_FN_STATE_RESERVED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			zpci_device_reserved(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	case 0x0306: /* 0x308 or 0x302 for multiple devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		zpci_remove_reserved_devices();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		clp_scan_pci_devices();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	case 0x0308: /* Standby -> Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (!zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		zpci_device_reserved(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void zpci_event_availability(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (zpci_is_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		__zpci_event_availability(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }