Skip to content

Commit 57d6ec5

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: drop driver specific structure from fwlog code
In debugfs pass ice_fwlog structure instead of ice_pf. The debgufs dirs specific for fwlog can be stored in fwlog structure. Add debugfs entry point to fwlog api. Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> Tested-by: Rinitha S <sx.rinitha@intel.com> (A Contingent worker at Intel) Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 360c465 commit 57d6ec5

File tree

5 files changed

+75
-90
lines changed

5 files changed

+75
-90
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,6 @@ struct ice_pf {
568568
struct ice_sw *first_sw; /* first switch created by firmware */
569569
u16 eswitch_mode; /* current mode of eswitch */
570570
struct dentry *ice_debugfs_pf;
571-
struct dentry *ice_debugfs_pf_fwlog;
572-
/* keep track of all the dentrys for FW log modules */
573-
struct dentry **ice_debugfs_pf_fwlog_modules;
574571
struct ice_vfs vfs;
575572
DECLARE_BITMAP(features, ICE_F_MAX);
576573
DECLARE_BITMAP(state, ICE_STATE_NBITS);
@@ -908,7 +905,7 @@ static inline bool ice_is_adq_active(struct ice_pf *pf)
908905
return false;
909906
}
910907

911-
void ice_debugfs_fwlog_init(struct ice_pf *pf);
908+
void ice_debugfs_fwlog_init(struct ice_fwlog *fwlog, struct dentry *root);
912909
int ice_debugfs_pf_init(struct ice_pf *pf);
913910
void ice_debugfs_pf_deinit(struct ice_pf *pf);
914911
void ice_debugfs_init(void);

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,9 @@ static int __fwlog_init(struct ice_hw *hw)
10101010
if (err)
10111011
return err;
10121012

1013-
return ice_fwlog_init(hw, &hw->fwlog, &api);
1013+
api.debugfs_root = pf->ice_debugfs_pf;
1014+
1015+
return ice_fwlog_init(&hw->fwlog, &api);
10141016
}
10151017

10161018
/**
@@ -1195,7 +1197,7 @@ static void __fwlog_deinit(struct ice_hw *hw)
11951197
return;
11961198

11971199
ice_debugfs_pf_deinit(hw->back);
1198-
ice_fwlog_deinit(hw, &hw->fwlog);
1200+
ice_fwlog_deinit(&hw->fwlog);
11991201
}
12001202

12011203
/**

drivers/net/ethernet/intel/ice/ice_debugfs.c

Lines changed: 59 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ static const char * const ice_fwlog_log_size[] = {
7474

7575
/**
7676
* ice_fwlog_print_module_cfg - print current FW logging module configuration
77-
* @hw: pointer to the HW structure
77+
* @cfg: pointer to the fwlog cfg structure
7878
* @module: module to print
7979
* @s: the seq file to put data into
8080
*/
8181
static void
82-
ice_fwlog_print_module_cfg(struct ice_hw *hw, int module, struct seq_file *s)
82+
ice_fwlog_print_module_cfg(struct ice_fwlog_cfg *cfg, int module,
83+
struct seq_file *s)
8384
{
84-
struct ice_fwlog_cfg *cfg = &hw->fwlog.cfg;
8585
struct ice_fwlog_module_entry *entry;
8686

8787
if (module != ICE_AQC_FW_LOG_ID_MAX) {
@@ -103,14 +103,14 @@ ice_fwlog_print_module_cfg(struct ice_hw *hw, int module, struct seq_file *s)
103103
}
104104
}
105105

106-
static int ice_find_module_by_dentry(struct ice_pf *pf, struct dentry *d)
106+
static int ice_find_module_by_dentry(struct dentry **modules, struct dentry *d)
107107
{
108108
int i, module;
109109

110110
module = -1;
111111
/* find the module based on the dentry */
112112
for (i = 0; i < ICE_NR_FW_LOG_MODULES; i++) {
113-
if (d == pf->ice_debugfs_pf_fwlog_modules[i]) {
113+
if (d == modules[i]) {
114114
module = i;
115115
break;
116116
}
@@ -126,21 +126,20 @@ static int ice_find_module_by_dentry(struct ice_pf *pf, struct dentry *d)
126126
*/
127127
static int ice_debugfs_module_show(struct seq_file *s, void *v)
128128
{
129+
struct ice_fwlog *fwlog = s->private;
129130
const struct file *filp = s->file;
130131
struct dentry *dentry;
131-
struct ice_pf *pf;
132132
int module;
133133

134134
dentry = file_dentry(filp);
135-
pf = s->private;
136135

137-
module = ice_find_module_by_dentry(pf, dentry);
136+
module = ice_find_module_by_dentry(fwlog->debugfs_modules, dentry);
138137
if (module < 0) {
139-
dev_info(ice_pf_to_dev(pf), "unknown module\n");
138+
dev_info(&fwlog->pdev->dev, "unknown module\n");
140139
return -EINVAL;
141140
}
142141

143-
ice_fwlog_print_module_cfg(&pf->hw, module, s);
142+
ice_fwlog_print_module_cfg(&fwlog->cfg, module, s);
144143

145144
return 0;
146145
}
@@ -161,10 +160,9 @@ static ssize_t
161160
ice_debugfs_module_write(struct file *filp, const char __user *buf,
162161
size_t count, loff_t *ppos)
163162
{
164-
struct ice_pf *pf = file_inode(filp)->i_private;
163+
struct ice_fwlog *fwlog = file_inode(filp)->i_private;
165164
struct dentry *dentry = file_dentry(filp);
166-
struct device *dev = ice_pf_to_dev(pf);
167-
struct ice_hw *hw = &pf->hw;
165+
struct device *dev = &fwlog->pdev->dev;
168166
char user_val[16], *cmd_buf;
169167
int module, log_level, cnt;
170168

@@ -176,7 +174,7 @@ ice_debugfs_module_write(struct file *filp, const char __user *buf,
176174
if (IS_ERR(cmd_buf))
177175
return PTR_ERR(cmd_buf);
178176

179-
module = ice_find_module_by_dentry(pf, dentry);
177+
module = ice_find_module_by_dentry(fwlog->debugfs_modules, dentry);
180178
if (module < 0) {
181179
dev_info(dev, "unknown module\n");
182180
return -EINVAL;
@@ -193,15 +191,15 @@ ice_debugfs_module_write(struct file *filp, const char __user *buf,
193191
}
194192

195193
if (module != ICE_AQC_FW_LOG_ID_MAX) {
196-
hw->fwlog.cfg.module_entries[module].log_level = log_level;
194+
fwlog->cfg.module_entries[module].log_level = log_level;
197195
} else {
198196
/* the module 'all' is a shortcut so that we can set
199197
* all of the modules to the same level quickly
200198
*/
201199
int i;
202200

203201
for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++)
204-
hw->fwlog.cfg.module_entries[i].log_level = log_level;
202+
fwlog->cfg.module_entries[i].log_level = log_level;
205203
}
206204

207205
return count;
@@ -226,12 +224,11 @@ static ssize_t ice_debugfs_nr_messages_read(struct file *filp,
226224
char __user *buffer, size_t count,
227225
loff_t *ppos)
228226
{
229-
struct ice_pf *pf = filp->private_data;
230-
struct ice_hw *hw = &pf->hw;
227+
struct ice_fwlog *fwlog = filp->private_data;
231228
char buff[32] = {};
232229

233230
snprintf(buff, sizeof(buff), "%d\n",
234-
hw->fwlog.cfg.log_resolution);
231+
fwlog->cfg.log_resolution);
235232

236233
return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
237234
}
@@ -247,9 +244,8 @@ static ssize_t
247244
ice_debugfs_nr_messages_write(struct file *filp, const char __user *buf,
248245
size_t count, loff_t *ppos)
249246
{
250-
struct ice_pf *pf = filp->private_data;
251-
struct device *dev = ice_pf_to_dev(pf);
252-
struct ice_hw *hw = &pf->hw;
247+
struct ice_fwlog *fwlog = filp->private_data;
248+
struct device *dev = &fwlog->pdev->dev;
253249
char user_val[8], *cmd_buf;
254250
s16 nr_messages;
255251
ssize_t ret;
@@ -278,7 +274,7 @@ ice_debugfs_nr_messages_write(struct file *filp, const char __user *buf,
278274
return -EINVAL;
279275
}
280276

281-
hw->fwlog.cfg.log_resolution = nr_messages;
277+
fwlog->cfg.log_resolution = nr_messages;
282278

283279
return count;
284280
}
@@ -301,12 +297,11 @@ static ssize_t ice_debugfs_enable_read(struct file *filp,
301297
char __user *buffer, size_t count,
302298
loff_t *ppos)
303299
{
304-
struct ice_pf *pf = filp->private_data;
305-
struct ice_hw *hw = &pf->hw;
300+
struct ice_fwlog *fwlog = filp->private_data;
306301
char buff[32] = {};
307302

308303
snprintf(buff, sizeof(buff), "%u\n",
309-
(u16)(hw->fwlog.cfg.options &
304+
(u16)(fwlog->cfg.options &
310305
ICE_FWLOG_OPTION_IS_REGISTERED) >> 3);
311306

312307
return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
@@ -323,8 +318,7 @@ static ssize_t
323318
ice_debugfs_enable_write(struct file *filp, const char __user *buf,
324319
size_t count, loff_t *ppos)
325320
{
326-
struct ice_pf *pf = filp->private_data;
327-
struct ice_hw *hw = &pf->hw;
321+
struct ice_fwlog *fwlog = filp->private_data;
328322
char user_val[8], *cmd_buf;
329323
bool enable;
330324
ssize_t ret;
@@ -346,18 +340,18 @@ ice_debugfs_enable_write(struct file *filp, const char __user *buf,
346340
goto enable_write_error;
347341

348342
if (enable)
349-
hw->fwlog.cfg.options |= ICE_FWLOG_OPTION_ARQ_ENA;
343+
fwlog->cfg.options |= ICE_FWLOG_OPTION_ARQ_ENA;
350344
else
351-
hw->fwlog.cfg.options &= ~ICE_FWLOG_OPTION_ARQ_ENA;
345+
fwlog->cfg.options &= ~ICE_FWLOG_OPTION_ARQ_ENA;
352346

353-
ret = ice_fwlog_set(&hw->fwlog, &hw->fwlog.cfg);
347+
ret = ice_fwlog_set(fwlog, &fwlog->cfg);
354348
if (ret)
355349
goto enable_write_error;
356350

357351
if (enable)
358-
ret = ice_fwlog_register(&hw->fwlog);
352+
ret = ice_fwlog_register(fwlog);
359353
else
360-
ret = ice_fwlog_unregister(&hw->fwlog);
354+
ret = ice_fwlog_unregister(fwlog);
361355

362356
if (ret)
363357
goto enable_write_error;
@@ -396,12 +390,11 @@ static ssize_t ice_debugfs_log_size_read(struct file *filp,
396390
char __user *buffer, size_t count,
397391
loff_t *ppos)
398392
{
399-
struct ice_pf *pf = filp->private_data;
400-
struct ice_hw *hw = &pf->hw;
393+
struct ice_fwlog *fwlog = filp->private_data;
401394
char buff[32] = {};
402395
int index;
403396

404-
index = hw->fwlog.ring.index;
397+
index = fwlog->ring.index;
405398
snprintf(buff, sizeof(buff), "%s\n", ice_fwlog_log_size[index]);
406399

407400
return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
@@ -418,9 +411,8 @@ static ssize_t
418411
ice_debugfs_log_size_write(struct file *filp, const char __user *buf,
419412
size_t count, loff_t *ppos)
420413
{
421-
struct ice_pf *pf = filp->private_data;
422-
struct device *dev = ice_pf_to_dev(pf);
423-
struct ice_hw *hw = &pf->hw;
414+
struct ice_fwlog *fwlog = filp->private_data;
415+
struct device *dev = &fwlog->pdev->dev;
424416
char user_val[8], *cmd_buf;
425417
ssize_t ret;
426418
int index;
@@ -443,14 +435,14 @@ ice_debugfs_log_size_write(struct file *filp, const char __user *buf,
443435
user_val);
444436
ret = -EINVAL;
445437
goto log_size_write_error;
446-
} else if (hw->fwlog.cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED) {
438+
} else if (fwlog->cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED) {
447439
dev_info(dev, "FW logging is currently running. Please disable FW logging to change log_size\n");
448440
ret = -EINVAL;
449441
goto log_size_write_error;
450442
}
451443

452444
/* free all the buffers and the tracking info and resize */
453-
ice_fwlog_realloc_rings(&hw->fwlog, index);
445+
ice_fwlog_realloc_rings(fwlog, index);
454446

455447
/* if we get here, nothing went wrong; return count since we didn't
456448
* really write anything
@@ -485,19 +477,18 @@ static const struct file_operations ice_debugfs_log_size_fops = {
485477
static ssize_t ice_debugfs_data_read(struct file *filp, char __user *buffer,
486478
size_t count, loff_t *ppos)
487479
{
488-
struct ice_pf *pf = filp->private_data;
489-
struct ice_hw *hw = &pf->hw;
480+
struct ice_fwlog *fwlog = filp->private_data;
490481
int data_copied = 0;
491482
bool done = false;
492483

493-
if (ice_fwlog_ring_empty(&hw->fwlog.ring))
484+
if (ice_fwlog_ring_empty(&fwlog->ring))
494485
return 0;
495486

496-
while (!ice_fwlog_ring_empty(&hw->fwlog.ring) && !done) {
487+
while (!ice_fwlog_ring_empty(&fwlog->ring) && !done) {
497488
struct ice_fwlog_data *log;
498489
u16 cur_buf_len;
499490

500-
log = &hw->fwlog.ring.rings[hw->fwlog.ring.head];
491+
log = &fwlog->ring.rings[fwlog->ring.head];
501492
cur_buf_len = log->data_size;
502493
if (cur_buf_len >= count) {
503494
done = true;
@@ -516,8 +507,7 @@ static ssize_t ice_debugfs_data_read(struct file *filp, char __user *buffer,
516507
buffer += cur_buf_len;
517508
count -= cur_buf_len;
518509
*ppos += cur_buf_len;
519-
ice_fwlog_ring_increment(&hw->fwlog.ring.head,
520-
hw->fwlog.ring.size);
510+
ice_fwlog_ring_increment(&fwlog->ring.head, fwlog->ring.size);
521511
}
522512

523513
return data_copied;
@@ -534,9 +524,8 @@ static ssize_t
534524
ice_debugfs_data_write(struct file *filp, const char __user *buf, size_t count,
535525
loff_t *ppos)
536526
{
537-
struct ice_pf *pf = filp->private_data;
538-
struct device *dev = ice_pf_to_dev(pf);
539-
struct ice_hw *hw = &pf->hw;
527+
struct ice_fwlog *fwlog = filp->private_data;
528+
struct device *dev = &fwlog->pdev->dev;
540529
ssize_t ret;
541530

542531
/* don't allow partial writes */
@@ -546,9 +535,9 @@ ice_debugfs_data_write(struct file *filp, const char __user *buf, size_t count,
546535
/* any value is allowed to clear the buffer so no need to even look at
547536
* what the value is
548537
*/
549-
if (!(hw->fwlog.cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED)) {
550-
hw->fwlog.ring.head = 0;
551-
hw->fwlog.ring.tail = 0;
538+
if (!(fwlog->cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED)) {
539+
fwlog->ring.head = 0;
540+
fwlog->ring.tail = 0;
552541
} else {
553542
dev_info(dev, "Can't clear FW log data while FW log running\n");
554543
ret = -EINVAL;
@@ -580,9 +569,10 @@ static const struct file_operations ice_debugfs_data_fops = {
580569

581570
/**
582571
* ice_debugfs_fwlog_init - setup the debugfs directory
583-
* @pf: the ice that is starting up
572+
* @fwlog: pointer to the fwlog structure
573+
* @root: debugfs root entry on which fwlog director will be registered
584574
*/
585-
void ice_debugfs_fwlog_init(struct ice_pf *pf)
575+
void ice_debugfs_fwlog_init(struct ice_fwlog *fwlog, struct dentry *root)
586576
{
587577
struct dentry *fw_modules_dir;
588578
struct dentry **fw_modules;
@@ -596,43 +586,40 @@ void ice_debugfs_fwlog_init(struct ice_pf *pf)
596586
if (!fw_modules)
597587
return;
598588

599-
pf->ice_debugfs_pf_fwlog = debugfs_create_dir("fwlog",
600-
pf->ice_debugfs_pf);
601-
if (IS_ERR(pf->ice_debugfs_pf_fwlog))
589+
fwlog->debugfs = debugfs_create_dir("fwlog", root);
590+
if (IS_ERR(fwlog->debugfs))
602591
goto err_create_module_files;
603592

604-
fw_modules_dir = debugfs_create_dir("modules",
605-
pf->ice_debugfs_pf_fwlog);
593+
fw_modules_dir = debugfs_create_dir("modules", fwlog->debugfs);
606594
if (IS_ERR(fw_modules_dir))
607595
goto err_create_module_files;
608596

609597
for (i = 0; i < ICE_NR_FW_LOG_MODULES; i++) {
610598
fw_modules[i] = debugfs_create_file(ice_fwlog_module_string[i],
611-
0600, fw_modules_dir, pf,
599+
0600, fw_modules_dir, fwlog,
612600
&ice_debugfs_module_fops);
613601
if (IS_ERR(fw_modules[i]))
614602
goto err_create_module_files;
615603
}
616604

617-
debugfs_create_file("nr_messages", 0600,
618-
pf->ice_debugfs_pf_fwlog, pf,
605+
debugfs_create_file("nr_messages", 0600, fwlog->debugfs, fwlog,
619606
&ice_debugfs_nr_messages_fops);
620607

621-
pf->ice_debugfs_pf_fwlog_modules = fw_modules;
608+
fwlog->debugfs_modules = fw_modules;
622609

623-
debugfs_create_file("enable", 0600, pf->ice_debugfs_pf_fwlog,
624-
pf, &ice_debugfs_enable_fops);
610+
debugfs_create_file("enable", 0600, fwlog->debugfs, fwlog,
611+
&ice_debugfs_enable_fops);
625612

626-
debugfs_create_file("log_size", 0600, pf->ice_debugfs_pf_fwlog,
627-
pf, &ice_debugfs_log_size_fops);
613+
debugfs_create_file("log_size", 0600, fwlog->debugfs, fwlog,
614+
&ice_debugfs_log_size_fops);
628615

629-
debugfs_create_file("data", 0600, pf->ice_debugfs_pf_fwlog,
630-
pf, &ice_debugfs_data_fops);
616+
debugfs_create_file("data", 0600, fwlog->debugfs, fwlog,
617+
&ice_debugfs_data_fops);
631618

632619
return;
633620

634621
err_create_module_files:
635-
debugfs_remove_recursive(pf->ice_debugfs_pf_fwlog);
622+
debugfs_remove_recursive(fwlog->debugfs);
636623
kfree(fw_modules);
637624
}
638625

0 commit comments

Comments
 (0)