1
2
3
4
5
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
18
19
20
21#define MAX_PNETID_LEN 16
22#define MAX_PNETID_PORTS (PNETIDS_LEN / MAX_PNETID_LEN)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41static 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
68
69
70
71int 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}
88EXPORT_SYMBOL_GPL(pnet_id_by_dev_port);
89
90MODULE_DESCRIPTION("pnetid determination from utility strings");
91MODULE_LICENSE("GPL");
92