Skip to content

Commit

Permalink
s390/net: add pnetid support
Browse files Browse the repository at this point in the history
s390 hardware supports the definition of a so-call Physical NETwork
IDentifier (short PNETID) per network device port. These PNETIDS
can be used to identify network devices that are attached to the same
physical network (broadcast domain).

This patch provides the interface to extract the PNETID of a port of
a device attached to the ccw-bus or pci-bus.

Parts of this patch are based on an initial implementation by
Thomas Richter.

Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Ursula Braun authored and Martin Schwidefsky committed May 25, 2018
1 parent 1bcdb53 commit 866f4c8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/s390/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ config PCI_QUIRKS
config ARCH_SUPPORTS_UPROBES
def_bool y

config HAVE_PNETID
def_bool y if SMC

config S390
def_bool y
select ARCH_BINFMT_ELF_STATE
Expand Down
23 changes: 23 additions & 0 deletions arch/s390/include/asm/pnet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* IBM System z PNET ID Support
*
* Copyright IBM Corp. 2018
*/

#ifndef _ASM_S390_PNET_H
#define _ASM_S390_PNET_H

#include <linux/device.h>
#include <linux/types.h>

#define PNETIDS_LEN 64 /* Total utility string length in bytes
* to cover up to 4 PNETIDs of 16 bytes
* for up to 4 device ports
*/
#define MAX_PNETID_LEN 16 /* Max.length of a single port PNETID */
#define MAX_PNETID_PORTS (PNETIDS_LEN / MAX_PNETID_LEN)
/* Max. # of ports with a PNETID */

int pnet_id_by_dev_port(struct device *dev, unsigned short port, u8 *pnetid);
#endif /* _ASM_S390_PNET_H */
1 change: 1 addition & 0 deletions arch/s390/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Arch-specific network modules
#
obj-$(CONFIG_BPF_JIT) += bpf_jit.o bpf_jit_comp.o
obj-$(CONFIG_HAVE_PNETID) += pnet.o
76 changes: 76 additions & 0 deletions arch/s390/net/pnet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: GPL-2.0
/*
* IBM System z PNET ID Support
*
* Copyright IBM Corp. 2018
*/

#include <linux/device.h>
#include <linux/pci.h>
#include <linux/types.h>
#include <asm/ccwgroup.h>
#include <asm/ccwdev.h>
#include <asm/pnet.h>

/*
* Get the PNETIDs from a device.
* s390 hardware supports the definition of a so-called Physical Network
* Identifier (short PNETID) per network device port. These PNETIDs can be
* used to identify network devices that are attached to the same physical
* network (broadcast domain).
*
* The device can be
* - a ccwgroup device with all bundled subchannels having the same PNETID
* - a PCI attached network device
*
* Returns:
* 0: PNETIDs extracted from device.
* -ENOMEM: No memory to extract utility string.
* -EOPNOTSUPP: Device type without utility string support
*/
static int pnet_ids_by_device(struct device *dev, u8 *pnetids)
{
memset(pnetids, 0, PNETIDS_LEN);
if (dev_is_ccwgroup(dev)) {
struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
u8 *util_str;

util_str = ccw_device_get_util_str(gdev->cdev[0], 0);
if (!util_str)
return -ENOMEM;
memcpy(pnetids, util_str, PNETIDS_LEN);
kfree(util_str);
return 0;
}
if (dev_is_pci(dev)) {
struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));

memcpy(pnetids, zdev->util_str, sizeof(zdev->util_str));
return 0;
}
return -EOPNOTSUPP;
}

/*
* Extract the pnetid for a device port.
*
* Return 0 if a pnetid is found and -ENOENT otherwise.
*/
int pnet_id_by_dev_port(struct device *dev, unsigned short port, u8 *pnetid)
{
u8 pnetids[MAX_PNETID_PORTS][MAX_PNETID_LEN];
static const u8 zero[MAX_PNETID_LEN] = { 0 };
int rc = 0;

if (!dev || port >= MAX_PNETID_PORTS)
return -ENOENT;

if (!pnet_ids_by_device(dev, (u8 *)pnetids) &&
memcmp(pnetids[port], zero, MAX_PNETID_LEN))
memcpy(pnetid, pnetids[port], MAX_PNETID_LEN);
else
rc = -ENOENT;

return rc;
}
EXPORT_SYMBOL_GPL(pnet_id_by_dev_port);

0 comments on commit 866f4c8

Please sign in to comment.