1 // SPDX-License-Identifier: GPL-2.0
3 * IBM System z PNET ID Support
5 * Copyright IBM Corp. 2018
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>
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).
24 * - a ccwgroup device with all bundled subchannels having the same PNETID
25 * - a PCI attached network device
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
);
39 util_str
= ccw_device_get_util_str(gdev
->cdev
[0], 0);
42 memcpy(pnetids
, util_str
, PNETIDS_LEN
);
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
));
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 };
66 if (!dev
|| port
>= MAX_PNETID_PORTS
)
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
);
77 EXPORT_SYMBOL_GPL(pnet_id_by_dev_port
);
79 MODULE_DESCRIPTION("pnetid determination from utility strings");
80 MODULE_LICENSE("GPL");