diff options
| author | David DSH <ddastoussthi@nvidia.com> | 2016-11-15 21:50:24 -0500 |
|---|---|---|
| committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-03-22 18:31:53 -0400 |
| commit | 03ab6394f1bf20e58ed437726f979366d0740de8 (patch) | |
| tree | 42b27ab8b97b2b3c64282f0396cfc0bbd5f21023 | |
| parent | 7028a106cd9f1e44d74ee26baf995d300d870362 (diff) | |
RT8168: Add power control sysfs knobs
Add low power modes control knobs via sysfs
Bug 1828585
Change-Id: If9fbd678399c811177f4550f54ef7be88070b795
Signed-off-by: David DSH <ddastoussthi@nvidia.com>
Reviewed-on: http://git-master/r/1254366
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vinayak Pane <vpane@nvidia.com>
Signed-off-by: Vladislav Zhurba <vzhurba@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1679175
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
| -rw-r--r-- | drivers/net/ethernet/realtek/r8168_n.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/drivers/net/ethernet/realtek/r8168_n.c b/drivers/net/ethernet/realtek/r8168_n.c index 31b4a5cfd..53f2627e6 100644 --- a/drivers/net/ethernet/realtek/r8168_n.c +++ b/drivers/net/ethernet/realtek/r8168_n.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | * This driver is modified from r8169.c in Linux kernel 2.6.18 | 35 | * This driver is modified from r8169.c in Linux kernel 2.6.18 |
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | #include <linux/kernel.h> | ||
| 38 | #include <linux/module.h> | 39 | #include <linux/module.h> |
| 39 | #include <linux/version.h> | 40 | #include <linux/version.h> |
| 40 | #include <linux/pci.h> | 41 | #include <linux/pci.h> |
| @@ -681,6 +682,92 @@ struct rtl8168_counters { | |||
| 681 | u16 tx_underun; | 682 | u16 tx_underun; |
| 682 | }; | 683 | }; |
| 683 | 684 | ||
| 685 | /* SysFS node */ | ||
| 686 | static int power_saver_flag; | ||
| 687 | static struct kobject *rt8168_ps_kobj; | ||
| 688 | static ssize_t show_power_saver(struct kobject *dev, | ||
| 689 | struct kobj_attribute *attr, char *buf) { | ||
| 690 | ssize_t ret; | ||
| 691 | ret = snprintf(buf, PAGE_SIZE, "%u\n", power_saver_flag); | ||
| 692 | return ret; | ||
| 693 | } | ||
| 694 | |||
| 695 | static ssize_t set_power_saver(struct kobject *dev, | ||
| 696 | struct kobj_attribute *attr, const char *buf, size_t count) { | ||
| 697 | sscanf(buf, "%d", &power_saver_flag); | ||
| 698 | |||
| 699 | if (!power_saver_flag) { | ||
| 700 | pr_debug("rt8168_power mode is set to big spender"); | ||
| 701 | aspm = 0; | ||
| 702 | s5wol = 0; | ||
| 703 | eee_enable = 0; | ||
| 704 | } else { | ||
| 705 | pr_debug("rt8168_power mode is set to no waste"); | ||
| 706 | #ifdef CONFIG_R8168_ASPM | ||
| 707 | aspm = 1; | ||
| 708 | #else | ||
| 709 | aspm = 0; | ||
| 710 | #endif | ||
| 711 | #ifdef CONFIG_R8168_S5WOL | ||
| 712 | s5wol = 1; | ||
| 713 | #else | ||
| 714 | s5wol = 0; | ||
| 715 | #endif | ||
| 716 | #ifdef ENABLE_EEE | ||
| 717 | eee_enable = 1; | ||
| 718 | #else | ||
| 719 | eee_enable = 0; | ||
| 720 | #endif | ||
| 721 | } | ||
| 722 | |||
| 723 | return count; | ||
| 724 | } | ||
| 725 | |||
| 726 | static const struct kobj_attribute rt8168_psaver_attr[] = { | ||
| 727 | __ATTR(mode, S_IRUGO | S_IWUSR | S_IWGRP, show_power_saver, set_power_saver), | ||
| 728 | }; | ||
| 729 | |||
| 730 | static int rtl8168_sysfs_register(void) | ||
| 731 | { | ||
| 732 | int ret, i; | ||
| 733 | |||
| 734 | if (!kernel_kobj) { | ||
| 735 | pr_err("kernel_kobj is NULL\n"); | ||
| 736 | return -1; | ||
| 737 | } | ||
| 738 | |||
| 739 | rt8168_ps_kobj = kobject_create_and_add("rt8168_power", kernel_kobj); | ||
| 740 | |||
| 741 | if (!rt8168_ps_kobj) { | ||
| 742 | pr_err("unable to create rt8168_power_saver kernel object!\n"); | ||
| 743 | return -1; | ||
| 744 | } | ||
| 745 | |||
| 746 | for (i = 0; i < ARRAY_SIZE(rt8168_psaver_attr); i++) { | ||
| 747 | ret = sysfs_create_file(rt8168_ps_kobj, | ||
| 748 | &rt8168_psaver_attr[i].attr); | ||
| 749 | |||
| 750 | if (ret) | ||
| 751 | pr_err("failed to create %s\n", | ||
| 752 | rt8168_psaver_attr[i].attr.name); | ||
| 753 | } | ||
| 754 | |||
| 755 | return ret; | ||
| 756 | } | ||
| 757 | |||
| 758 | static int rtl8168_sysfs_remove(void) | ||
| 759 | { | ||
| 760 | int i; | ||
| 761 | |||
| 762 | if (!rt8168_ps_kobj) | ||
| 763 | return -1; | ||
| 764 | |||
| 765 | for (i = 0; i < ARRAY_SIZE(rt8168_psaver_attr); i++) | ||
| 766 | sysfs_remove_file(rt8168_ps_kobj, &rt8168_psaver_attr[i].attr); | ||
| 767 | |||
| 768 | return 0; | ||
| 769 | } | ||
| 770 | |||
| 684 | #ifdef ENABLE_R8168_PROCFS | 771 | #ifdef ENABLE_R8168_PROCFS |
| 685 | /**************************************************************************** | 772 | /**************************************************************************** |
| 686 | * -----------------------------PROCFS STUFF------------------------- | 773 | * -----------------------------PROCFS STUFF------------------------- |
| @@ -25066,6 +25153,7 @@ rtl8168_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
| 25066 | } | 25153 | } |
| 25067 | 25154 | ||
| 25068 | printk(KERN_INFO "%s: This product is covered by one or more of the following patents: US6,570,884, US6,115,776, and US6,327,625.\n", MODULENAME); | 25155 | printk(KERN_INFO "%s: This product is covered by one or more of the following patents: US6,570,884, US6,115,776, and US6,327,625.\n", MODULENAME); |
| 25156 | rtl8168_sysfs_register(); | ||
| 25069 | 25157 | ||
| 25070 | device_set_wakeup_enable(&pdev->dev, tp->wol_enabled); | 25158 | device_set_wakeup_enable(&pdev->dev, tp->wol_enabled); |
| 25071 | 25159 | ||
| @@ -25103,6 +25191,7 @@ void __devexit rtl8168_remove_one(struct pci_dev *pdev) | |||
| 25103 | #ifdef CONFIG_R8168_NAPI | 25191 | #ifdef CONFIG_R8168_NAPI |
| 25104 | RTL_NAPI_DEL(tp); | 25192 | RTL_NAPI_DEL(tp); |
| 25105 | #endif | 25193 | #endif |
| 25194 | rtl8168_sysfs_remove(); | ||
| 25106 | if (tp->DASH) | 25195 | if (tp->DASH) |
| 25107 | rtl8168_driver_stop(tp); | 25196 | rtl8168_driver_stop(tp); |
| 25108 | 25197 | ||
