Skip to content

Commit

Permalink
iwlwifi: rework the iwlwifi debugfs structure
Browse files Browse the repository at this point in the history
The generic part of the driver now creates all debugfs
directories. It creates a root directory directly in
the the root of the debugfs filesystem and within that
directories for each device, named after the device ID
of the devices iwlwifi is attached to.

In the cfg80211/mac80211 directory there's now a link
to the toplevel iwlwifi debugfs directory to make it
easier to find the debugfs files.

Signed-off-by: Meenakshi Venkataraman <meenakshi.venkataraman@intel.com>
Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Meenakshi Venkataraman authored and Johannes Berg committed Jul 26, 2012
1 parent 273a576 commit 9da987a
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 60 deletions.
9 changes: 3 additions & 6 deletions drivers/net/wireless/iwlwifi/dvm/agn.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,13 @@ static inline void iwl_dvm_set_pmi(struct iwl_priv *priv, bool state)
}

#ifdef CONFIG_IWLWIFI_DEBUGFS
int iwl_dbgfs_register(struct iwl_priv *priv, const char *name);
void iwl_dbgfs_unregister(struct iwl_priv *priv);
int iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir);
#else
static inline int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
static inline int iwl_dbgfs_register(struct iwl_priv *priv,
struct dentry *dbgfs_dir)
{
return 0;
}
static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
{
}
#endif /* CONFIG_IWLWIFI_DEBUGFS */

#ifdef CONFIG_IWLWIFI_DEBUG
Expand Down
56 changes: 28 additions & 28 deletions drivers/net/wireless/iwlwifi/dvm/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2349,24 +2349,19 @@ DEBUGFS_READ_WRITE_FILE_OPS(calib_disabled);
* Create the debugfs files and directories
*
*/
int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
int iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir)
{
struct dentry *phyd = priv->hw->wiphy->debugfsdir;
struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
struct dentry *dir_data, *dir_rf, *dir_debug;

dir_drv = debugfs_create_dir(name, phyd);
if (!dir_drv)
return -ENOMEM;

priv->debugfs_dir = dir_drv;
priv->debugfs_dir = dbgfs_dir;

dir_data = debugfs_create_dir("data", dir_drv);
dir_data = debugfs_create_dir("data", dbgfs_dir);
if (!dir_data)
goto err;
dir_rf = debugfs_create_dir("rf", dir_drv);
dir_rf = debugfs_create_dir("rf", dbgfs_dir);
if (!dir_rf)
goto err;
dir_debug = debugfs_create_dir("debug", dir_drv);
dir_debug = debugfs_create_dir("debug", dbgfs_dir);
if (!dir_debug)
goto err;

Expand Down Expand Up @@ -2412,25 +2407,30 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
/* Calibrations disabled/enabled status*/
DEBUGFS_ADD_FILE(calib_disabled, dir_rf, S_IWUSR | S_IRUSR);

if (iwl_trans_dbgfs_register(priv->trans, dir_debug))
goto err;
/*
* Create a symlink with mac80211. This is not very robust, as it does
* not remove the symlink created. The implicit assumption is that
* when the opmode exits, mac80211 will also exit, and will remove
* this symlink as part of its cleanup.
*/
if (priv->mac80211_registered) {
char buf[100];
struct dentry *mac80211_dir, *dev_dir, *root_dir;

dev_dir = dbgfs_dir->d_parent;
root_dir = dev_dir->d_parent;
mac80211_dir = priv->hw->wiphy->debugfsdir;

snprintf(buf, 100, "../../%s/%s", root_dir->d_name.name,
dev_dir->d_name.name);

if (!debugfs_create_symlink("iwlwifi", mac80211_dir, buf))
goto err;
}

return 0;

err:
IWL_ERR(priv, "Can't create the debugfs directory\n");
iwl_dbgfs_unregister(priv);
IWL_ERR(priv, "failed to create the dvm debugfs entries\n");
return -ENOMEM;
}

/**
* Remove the debugfs files and directories
*
*/
void iwl_dbgfs_unregister(struct iwl_priv *priv)
{
if (!priv->debugfs_dir)
return;

debugfs_remove_recursive(priv->debugfs_dir);
priv->debugfs_dir = NULL;
}
12 changes: 6 additions & 6 deletions drivers/net/wireless/iwlwifi/dvm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,8 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)

static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
const struct iwl_cfg *cfg,
const struct iwl_fw *fw)
const struct iwl_fw *fw,
struct dentry *dbgfs_dir)
{
struct iwl_priv *priv;
struct ieee80211_hw *hw;
Expand Down Expand Up @@ -1466,12 +1467,13 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
goto out_destroy_workqueue;

if (iwl_dbgfs_register(priv, DRV_NAME))
IWL_ERR(priv,
"failed to create debugfs files. Ignoring error\n");
if (iwl_dbgfs_register(priv, dbgfs_dir))
goto out_mac80211_unregister;

return op_mode;

out_mac80211_unregister:
iwlagn_mac_unregister(priv);
out_destroy_workqueue:
iwl_tt_exit(priv);
iwl_testmode_free(priv);
Expand All @@ -1496,8 +1498,6 @@ static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)

IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");

iwl_dbgfs_unregister(priv);

iwl_testmode_free(priv);
iwlagn_mac_unregister(priv);

Expand Down
132 changes: 114 additions & 18 deletions drivers/net/wireless/iwlwifi/iwl-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ MODULE_VERSION(DRV_VERSION);
MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
MODULE_LICENSE("GPL");

#ifdef CONFIG_IWLWIFI_DEBUGFS
static struct dentry *iwl_dbgfs_root;
#endif

/**
* struct iwl_drv - drv common data
* @list: list of drv structures using this opmode
Expand All @@ -126,6 +130,12 @@ struct iwl_drv {
char firmware_name[25]; /* name of firmware file to load */

struct completion request_firmware_complete;

#ifdef CONFIG_IWLWIFI_DEBUGFS
struct dentry *dbgfs_drv;
struct dentry *dbgfs_trans;
struct dentry *dbgfs_op_mode;
#endif
};

#define DVM_OP_MODE 0
Expand Down Expand Up @@ -760,6 +770,50 @@ static int validate_sec_sizes(struct iwl_drv *drv,
return 0;
}

static struct iwl_op_mode *
_iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
{
const struct iwl_op_mode_ops *ops = op->ops;
struct dentry *dbgfs_dir = NULL;
struct iwl_op_mode *op_mode = NULL;

#ifdef CONFIG_IWLWIFI_DEBUGFS
drv->dbgfs_op_mode = debugfs_create_dir(op->name,
drv->dbgfs_drv);
if (!drv->dbgfs_op_mode) {
IWL_ERR(drv,
"failed to create opmode debugfs directory\n");
return op_mode;
}
dbgfs_dir = drv->dbgfs_op_mode;
#endif

op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);

#ifdef CONFIG_IWLWIFI_DEBUGFS
if (!op_mode) {
debugfs_remove_recursive(drv->dbgfs_op_mode);
drv->dbgfs_op_mode = NULL;
}
#endif

return op_mode;
}

static void _iwl_op_mode_stop(struct iwl_drv *drv)
{
/* op_mode can be NULL if its start failed */
if (drv->op_mode) {
iwl_op_mode_stop(drv->op_mode);
drv->op_mode = NULL;

#ifdef CONFIG_IWLWIFI_DEBUGFS
debugfs_remove_recursive(drv->dbgfs_op_mode);
drv->dbgfs_op_mode = NULL;
#endif
}
}

/**
* iwl_req_fw_callback - callback when firmware was loaded
*
Expand Down Expand Up @@ -909,8 +963,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
list_add_tail(&drv->list, &op->drv);

if (op->ops) {
const struct iwl_op_mode_ops *ops = op->ops;
drv->op_mode = ops->start(drv->trans, drv->cfg, &drv->fw);
drv->op_mode = _iwl_op_mode_start(drv, op);

if (!drv->op_mode) {
mutex_unlock(&iwlwifi_opmode_table_mtx);
Expand Down Expand Up @@ -970,24 +1023,51 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
init_completion(&drv->request_firmware_complete);
INIT_LIST_HEAD(&drv->list);

#ifdef CONFIG_IWLWIFI_DEBUGFS
/* Create the device debugfs entries. */
drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
iwl_dbgfs_root);

if (!drv->dbgfs_drv) {
IWL_ERR(drv, "failed to create debugfs directory\n");
goto err_free_drv;
}

/* Create transport layer debugfs dir */
drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);

if (!drv->trans->dbgfs_dir) {
IWL_ERR(drv, "failed to create transport debugfs directory\n");
goto err_free_dbgfs;
}
#endif

ret = iwl_request_firmware(drv, true);

if (ret) {
IWL_ERR(trans, "Couldn't request the fw\n");
kfree(drv);
drv = NULL;
goto err_fw;
}

return drv;

err_fw:
#ifdef CONFIG_IWLWIFI_DEBUGFS
err_free_dbgfs:
debugfs_remove_recursive(drv->dbgfs_drv);
err_free_drv:
#endif
kfree(drv);
drv = NULL;

return drv;
}

void iwl_drv_stop(struct iwl_drv *drv)
{
wait_for_completion(&drv->request_firmware_complete);

/* op_mode can be NULL if its start failed */
if (drv->op_mode)
iwl_op_mode_stop(drv->op_mode);
_iwl_op_mode_stop(drv);

iwl_dealloc_ucode(drv);

Expand All @@ -1001,6 +1081,10 @@ void iwl_drv_stop(struct iwl_drv *drv)
list_del(&drv->list);
mutex_unlock(&iwlwifi_opmode_table_mtx);

#ifdef CONFIG_IWLWIFI_DEBUGFS
debugfs_remove_recursive(drv->dbgfs_drv);
#endif

kfree(drv);
}

Expand All @@ -1023,15 +1107,18 @@ int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
{
int i;
struct iwl_drv *drv;
struct iwlwifi_opmode_table *op;

mutex_lock(&iwlwifi_opmode_table_mtx);
for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
if (strcmp(iwlwifi_opmode_table[i].name, name))
op = &iwlwifi_opmode_table[i];
if (strcmp(op->name, name))
continue;
iwlwifi_opmode_table[i].ops = ops;
list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
drv->op_mode = ops->start(drv->trans, drv->cfg,
&drv->fw);
op->ops = ops;
/* TODO: need to handle exceptional case */
list_for_each_entry(drv, &op->drv, list)
drv->op_mode = _iwl_op_mode_start(drv, op);

mutex_unlock(&iwlwifi_opmode_table_mtx);
return 0;
}
Expand All @@ -1052,12 +1139,9 @@ void iwl_opmode_deregister(const char *name)
iwlwifi_opmode_table[i].ops = NULL;

/* call the stop routine for all devices */
list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list) {
if (drv->op_mode) {
iwl_op_mode_stop(drv->op_mode);
drv->op_mode = NULL;
}
}
list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
_iwl_op_mode_stop(drv);

mutex_unlock(&iwlwifi_opmode_table_mtx);
return;
}
Expand All @@ -1077,13 +1161,25 @@ static int __init iwl_drv_init(void)
pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
pr_info(DRV_COPYRIGHT "\n");

#ifdef CONFIG_IWLWIFI_DEBUGFS
/* Create the root of iwlwifi debugfs subsystem. */
iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);

if (!iwl_dbgfs_root)
return -EFAULT;
#endif

return iwl_pci_register_driver();
}
module_init(iwl_drv_init);

static void __exit iwl_drv_exit(void)
{
iwl_pci_unregister_driver();

#ifdef CONFIG_IWLWIFI_DEBUGFS
debugfs_remove_recursive(iwl_dbgfs_root);
#endif
}
module_exit(iwl_drv_exit);

Expand Down
3 changes: 2 additions & 1 deletion drivers/net/wireless/iwlwifi/iwl-op-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ struct iwl_cfg;
struct iwl_op_mode_ops {
struct iwl_op_mode *(*start)(struct iwl_trans *trans,
const struct iwl_cfg *cfg,
const struct iwl_fw *fw);
const struct iwl_fw *fw,
struct dentry *dbgfs_dir);
void (*stop)(struct iwl_op_mode *op_mode);
int (*rx)(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
struct iwl_device_cmd *cmd);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/wireless/iwlwifi/iwl-trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ struct iwl_trans {
size_t dev_cmd_headroom;
char dev_cmd_pool_name[50];

struct dentry *dbgfs_dir;

/* pointer to trans specific struct */
/*Ensure that this pointer will always be aligned to sizeof pointer */
char trans_specific[0] __aligned(sizeof(void *));
Expand Down
6 changes: 6 additions & 0 deletions drivers/net/wireless/iwlwifi/pcie/drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,14 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (!trans_pcie->drv)
goto out_free_trans;

/* register transport layer debugfs here */
if (iwl_trans_dbgfs_register(iwl_trans, iwl_trans->dbgfs_dir))
goto out_free_drv;

return 0;

out_free_drv:
iwl_drv_stop(trans_pcie->drv);
out_free_trans:
iwl_trans_pcie_free(iwl_trans);
pci_set_drvdata(pdev, NULL);
Expand Down
Loading

0 comments on commit 9da987a

Please sign in to comment.