diff options
author | Jade Bilkey <herself@thefumon.com> | 2014-08-30 15:14:14 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2014-09-04 13:50:12 -0400 |
commit | db906eb2101b0564b0c65edf4a8647395196342e (patch) | |
tree | bf20ebd6a42cbdb23ad14c449fcccc23e0a71ace | |
parent | 87fed556d08d21dd7dd3e0222c94c187e4c2d5e2 (diff) |
ath5k: added debugfs file for dumping eeprom
Signed-off-by: Jade Bilkey <herself@thefumon.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/ath/ath5k/debug.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c index b8d031ae63c2..30e4e1fd4b04 100644 --- a/drivers/net/wireless/ath/ath5k/debug.c +++ b/drivers/net/wireless/ath/ath5k/debug.c | |||
@@ -894,6 +894,100 @@ static const struct file_operations fops_queue = { | |||
894 | .llseek = default_llseek, | 894 | .llseek = default_llseek, |
895 | }; | 895 | }; |
896 | 896 | ||
897 | /* debugfs: eeprom */ | ||
898 | |||
899 | struct eeprom_private { | ||
900 | u16 *buf; | ||
901 | int len; | ||
902 | }; | ||
903 | |||
904 | static int open_file_eeprom(struct inode *inode, struct file *file) | ||
905 | { | ||
906 | struct eeprom_private *ep; | ||
907 | struct ath5k_hw *ah = inode->i_private; | ||
908 | bool res; | ||
909 | int i, ret; | ||
910 | u32 eesize; | ||
911 | u16 val, *buf; | ||
912 | |||
913 | /* Get eeprom size */ | ||
914 | |||
915 | res = ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_UPPER, &val); | ||
916 | if (!res) | ||
917 | return -EACCES; | ||
918 | |||
919 | if (val == 0) { | ||
920 | eesize = AR5K_EEPROM_INFO_MAX + AR5K_EEPROM_INFO_BASE; | ||
921 | } else { | ||
922 | eesize = (val & AR5K_EEPROM_SIZE_UPPER_MASK) << | ||
923 | AR5K_EEPROM_SIZE_ENDLOC_SHIFT; | ||
924 | ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_LOWER, &val); | ||
925 | eesize = eesize | val; | ||
926 | } | ||
927 | |||
928 | if (eesize > 4096) | ||
929 | return -EINVAL; | ||
930 | |||
931 | /* Create buffer and read in eeprom */ | ||
932 | |||
933 | buf = vmalloc(eesize); | ||
934 | if (!buf) { | ||
935 | ret = -ENOMEM; | ||
936 | goto err; | ||
937 | } | ||
938 | |||
939 | for (i = 0; i < eesize; ++i) { | ||
940 | AR5K_EEPROM_READ(i, val); | ||
941 | buf[i] = val; | ||
942 | } | ||
943 | |||
944 | /* Create private struct and assign to file */ | ||
945 | |||
946 | ep = kmalloc(sizeof(*ep), GFP_KERNEL); | ||
947 | if (!ep) { | ||
948 | ret = -ENOMEM; | ||
949 | goto freebuf; | ||
950 | } | ||
951 | |||
952 | ep->buf = buf; | ||
953 | ep->len = i; | ||
954 | |||
955 | file->private_data = (void *)ep; | ||
956 | |||
957 | return 0; | ||
958 | |||
959 | freebuf: | ||
960 | vfree(buf); | ||
961 | err: | ||
962 | return ret; | ||
963 | |||
964 | } | ||
965 | |||
966 | static ssize_t read_file_eeprom(struct file *file, char __user *user_buf, | ||
967 | size_t count, loff_t *ppos) | ||
968 | { | ||
969 | struct eeprom_private *ep = file->private_data; | ||
970 | |||
971 | return simple_read_from_buffer(user_buf, count, ppos, ep->buf, ep->len); | ||
972 | } | ||
973 | |||
974 | static int release_file_eeprom(struct inode *inode, struct file *file) | ||
975 | { | ||
976 | struct eeprom_private *ep = file->private_data; | ||
977 | |||
978 | vfree(ep->buf); | ||
979 | kfree(ep); | ||
980 | |||
981 | return 0; | ||
982 | } | ||
983 | |||
984 | static const struct file_operations fops_eeprom = { | ||
985 | .open = open_file_eeprom, | ||
986 | .read = read_file_eeprom, | ||
987 | .release = release_file_eeprom, | ||
988 | .owner = THIS_MODULE, | ||
989 | }; | ||
990 | |||
897 | 991 | ||
898 | void | 992 | void |
899 | ath5k_debug_init_device(struct ath5k_hw *ah) | 993 | ath5k_debug_init_device(struct ath5k_hw *ah) |
@@ -921,6 +1015,8 @@ ath5k_debug_init_device(struct ath5k_hw *ah) | |||
921 | 1015 | ||
922 | debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc); | 1016 | debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc); |
923 | 1017 | ||
1018 | debugfs_create_file("eeprom", S_IRUSR, phydir, ah, &fops_eeprom); | ||
1019 | |||
924 | debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah, | 1020 | debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah, |
925 | &fops_frameerrors); | 1021 | &fops_frameerrors); |
926 | 1022 | ||