Skip to content

Commit 07e2aef

Browse files
KrishnaSimmadharipreetam-narayan
authored andcommitted
Simmadha/qsfp mem controller driver (#22)
Sync with linux-dfl branch
1 parent 55114b8 commit 07e2aef

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

drivers/net/phy/qsfp-mem-core.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,33 @@ int check_qsfp_plugin(struct qsfp *qsfp)
107107
}
108108
EXPORT_SYMBOL_GPL(check_qsfp_plugin);
109109

110-
u32 qsfp_connected_show(struct qsfp *qsfp)
110+
ssize_t qsfp_connected_show(struct device *dev, struct device_attribute *attr, char *buf)
111111
{
112+
struct qsfp *qsfp = dev_get_drvdata(dev);
112113
u32 plugin;
113114

114115
mutex_lock(&qsfp->lock);
115116
plugin = check_qsfp_plugin(qsfp) && (qsfp->init == QSFP_INIT_DONE);
116117
mutex_unlock(&qsfp->lock);
117118

118-
return plugin;
119+
return sysfs_emit(buf, "%u\n", plugin);
119120
}
120-
EXPORT_SYMBOL_GPL(qsfp_connected_show);
121+
static DEVICE_ATTR_RO(qsfp_connected);
122+
123+
static struct attribute *qsfp_mem_attrs[] = {
124+
&dev_attr_qsfp_connected.attr,
125+
NULL,
126+
};
127+
128+
static const struct attribute_group qsfp_mem_group = {
129+
.attrs = qsfp_mem_attrs,
130+
};
131+
132+
const struct attribute_group *qsfp_mem_groups[] = {
133+
&qsfp_mem_group,
134+
NULL,
135+
};
136+
EXPORT_SYMBOL_GPL(qsfp_mem_groups);
121137

122138
void qsfp_check_hotplug(struct work_struct *work)
123139
{

drivers/net/phy/qsfp-mem-dfl.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,14 @@
55
* Copyright (C) 2022 Intel Corporation. All rights reserved.
66
*/
77
#include <linux/dfl.h>
8-
#include <linux/phy/qsfp-mem.h>
98
#include <linux/module.h>
10-
11-
ssize_t dfl_qsfp_connected_show(struct device *dev, struct device_attribute *attr, char *buf)
12-
{
13-
struct qsfp *qsfp = dev_get_drvdata(dev);
14-
u32 plugin = qsfp_connected_show(qsfp);
15-
16-
return sysfs_emit(buf, "%u\n", plugin);
17-
}
18-
19-
static DEVICE_ATTR_RO(dfl_qsfp_connected);
20-
21-
static struct attribute *qsfp_mem_attrs[] = {
22-
&dev_attr_dfl_qsfp_connected.attr,
23-
NULL,
24-
};
25-
ATTRIBUTE_GROUPS(qsfp_mem);
9+
#include <linux/phy/qsfp-mem.h>
2610

2711
static int qsfp_dfl_probe(struct dfl_device *dfl_dev)
2812
{
2913
struct device *dev = &dfl_dev->dev;
3014
struct qsfp *qsfp;
31-
int ret = 0;
15+
int ret;
3216

3317
qsfp = devm_kzalloc(dev, sizeof(*qsfp), GFP_KERNEL);
3418
if (!qsfp)
@@ -44,11 +28,23 @@ static int qsfp_dfl_probe(struct dfl_device *dfl_dev)
4428
dev_set_drvdata(dev, qsfp);
4529

4630
ret = qsfp_init_work(qsfp);
47-
if (ret != 0) {
48-
dev_err(dev, "Failed to initialize delayed work to read QSFP\n");
49-
return ret;
31+
if (ret) {
32+
dev_err_probe(dev, ret,
33+
"Failed to initialize delayed work to read QSFP\n");
34+
goto exit;
5035
}
51-
return qsfp_register_regmap(qsfp);
36+
37+
ret = qsfp_register_regmap(qsfp);
38+
if (ret)
39+
goto cancel_work;
40+
41+
return 0;
42+
43+
cancel_work:
44+
qsfp_remove_device(qsfp);
45+
exit:
46+
mutex_destroy(&qsfp->lock);
47+
return ret;
5248
}
5349

5450
static void qsfp_dfl_remove(struct dfl_device *dfl_dev)

drivers/net/phy/qsfp-mem-platform.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* Copyright (C) 2022 Intel Corporation. All rights reserved.
66
*/
77

8-
#include <linux/phy/qsfp-mem.h>
98
#include <linux/bitfield.h>
109
#include <linux/module.h>
1110
#include <linux/of_address.h>
1211
#include <linux/of_device.h>
12+
#include <linux/phy/qsfp-mem.h>
1313
#include <linux/processor.h>
1414
#include <linux/slab.h>
1515

@@ -21,7 +21,7 @@ static int qsfp_platform_probe(struct platform_device *pdev)
2121
struct resource *region = NULL;
2222
struct resource *qsfpconfig = NULL;
2323
struct qsfp *qsfp = NULL;
24-
int ret = 0;
24+
int ret;
2525

2626
qsfp = devm_kzalloc(dev, sizeof(*qsfp), GFP_KERNEL);
2727
if (!qsfp)
@@ -35,8 +35,7 @@ static int qsfp_platform_probe(struct platform_device *pdev)
3535
qsfpconfig = platform_get_resource_byname(pdev, IORESOURCE_MEM,
3636
INTEL_QSFP_MEM_CONTROLLER_NAME);
3737
if (!qsfpconfig) {
38-
dev_err(dev, "resource %s not defined\n",
39-
INTEL_QSFP_MEM_CONTROLLER_NAME);
38+
dev_err(dev, "resource %s not defined\n", INTEL_QSFP_MEM_CONTROLLER_NAME);
4039
return -ENODEV;
4140
}
4241

@@ -53,12 +52,23 @@ static int qsfp_platform_probe(struct platform_device *pdev)
5352
}
5453

5554
ret = qsfp_init_work(qsfp);
56-
if (ret != 0) {
57-
dev_err(dev, "Failed to initialize delayed work to read QSFP\n");
58-
return ret;
55+
if (ret) {
56+
dev_err_probe(dev, ret,
57+
"Failed to initialize delayed work to read QSFP\n");
58+
goto exit;
5959
}
6060

61-
return qsfp_register_regmap(qsfp);
61+
ret = qsfp_register_regmap(qsfp);
62+
if (ret)
63+
goto cancel_work;
64+
65+
return 0;
66+
67+
cancel_work:
68+
qsfp_remove_device(qsfp);
69+
exit:
70+
mutex_destroy(&qsfp->lock);
71+
return ret;
6272
}
6373

6474
static int qsfp_platform_remove(struct platform_device *pdev)
@@ -72,8 +82,7 @@ static int qsfp_platform_remove(struct platform_device *pdev)
7282
}
7383

7484
static const struct of_device_id intel_fpga_qsfp_mem_ids[] = {
75-
{ .compatible = "intel,qsfp-mem",
76-
.data = NULL, },
85+
{ .compatible = "intel,qsfp-mem", .data = NULL, },
7786
{},
7887
};
7988
MODULE_DEVICE_TABLE(of, intel_fpga_qsfp_mem_ids);
@@ -84,7 +93,8 @@ static struct platform_driver qsfp_driver = {
8493
.suspend = NULL,
8594
.resume = NULL,
8695
.driver = {
87-
.name = "intel,qsfp-mem",
96+
.name = "qsfp-mem",
97+
.dev_groups = qsfp_mem_groups,
8898
.owner = THIS_MODULE,
8999
.of_match_table = intel_fpga_qsfp_mem_ids,
90100
},
@@ -94,4 +104,3 @@ module_platform_driver(qsfp_driver);
94104
MODULE_DESCRIPTION("Intel(R) Memory based QSFP Platform driver");
95105
MODULE_AUTHOR("Intel Corporation");
96106
MODULE_LICENSE("GPL");
97-

include/linux/phy/qsfp-mem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ int qsfp_init_work(struct qsfp *qsfp);
4545
int qsfp_register_regmap(struct qsfp *qsfp);
4646
void qsfp_remove_device(struct qsfp *qsfp);
4747
int check_qsfp_plugin(struct qsfp *qsfp);
48-
u32 qsfp_connected_show(struct qsfp *qsfp);
48+
extern const struct attribute_group *qsfp_mem_groups[];
4949

5050
#endif //__LINUX_QSFP_MEM_H

0 commit comments

Comments
 (0)