~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/s390/net/pnet.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php