iwlwifi: mvm: fix version check for GEO_TX_POWER_LIMIT support
[linux/fpc-iii.git] / arch / s390 / net / pnet.c
blobe22f1b10a6c7bea046cc88502313a9d63893a95e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * IBM System z PNET ID Support
5 * Copyright IBM Corp. 2018
6 */
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>
17 * Get the PNETIDs from a device.
18 * s390 hardware supports the definition of a so-called Physical Network
19 * Identifier (short PNETID) per network device port. These PNETIDs can be
20 * used to identify network devices that are attached to the same physical
21 * network (broadcast domain).
23 * The device can be
24 * - a ccwgroup device with all bundled subchannels having the same PNETID
25 * - a PCI attached network device
27 * Returns:
28 * 0: PNETIDs extracted from device.
29 * -ENOMEM: No memory to extract utility string.
30 * -EOPNOTSUPP: Device type without utility string support
32 static int pnet_ids_by_device(struct device *dev, u8 *pnetids)
34 memset(pnetids, 0, PNETIDS_LEN);
35 if (dev_is_ccwgroup(dev)) {
36 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
37 u8 *util_str;
39 util_str = ccw_device_get_util_str(gdev->cdev[0], 0);
40 if (!util_str)
41 return -ENOMEM;
42 memcpy(pnetids, util_str, PNETIDS_LEN);
43 kfree(util_str);
44 return 0;
46 if (dev_is_pci(dev)) {
47 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
49 memcpy(pnetids, zdev->util_str, sizeof(zdev->util_str));
50 return 0;
52 return -EOPNOTSUPP;
56 * Extract the pnetid for a device port.
58 * Return 0 if a pnetid is found and -ENOENT otherwise.
60 int pnet_id_by_dev_port(struct device *dev, unsigned short port, u8 *pnetid)
62 u8 pnetids[MAX_PNETID_PORTS][MAX_PNETID_LEN];
63 static const u8 zero[MAX_PNETID_LEN] = { 0 };
64 int rc = 0;
66 if (!dev || port >= MAX_PNETID_PORTS)
67 return -ENOENT;
69 if (!pnet_ids_by_device(dev, (u8 *)pnetids) &&
70 memcmp(pnetids[port], zero, MAX_PNETID_LEN))
71 memcpy(pnetid, pnetids[port], MAX_PNETID_LEN);
72 else
73 rc = -ENOENT;
75 return rc;
77 EXPORT_SYMBOL_GPL(pnet_id_by_dev_port);
79 MODULE_DESCRIPTION("pnetid determination from utility strings");
80 MODULE_LICENSE("GPL");