Path: blob/main/sys/contrib/dev/iwlwifi/mld/debugfs.h
48285 views
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */1/*2* Copyright (C) 2024-2025 Intel Corporation3*/4#include "iface.h"5#include "sta.h"67#define MLD_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \8struct dbgfs_##name##_data { \9argtype *arg; \10bool read_done; \11ssize_t rlen; \12char buf[buflen]; \13}; \14static int _iwl_dbgfs_##name##_open(struct inode *inode, \15struct file *file) \16{ \17struct dbgfs_##name##_data *data; \18\19if ((file->f_flags & O_ACCMODE) == O_RDWR) \20return -EOPNOTSUPP; \21\22data = kzalloc(sizeof(*data), GFP_KERNEL); \23if (!data) \24return -ENOMEM; \25\26data->read_done = false; \27data->arg = inode->i_private; \28file->private_data = data; \29\30return 0; \31}3233#define MLD_DEBUGFS_READ_WRAPPER(name) \34static ssize_t _iwl_dbgfs_##name##_read(struct file *file, \35char __user *user_buf, \36size_t count, loff_t *ppos) \37{ \38struct dbgfs_##name##_data *data = file->private_data; \39\40if (!data->read_done) { \41data->read_done = true; \42data->rlen = iwl_dbgfs_##name##_read(data->arg, \43sizeof(data->buf),\44data->buf); \45} \46\47if (data->rlen < 0) \48return data->rlen; \49return simple_read_from_buffer(user_buf, count, ppos, \50data->buf, data->rlen); \51}5253static int _iwl_dbgfs_release(struct inode *inode, struct file *file)54{55kfree(file->private_data);56return 0;57}5859#define _MLD_DEBUGFS_READ_FILE_OPS(name, buflen, argtype) \60MLD_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \61MLD_DEBUGFS_READ_WRAPPER(name) \62static const struct file_operations iwl_dbgfs_##name##_ops = { \63.read = _iwl_dbgfs_##name##_read, \64.open = _iwl_dbgfs_##name##_open, \65.llseek = generic_file_llseek, \66.release = _iwl_dbgfs_release, \67}6869#define WIPHY_DEBUGFS_WRITE_HANDLER_WRAPPER(name) \70static ssize_t iwl_dbgfs_##name##_write_handler(struct wiphy *wiphy, \71struct file *file, char *buf, \72size_t count, void *data) \73{ \74struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); \75struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); \76return iwl_dbgfs_##name##_write(mld, buf, count, data); \77}7879static inline struct iwl_mld *80iwl_mld_from_link_sta(struct ieee80211_link_sta *link_sta)81{82struct ieee80211_vif *vif =83iwl_mld_sta_from_mac80211(link_sta->sta)->vif;84return iwl_mld_vif_from_mac80211(vif)->mld;85}8687static inline struct iwl_mld *88iwl_mld_from_bss_conf(struct ieee80211_bss_conf *link)89{90return iwl_mld_vif_from_mac80211(link->vif)->mld;91}9293static inline struct iwl_mld *iwl_mld_from_vif(struct ieee80211_vif *vif)94{95return iwl_mld_vif_from_mac80211(vif)->mld;96}9798#define WIPHY_DEBUGFS_WRITE_WRAPPER(name, bufsz, objtype) \99WIPHY_DEBUGFS_WRITE_HANDLER_WRAPPER(name) \100static ssize_t __iwl_dbgfs_##name##_write(struct file *file, \101const char __user *user_buf, \102size_t count, loff_t *ppos) \103{ \104struct ieee80211_##objtype *arg = file->private_data; \105struct iwl_mld *mld = iwl_mld_from_##objtype(arg); \106char buf[bufsz] = {}; \107\108return wiphy_locked_debugfs_write(mld->wiphy, file, \109buf, sizeof(buf), \110user_buf, count, \111iwl_dbgfs_##name##_write_handler, \112arg); \113}114115#define WIPHY_DEBUGFS_WRITE_FILE_OPS(name, bufsz, objtype) \116WIPHY_DEBUGFS_WRITE_WRAPPER(name, bufsz, objtype) \117static const struct file_operations iwl_dbgfs_##name##_ops = { \118.write = __iwl_dbgfs_##name##_write, \119.open = simple_open, \120.llseek = generic_file_llseek, \121}122123#define WIPHY_DEBUGFS_READ_HANDLER_WRAPPER_MLD(name) \124static ssize_t iwl_dbgfs_##name##_read_handler(struct wiphy *wiphy, \125struct file *file, char *buf, \126size_t count, void *data) \127{ \128struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); \129struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); \130return iwl_dbgfs_##name##_read(mld, buf, count); \131}132133#define WIPHY_DEBUGFS_WRITE_HANDLER_WRAPPER_MLD(name) \134static ssize_t iwl_dbgfs_##name##_write_handler(struct wiphy *wiphy, \135struct file *file, char *buf, \136size_t count, void *data) \137{ \138struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); \139struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); \140return iwl_dbgfs_##name##_write(mld, buf, count); \141}142143#define WIPHY_DEBUGFS_WRITE_WRAPPER_MLD(name) \144WIPHY_DEBUGFS_WRITE_HANDLER_WRAPPER_MLD(name) \145static ssize_t __iwl_dbgfs_##name##_write(struct file *file, \146const char __user *user_buf, \147size_t count, loff_t *ppos) \148{ \149struct dbgfs_##name##_data *data = file->private_data; \150struct iwl_mld *mld = data->arg; \151\152return wiphy_locked_debugfs_write(mld->wiphy, file, \153data->buf, sizeof(data->buf), \154user_buf, count, \155iwl_dbgfs_##name##_write_handler, \156NULL); \157}158159#define WIPHY_DEBUGFS_READ_WRAPPER_MLD(name) \160WIPHY_DEBUGFS_READ_HANDLER_WRAPPER_MLD(name) \161static ssize_t __iwl_dbgfs_##name##_read(struct file *file, \162char __user *user_buf, \163size_t count, loff_t *ppos) \164{ \165struct dbgfs_##name##_data *data = file->private_data; \166struct iwl_mld *mld = data->arg; \167\168if (!data->read_done) { \169data->read_done = true; \170data->rlen = wiphy_locked_debugfs_read(mld->wiphy, \171file, data->buf, sizeof(data->buf), \172user_buf, count, ppos, \173iwl_dbgfs_##name##_read_handler, NULL); \174return data->rlen; \175} \176\177if (data->rlen < 0) \178return data->rlen; \179return simple_read_from_buffer(user_buf, count, ppos, \180data->buf, data->rlen); \181}182183#define WIPHY_DEBUGFS_READ_FILE_OPS_MLD(name, bufsz) \184MLD_DEBUGFS_OPEN_WRAPPER(name, bufsz, struct iwl_mld) \185WIPHY_DEBUGFS_READ_WRAPPER_MLD(name) \186static const struct file_operations iwl_dbgfs_##name##_ops = { \187.read = __iwl_dbgfs_##name##_read, \188.open = _iwl_dbgfs_##name##_open, \189.llseek = generic_file_llseek, \190.release = _iwl_dbgfs_release, \191}192193#define WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(name, bufsz) \194MLD_DEBUGFS_OPEN_WRAPPER(name, bufsz, struct iwl_mld) \195WIPHY_DEBUGFS_WRITE_WRAPPER_MLD(name) \196static const struct file_operations iwl_dbgfs_##name##_ops = { \197.write = __iwl_dbgfs_##name##_write, \198.open = _iwl_dbgfs_##name##_open, \199.llseek = generic_file_llseek, \200.release = _iwl_dbgfs_release, \201}202203#define WIPHY_DEBUGFS_READ_WRITE_FILE_OPS_MLD(name, bufsz) \204MLD_DEBUGFS_OPEN_WRAPPER(name, bufsz, struct iwl_mld) \205WIPHY_DEBUGFS_WRITE_WRAPPER_MLD(name) \206WIPHY_DEBUGFS_READ_WRAPPER_MLD(name) \207static const struct file_operations iwl_dbgfs_##name##_ops = { \208.write = __iwl_dbgfs_##name##_write, \209.read = __iwl_dbgfs_##name##_read, \210.open = _iwl_dbgfs_##name##_open, \211.llseek = generic_file_llseek, \212.release = _iwl_dbgfs_release, \213}214215#define WIPHY_DEBUGFS_WRITE_WRAPPER_IEEE80211(name, bufsz, objtype) \216WIPHY_DEBUGFS_WRITE_HANDLER_WRAPPER(name) \217static ssize_t _iwl_dbgfs_##name##_write(struct file *file, \218const char __user *user_buf, \219size_t count, loff_t *ppos) \220{ \221struct dbgfs_##name##_data *data = file->private_data; \222struct ieee80211_##objtype *arg = data->arg; \223struct iwl_mld *mld = iwl_mld_from_##objtype(arg); \224char buf[bufsz] = {}; \225\226return wiphy_locked_debugfs_write(mld->wiphy, file, \227buf, sizeof(buf), \228user_buf, count, \229iwl_dbgfs_##name##_write_handler, \230arg); \231}232233#define IEEE80211_WIPHY_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, objtype) \234MLD_DEBUGFS_OPEN_WRAPPER(name, bufsz, struct ieee80211_##objtype) \235WIPHY_DEBUGFS_WRITE_WRAPPER_IEEE80211(name, bufsz, objtype) \236MLD_DEBUGFS_READ_WRAPPER(name) \237static const struct file_operations iwl_dbgfs_##name##_ops = { \238.write = _iwl_dbgfs_##name##_write, \239.read = _iwl_dbgfs_##name##_read, \240.open = _iwl_dbgfs_##name##_open, \241.llseek = generic_file_llseek, \242.release = _iwl_dbgfs_release, \243}244245246