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)  *  IBM System z PNET ID Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *    Copyright IBM Corp. 2018
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/ccwgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/ccwdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/pnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PNETIDS_LEN		64	/* Total utility string length in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 					 * to cover up to 4 PNETIDs of 16 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 					 * for up to 4 device ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define MAX_PNETID_LEN		16	/* Max.length of a single port PNETID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define MAX_PNETID_PORTS	(PNETIDS_LEN / MAX_PNETID_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 					/* Max. # of ports with a PNETID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * Get the PNETIDs from a device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * s390 hardware supports the definition of a so-called Physical Network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  * Identifier (short PNETID) per network device port. These PNETIDs can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  * used to identify network devices that are attached to the same physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  * network (broadcast domain).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  * The device can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  * - a ccwgroup device with all bundled subchannels having the same PNETID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * - a PCI attached network device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)  * 0:		PNETIDs extracted from device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)  * -ENOMEM:	No memory to extract utility string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)  * -EOPNOTSUPP: Device type without utility string support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int pnet_ids_by_device(struct device *dev, u8 *pnetids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	memset(pnetids, 0, PNETIDS_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	if (dev_is_ccwgroup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		u8 *util_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		util_str = ccw_device_get_util_str(gdev->cdev[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 		if (!util_str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		memcpy(pnetids, util_str, PNETIDS_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		EBCASC(pnetids, PNETIDS_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		kfree(util_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	if (dev_is_pci(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		memcpy(pnetids, zdev->util_str, sizeof(zdev->util_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		EBCASC(pnetids, sizeof(zdev->util_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)  * Extract the pnetid for a device port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)  * Return 0 if a pnetid is found and -ENOENT otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int pnet_id_by_dev_port(struct device *dev, unsigned short port, u8 *pnetid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	u8 pnetids[MAX_PNETID_PORTS][MAX_PNETID_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	static const u8 zero[MAX_PNETID_LEN] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	if (!dev || port >= MAX_PNETID_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	if (!pnet_ids_by_device(dev, (u8 *)pnetids) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	    memcmp(pnetids[port], zero, MAX_PNETID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		memcpy(pnetid, pnetids[port], MAX_PNETID_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 		rc = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) EXPORT_SYMBOL_GPL(pnet_id_by_dev_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_DESCRIPTION("pnetid determination from utility strings");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MODULE_LICENSE("GPL");