diff options
author | Ivo van Doorn <IvDoorn@gmail.com> | 2008-06-03 12:58:56 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-06-14 12:17:55 -0400 |
commit | 2b08da3fb595432f87b5206c1c77dcb72300cacf (patch) | |
tree | b165baf29c47a5e58ac7f9d755942aca5d519614 /drivers/net | |
parent | 9dad92b9ba49eaab72513d821ae43298bcf93b90 (diff) |
rt2x00: Cleanup/optimize set_state() function callback function
* Reduce goto usage
* Mark if-statements which are true on hardware error unlikely()
* Cleanup debug messages
This makes the code look nicer and be better optimized since
the chance of hardware errors should be very small.
Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2400pci.c | 56 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2500pci.c | 56 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2500usb.c | 44 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00dev.c | 3 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt61pci.c | 61 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt73usb.c | 49 |
6 files changed, 140 insertions, 129 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c index 900140d3b304..cfb720f35b2c 100644 --- a/drivers/net/wireless/rt2x00/rt2400pci.c +++ b/drivers/net/wireless/rt2x00/rt2400pci.c | |||
@@ -781,25 +781,32 @@ static int rt2400pci_init_registers(struct rt2x00_dev *rt2x00dev) | |||
781 | return 0; | 781 | return 0; |
782 | } | 782 | } |
783 | 783 | ||
784 | static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev) | 784 | static int rt2400pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
785 | { | 785 | { |
786 | unsigned int i; | 786 | unsigned int i; |
787 | u16 eeprom; | ||
788 | u8 reg_id; | ||
789 | u8 value; | 787 | u8 value; |
790 | 788 | ||
791 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 789 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
792 | rt2400pci_bbp_read(rt2x00dev, 0, &value); | 790 | rt2400pci_bbp_read(rt2x00dev, 0, &value); |
793 | if ((value != 0xff) && (value != 0x00)) | 791 | if ((value != 0xff) && (value != 0x00)) |
794 | goto continue_csr_init; | 792 | return 0; |
795 | NOTICE(rt2x00dev, "Waiting for BBP register.\n"); | ||
796 | udelay(REGISTER_BUSY_DELAY); | 793 | udelay(REGISTER_BUSY_DELAY); |
797 | } | 794 | } |
798 | 795 | ||
799 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); | 796 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
800 | return -EACCES; | 797 | return -EACCES; |
798 | } | ||
799 | |||
800 | static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev) | ||
801 | { | ||
802 | unsigned int i; | ||
803 | u16 eeprom; | ||
804 | u8 reg_id; | ||
805 | u8 value; | ||
806 | |||
807 | if (unlikely(rt2400pci_wait_bbp_ready(rt2x00dev))) | ||
808 | return -EACCES; | ||
801 | 809 | ||
802 | continue_csr_init: | ||
803 | rt2400pci_bbp_write(rt2x00dev, 1, 0x00); | 810 | rt2400pci_bbp_write(rt2x00dev, 1, 0x00); |
804 | rt2400pci_bbp_write(rt2x00dev, 3, 0x27); | 811 | rt2400pci_bbp_write(rt2x00dev, 3, 0x27); |
805 | rt2400pci_bbp_write(rt2x00dev, 4, 0x08); | 812 | rt2400pci_bbp_write(rt2x00dev, 4, 0x08); |
@@ -838,7 +845,8 @@ static void rt2400pci_toggle_rx(struct rt2x00_dev *rt2x00dev, | |||
838 | 845 | ||
839 | rt2x00pci_register_read(rt2x00dev, RXCSR0, ®); | 846 | rt2x00pci_register_read(rt2x00dev, RXCSR0, ®); |
840 | rt2x00_set_field32(®, RXCSR0_DISABLE_RX, | 847 | rt2x00_set_field32(®, RXCSR0_DISABLE_RX, |
841 | state == STATE_RADIO_RX_OFF); | 848 | (state == STATE_RADIO_RX_OFF) || |
849 | (state == STATE_RADIO_RX_OFF_LINK)); | ||
842 | rt2x00pci_register_write(rt2x00dev, RXCSR0, reg); | 850 | rt2x00pci_register_write(rt2x00dev, RXCSR0, reg); |
843 | } | 851 | } |
844 | 852 | ||
@@ -875,17 +883,10 @@ static int rt2400pci_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
875 | /* | 883 | /* |
876 | * Initialize all registers. | 884 | * Initialize all registers. |
877 | */ | 885 | */ |
878 | if (rt2400pci_init_queues(rt2x00dev) || | 886 | if (unlikely(rt2400pci_init_queues(rt2x00dev) || |
879 | rt2400pci_init_registers(rt2x00dev) || | 887 | rt2400pci_init_registers(rt2x00dev) || |
880 | rt2400pci_init_bbp(rt2x00dev)) { | 888 | rt2400pci_init_bbp(rt2x00dev))) |
881 | ERROR(rt2x00dev, "Register initialization failed.\n"); | ||
882 | return -EIO; | 889 | return -EIO; |
883 | } | ||
884 | |||
885 | /* | ||
886 | * Enable interrupts. | ||
887 | */ | ||
888 | rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON); | ||
889 | 890 | ||
890 | return 0; | 891 | return 0; |
891 | } | 892 | } |
@@ -907,11 +908,6 @@ static void rt2400pci_disable_radio(struct rt2x00_dev *rt2x00dev) | |||
907 | rt2x00pci_register_read(rt2x00dev, TXCSR0, ®); | 908 | rt2x00pci_register_read(rt2x00dev, TXCSR0, ®); |
908 | rt2x00_set_field32(®, TXCSR0_ABORT, 1); | 909 | rt2x00_set_field32(®, TXCSR0_ABORT, 1); |
909 | rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); | 910 | rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); |
910 | |||
911 | /* | ||
912 | * Disable interrupts. | ||
913 | */ | ||
914 | rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF); | ||
915 | } | 911 | } |
916 | 912 | ||
917 | static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev, | 913 | static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev, |
@@ -946,10 +942,6 @@ static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev, | |||
946 | msleep(10); | 942 | msleep(10); |
947 | } | 943 | } |
948 | 944 | ||
949 | NOTICE(rt2x00dev, "Device failed to enter state %d, " | ||
950 | "current device state: bbp %d and rf %d.\n", | ||
951 | state, bbp_state, rf_state); | ||
952 | |||
953 | return -EBUSY; | 945 | return -EBUSY; |
954 | } | 946 | } |
955 | 947 | ||
@@ -967,11 +959,13 @@ static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
967 | break; | 959 | break; |
968 | case STATE_RADIO_RX_ON: | 960 | case STATE_RADIO_RX_ON: |
969 | case STATE_RADIO_RX_ON_LINK: | 961 | case STATE_RADIO_RX_ON_LINK: |
970 | rt2400pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); | ||
971 | break; | ||
972 | case STATE_RADIO_RX_OFF: | 962 | case STATE_RADIO_RX_OFF: |
973 | case STATE_RADIO_RX_OFF_LINK: | 963 | case STATE_RADIO_RX_OFF_LINK: |
974 | rt2400pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); | 964 | rt2400pci_toggle_rx(rt2x00dev, state); |
965 | break; | ||
966 | case STATE_RADIO_IRQ_ON: | ||
967 | case STATE_RADIO_IRQ_OFF: | ||
968 | rt2400pci_toggle_irq(rt2x00dev, state); | ||
975 | break; | 969 | break; |
976 | case STATE_DEEP_SLEEP: | 970 | case STATE_DEEP_SLEEP: |
977 | case STATE_SLEEP: | 971 | case STATE_SLEEP: |
@@ -984,6 +978,10 @@ static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
984 | break; | 978 | break; |
985 | } | 979 | } |
986 | 980 | ||
981 | if (unlikely(retval)) | ||
982 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", | ||
983 | state, retval); | ||
984 | |||
987 | return retval; | 985 | return retval; |
988 | } | 986 | } |
989 | 987 | ||
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c index 673350953b89..b08932d7bf20 100644 --- a/drivers/net/wireless/rt2x00/rt2500pci.c +++ b/drivers/net/wireless/rt2x00/rt2500pci.c | |||
@@ -924,25 +924,32 @@ static int rt2500pci_init_registers(struct rt2x00_dev *rt2x00dev) | |||
924 | return 0; | 924 | return 0; |
925 | } | 925 | } |
926 | 926 | ||
927 | static int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev) | 927 | static int rt2500pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
928 | { | 928 | { |
929 | unsigned int i; | 929 | unsigned int i; |
930 | u16 eeprom; | ||
931 | u8 reg_id; | ||
932 | u8 value; | 930 | u8 value; |
933 | 931 | ||
934 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 932 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
935 | rt2500pci_bbp_read(rt2x00dev, 0, &value); | 933 | rt2500pci_bbp_read(rt2x00dev, 0, &value); |
936 | if ((value != 0xff) && (value != 0x00)) | 934 | if ((value != 0xff) && (value != 0x00)) |
937 | goto continue_csr_init; | 935 | return 0; |
938 | NOTICE(rt2x00dev, "Waiting for BBP register.\n"); | ||
939 | udelay(REGISTER_BUSY_DELAY); | 936 | udelay(REGISTER_BUSY_DELAY); |
940 | } | 937 | } |
941 | 938 | ||
942 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); | 939 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
943 | return -EACCES; | 940 | return -EACCES; |
941 | } | ||
942 | |||
943 | static int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev) | ||
944 | { | ||
945 | unsigned int i; | ||
946 | u16 eeprom; | ||
947 | u8 reg_id; | ||
948 | u8 value; | ||
949 | |||
950 | if (unlikely(rt2500pci_wait_bbp_ready(rt2x00dev))) | ||
951 | return -EACCES; | ||
944 | 952 | ||
945 | continue_csr_init: | ||
946 | rt2500pci_bbp_write(rt2x00dev, 3, 0x02); | 953 | rt2500pci_bbp_write(rt2x00dev, 3, 0x02); |
947 | rt2500pci_bbp_write(rt2x00dev, 4, 0x19); | 954 | rt2500pci_bbp_write(rt2x00dev, 4, 0x19); |
948 | rt2500pci_bbp_write(rt2x00dev, 14, 0x1c); | 955 | rt2500pci_bbp_write(rt2x00dev, 14, 0x1c); |
@@ -997,7 +1004,8 @@ static void rt2500pci_toggle_rx(struct rt2x00_dev *rt2x00dev, | |||
997 | 1004 | ||
998 | rt2x00pci_register_read(rt2x00dev, RXCSR0, ®); | 1005 | rt2x00pci_register_read(rt2x00dev, RXCSR0, ®); |
999 | rt2x00_set_field32(®, RXCSR0_DISABLE_RX, | 1006 | rt2x00_set_field32(®, RXCSR0_DISABLE_RX, |
1000 | state == STATE_RADIO_RX_OFF); | 1007 | (state == STATE_RADIO_RX_OFF) || |
1008 | (state == STATE_RADIO_RX_OFF_LINK)); | ||
1001 | rt2x00pci_register_write(rt2x00dev, RXCSR0, reg); | 1009 | rt2x00pci_register_write(rt2x00dev, RXCSR0, reg); |
1002 | } | 1010 | } |
1003 | 1011 | ||
@@ -1034,17 +1042,10 @@ static int rt2500pci_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
1034 | /* | 1042 | /* |
1035 | * Initialize all registers. | 1043 | * Initialize all registers. |
1036 | */ | 1044 | */ |
1037 | if (rt2500pci_init_queues(rt2x00dev) || | 1045 | if (unlikely(rt2500pci_init_queues(rt2x00dev) || |
1038 | rt2500pci_init_registers(rt2x00dev) || | 1046 | rt2500pci_init_registers(rt2x00dev) || |
1039 | rt2500pci_init_bbp(rt2x00dev)) { | 1047 | rt2500pci_init_bbp(rt2x00dev))) |
1040 | ERROR(rt2x00dev, "Register initialization failed.\n"); | ||
1041 | return -EIO; | 1048 | return -EIO; |
1042 | } | ||
1043 | |||
1044 | /* | ||
1045 | * Enable interrupts. | ||
1046 | */ | ||
1047 | rt2500pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON); | ||
1048 | 1049 | ||
1049 | return 0; | 1050 | return 0; |
1050 | } | 1051 | } |
@@ -1066,11 +1067,6 @@ static void rt2500pci_disable_radio(struct rt2x00_dev *rt2x00dev) | |||
1066 | rt2x00pci_register_read(rt2x00dev, TXCSR0, ®); | 1067 | rt2x00pci_register_read(rt2x00dev, TXCSR0, ®); |
1067 | rt2x00_set_field32(®, TXCSR0_ABORT, 1); | 1068 | rt2x00_set_field32(®, TXCSR0_ABORT, 1); |
1068 | rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); | 1069 | rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); |
1069 | |||
1070 | /* | ||
1071 | * Disable interrupts. | ||
1072 | */ | ||
1073 | rt2500pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF); | ||
1074 | } | 1070 | } |
1075 | 1071 | ||
1076 | static int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev, | 1072 | static int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev, |
@@ -1105,10 +1101,6 @@ static int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev, | |||
1105 | msleep(10); | 1101 | msleep(10); |
1106 | } | 1102 | } |
1107 | 1103 | ||
1108 | NOTICE(rt2x00dev, "Device failed to enter state %d, " | ||
1109 | "current device state: bbp %d and rf %d.\n", | ||
1110 | state, bbp_state, rf_state); | ||
1111 | |||
1112 | return -EBUSY; | 1104 | return -EBUSY; |
1113 | } | 1105 | } |
1114 | 1106 | ||
@@ -1126,11 +1118,13 @@ static int rt2500pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1126 | break; | 1118 | break; |
1127 | case STATE_RADIO_RX_ON: | 1119 | case STATE_RADIO_RX_ON: |
1128 | case STATE_RADIO_RX_ON_LINK: | 1120 | case STATE_RADIO_RX_ON_LINK: |
1129 | rt2500pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); | ||
1130 | break; | ||
1131 | case STATE_RADIO_RX_OFF: | 1121 | case STATE_RADIO_RX_OFF: |
1132 | case STATE_RADIO_RX_OFF_LINK: | 1122 | case STATE_RADIO_RX_OFF_LINK: |
1133 | rt2500pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); | 1123 | rt2500pci_toggle_rx(rt2x00dev, state); |
1124 | break; | ||
1125 | case STATE_RADIO_IRQ_ON: | ||
1126 | case STATE_RADIO_IRQ_OFF: | ||
1127 | rt2500pci_toggle_irq(rt2x00dev, state); | ||
1134 | break; | 1128 | break; |
1135 | case STATE_DEEP_SLEEP: | 1129 | case STATE_DEEP_SLEEP: |
1136 | case STATE_SLEEP: | 1130 | case STATE_SLEEP: |
@@ -1143,6 +1137,10 @@ static int rt2500pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1143 | break; | 1137 | break; |
1144 | } | 1138 | } |
1145 | 1139 | ||
1140 | if (unlikely(retval)) | ||
1141 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", | ||
1142 | state, retval); | ||
1143 | |||
1146 | return retval; | 1144 | return retval; |
1147 | } | 1145 | } |
1148 | 1146 | ||
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c index cca1504550dc..a46e4a6eba96 100644 --- a/drivers/net/wireless/rt2x00/rt2500usb.c +++ b/drivers/net/wireless/rt2x00/rt2500usb.c | |||
@@ -847,25 +847,32 @@ static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev) | |||
847 | return 0; | 847 | return 0; |
848 | } | 848 | } |
849 | 849 | ||
850 | static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev) | 850 | static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
851 | { | 851 | { |
852 | unsigned int i; | 852 | unsigned int i; |
853 | u16 eeprom; | ||
854 | u8 value; | 853 | u8 value; |
855 | u8 reg_id; | ||
856 | 854 | ||
857 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 855 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
858 | rt2500usb_bbp_read(rt2x00dev, 0, &value); | 856 | rt2500usb_bbp_read(rt2x00dev, 0, &value); |
859 | if ((value != 0xff) && (value != 0x00)) | 857 | if ((value != 0xff) && (value != 0x00)) |
860 | goto continue_csr_init; | 858 | return 0; |
861 | NOTICE(rt2x00dev, "Waiting for BBP register.\n"); | ||
862 | udelay(REGISTER_BUSY_DELAY); | 859 | udelay(REGISTER_BUSY_DELAY); |
863 | } | 860 | } |
864 | 861 | ||
865 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); | 862 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
866 | return -EACCES; | 863 | return -EACCES; |
864 | } | ||
865 | |||
866 | static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev) | ||
867 | { | ||
868 | unsigned int i; | ||
869 | u16 eeprom; | ||
870 | u8 value; | ||
871 | u8 reg_id; | ||
872 | |||
873 | if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev))) | ||
874 | return -EACCES; | ||
867 | 875 | ||
868 | continue_csr_init: | ||
869 | rt2500usb_bbp_write(rt2x00dev, 3, 0x02); | 876 | rt2500usb_bbp_write(rt2x00dev, 3, 0x02); |
870 | rt2500usb_bbp_write(rt2x00dev, 4, 0x19); | 877 | rt2500usb_bbp_write(rt2x00dev, 4, 0x19); |
871 | rt2500usb_bbp_write(rt2x00dev, 14, 0x1c); | 878 | rt2500usb_bbp_write(rt2x00dev, 14, 0x1c); |
@@ -921,7 +928,8 @@ static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev, | |||
921 | 928 | ||
922 | rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®); | 929 | rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®); |
923 | rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX, | 930 | rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX, |
924 | state == STATE_RADIO_RX_OFF); | 931 | (state == STATE_RADIO_RX_OFF) || |
932 | (state == STATE_RADIO_RX_OFF_LINK)); | ||
925 | rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg); | 933 | rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg); |
926 | } | 934 | } |
927 | 935 | ||
@@ -930,11 +938,9 @@ static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
930 | /* | 938 | /* |
931 | * Initialize all registers. | 939 | * Initialize all registers. |
932 | */ | 940 | */ |
933 | if (rt2500usb_init_registers(rt2x00dev) || | 941 | if (unlikely(rt2500usb_init_registers(rt2x00dev) || |
934 | rt2500usb_init_bbp(rt2x00dev)) { | 942 | rt2500usb_init_bbp(rt2x00dev))) |
935 | ERROR(rt2x00dev, "Register initialization failed.\n"); | ||
936 | return -EIO; | 943 | return -EIO; |
937 | } | ||
938 | 944 | ||
939 | return 0; | 945 | return 0; |
940 | } | 946 | } |
@@ -987,10 +993,6 @@ static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev, | |||
987 | msleep(30); | 993 | msleep(30); |
988 | } | 994 | } |
989 | 995 | ||
990 | NOTICE(rt2x00dev, "Device failed to enter state %d, " | ||
991 | "current device state: bbp %d and rf %d.\n", | ||
992 | state, bbp_state, rf_state); | ||
993 | |||
994 | return -EBUSY; | 996 | return -EBUSY; |
995 | } | 997 | } |
996 | 998 | ||
@@ -1008,11 +1010,13 @@ static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1008 | break; | 1010 | break; |
1009 | case STATE_RADIO_RX_ON: | 1011 | case STATE_RADIO_RX_ON: |
1010 | case STATE_RADIO_RX_ON_LINK: | 1012 | case STATE_RADIO_RX_ON_LINK: |
1011 | rt2500usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); | ||
1012 | break; | ||
1013 | case STATE_RADIO_RX_OFF: | 1013 | case STATE_RADIO_RX_OFF: |
1014 | case STATE_RADIO_RX_OFF_LINK: | 1014 | case STATE_RADIO_RX_OFF_LINK: |
1015 | rt2500usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); | 1015 | rt2500usb_toggle_rx(rt2x00dev, state); |
1016 | break; | ||
1017 | case STATE_RADIO_IRQ_ON: | ||
1018 | case STATE_RADIO_IRQ_OFF: | ||
1019 | /* No support, but no error either */ | ||
1016 | break; | 1020 | break; |
1017 | case STATE_DEEP_SLEEP: | 1021 | case STATE_DEEP_SLEEP: |
1018 | case STATE_SLEEP: | 1022 | case STATE_SLEEP: |
@@ -1025,6 +1029,10 @@ static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1025 | break; | 1029 | break; |
1026 | } | 1030 | } |
1027 | 1031 | ||
1032 | if (unlikely(retval)) | ||
1033 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", | ||
1034 | state, retval); | ||
1035 | |||
1028 | return retval; | 1036 | return retval; |
1029 | } | 1037 | } |
1030 | 1038 | ||
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c index dc5ab90a52c3..48f4aec1a4d9 100644 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c | |||
@@ -112,6 +112,8 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
112 | if (status) | 112 | if (status) |
113 | return status; | 113 | return status; |
114 | 114 | ||
115 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON); | ||
116 | |||
115 | rt2x00leds_led_radio(rt2x00dev, true); | 117 | rt2x00leds_led_radio(rt2x00dev, true); |
116 | rt2x00led_led_activity(rt2x00dev, true); | 118 | rt2x00led_led_activity(rt2x00dev, true); |
117 | 119 | ||
@@ -157,6 +159,7 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev) | |||
157 | * Disable radio. | 159 | * Disable radio. |
158 | */ | 160 | */ |
159 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF); | 161 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF); |
162 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF); | ||
160 | rt2x00led_led_activity(rt2x00dev, false); | 163 | rt2x00led_led_activity(rt2x00dev, false); |
161 | rt2x00leds_led_radio(rt2x00dev, false); | 164 | rt2x00leds_led_radio(rt2x00dev, false); |
162 | } | 165 | } |
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c index e13ed5ced26e..4658dbd7ef63 100644 --- a/drivers/net/wireless/rt2x00/rt61pci.c +++ b/drivers/net/wireless/rt2x00/rt61pci.c | |||
@@ -1270,25 +1270,32 @@ static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev) | |||
1270 | return 0; | 1270 | return 0; |
1271 | } | 1271 | } |
1272 | 1272 | ||
1273 | static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev) | 1273 | static int rt61pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
1274 | { | 1274 | { |
1275 | unsigned int i; | 1275 | unsigned int i; |
1276 | u16 eeprom; | ||
1277 | u8 reg_id; | ||
1278 | u8 value; | 1276 | u8 value; |
1279 | 1277 | ||
1280 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 1278 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
1281 | rt61pci_bbp_read(rt2x00dev, 0, &value); | 1279 | rt61pci_bbp_read(rt2x00dev, 0, &value); |
1282 | if ((value != 0xff) && (value != 0x00)) | 1280 | if ((value != 0xff) && (value != 0x00)) |
1283 | goto continue_csr_init; | 1281 | return 0; |
1284 | NOTICE(rt2x00dev, "Waiting for BBP register.\n"); | ||
1285 | udelay(REGISTER_BUSY_DELAY); | 1282 | udelay(REGISTER_BUSY_DELAY); |
1286 | } | 1283 | } |
1287 | 1284 | ||
1288 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); | 1285 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
1289 | return -EACCES; | 1286 | return -EACCES; |
1287 | } | ||
1288 | |||
1289 | static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev) | ||
1290 | { | ||
1291 | unsigned int i; | ||
1292 | u16 eeprom; | ||
1293 | u8 reg_id; | ||
1294 | u8 value; | ||
1295 | |||
1296 | if (unlikely(rt61pci_wait_bbp_ready(rt2x00dev))) | ||
1297 | return -EACCES; | ||
1290 | 1298 | ||
1291 | continue_csr_init: | ||
1292 | rt61pci_bbp_write(rt2x00dev, 3, 0x00); | 1299 | rt61pci_bbp_write(rt2x00dev, 3, 0x00); |
1293 | rt61pci_bbp_write(rt2x00dev, 15, 0x30); | 1300 | rt61pci_bbp_write(rt2x00dev, 15, 0x30); |
1294 | rt61pci_bbp_write(rt2x00dev, 21, 0xc8); | 1301 | rt61pci_bbp_write(rt2x00dev, 21, 0xc8); |
@@ -1337,7 +1344,8 @@ static void rt61pci_toggle_rx(struct rt2x00_dev *rt2x00dev, | |||
1337 | 1344 | ||
1338 | rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, ®); | 1345 | rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, ®); |
1339 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, | 1346 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, |
1340 | state == STATE_RADIO_RX_OFF); | 1347 | (state == STATE_RADIO_RX_OFF) || |
1348 | (state == STATE_RADIO_RX_OFF_LINK)); | ||
1341 | rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg); | 1349 | rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg); |
1342 | } | 1350 | } |
1343 | 1351 | ||
@@ -1389,17 +1397,10 @@ static int rt61pci_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
1389 | /* | 1397 | /* |
1390 | * Initialize all registers. | 1398 | * Initialize all registers. |
1391 | */ | 1399 | */ |
1392 | if (rt61pci_init_queues(rt2x00dev) || | 1400 | if (unlikely(rt61pci_init_queues(rt2x00dev) || |
1393 | rt61pci_init_registers(rt2x00dev) || | 1401 | rt61pci_init_registers(rt2x00dev) || |
1394 | rt61pci_init_bbp(rt2x00dev)) { | 1402 | rt61pci_init_bbp(rt2x00dev))) |
1395 | ERROR(rt2x00dev, "Register initialization failed.\n"); | ||
1396 | return -EIO; | 1403 | return -EIO; |
1397 | } | ||
1398 | |||
1399 | /* | ||
1400 | * Enable interrupts. | ||
1401 | */ | ||
1402 | rt61pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON); | ||
1403 | 1404 | ||
1404 | /* | 1405 | /* |
1405 | * Enable RX. | 1406 | * Enable RX. |
@@ -1431,11 +1432,6 @@ static void rt61pci_disable_radio(struct rt2x00_dev *rt2x00dev) | |||
1431 | rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC2, 1); | 1432 | rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC2, 1); |
1432 | rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC3, 1); | 1433 | rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC3, 1); |
1433 | rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg); | 1434 | rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg); |
1434 | |||
1435 | /* | ||
1436 | * Disable interrupts. | ||
1437 | */ | ||
1438 | rt61pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF); | ||
1439 | } | 1435 | } |
1440 | 1436 | ||
1441 | static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) | 1437 | static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) |
@@ -1443,7 +1439,6 @@ static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) | |||
1443 | u32 reg; | 1439 | u32 reg; |
1444 | unsigned int i; | 1440 | unsigned int i; |
1445 | char put_to_sleep; | 1441 | char put_to_sleep; |
1446 | char current_state; | ||
1447 | 1442 | ||
1448 | put_to_sleep = (state != STATE_AWAKE); | 1443 | put_to_sleep = (state != STATE_AWAKE); |
1449 | 1444 | ||
@@ -1459,16 +1454,12 @@ static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) | |||
1459 | */ | 1454 | */ |
1460 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 1455 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
1461 | rt2x00pci_register_read(rt2x00dev, MAC_CSR12, ®); | 1456 | rt2x00pci_register_read(rt2x00dev, MAC_CSR12, ®); |
1462 | current_state = | 1457 | state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); |
1463 | rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); | 1458 | if (state == !put_to_sleep) |
1464 | if (current_state == !put_to_sleep) | ||
1465 | return 0; | 1459 | return 0; |
1466 | msleep(10); | 1460 | msleep(10); |
1467 | } | 1461 | } |
1468 | 1462 | ||
1469 | NOTICE(rt2x00dev, "Device failed to enter state %d, " | ||
1470 | "current device state %d.\n", !put_to_sleep, current_state); | ||
1471 | |||
1472 | return -EBUSY; | 1463 | return -EBUSY; |
1473 | } | 1464 | } |
1474 | 1465 | ||
@@ -1486,11 +1477,13 @@ static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1486 | break; | 1477 | break; |
1487 | case STATE_RADIO_RX_ON: | 1478 | case STATE_RADIO_RX_ON: |
1488 | case STATE_RADIO_RX_ON_LINK: | 1479 | case STATE_RADIO_RX_ON_LINK: |
1489 | rt61pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); | ||
1490 | break; | ||
1491 | case STATE_RADIO_RX_OFF: | 1480 | case STATE_RADIO_RX_OFF: |
1492 | case STATE_RADIO_RX_OFF_LINK: | 1481 | case STATE_RADIO_RX_OFF_LINK: |
1493 | rt61pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); | 1482 | rt61pci_toggle_rx(rt2x00dev, state); |
1483 | break; | ||
1484 | case STATE_RADIO_IRQ_ON: | ||
1485 | case STATE_RADIO_IRQ_OFF: | ||
1486 | rt61pci_toggle_irq(rt2x00dev, state); | ||
1494 | break; | 1487 | break; |
1495 | case STATE_DEEP_SLEEP: | 1488 | case STATE_DEEP_SLEEP: |
1496 | case STATE_SLEEP: | 1489 | case STATE_SLEEP: |
@@ -1503,6 +1496,10 @@ static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1503 | break; | 1496 | break; |
1504 | } | 1497 | } |
1505 | 1498 | ||
1499 | if (unlikely(retval)) | ||
1500 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", | ||
1501 | state, retval); | ||
1502 | |||
1506 | return retval; | 1503 | return retval; |
1507 | } | 1504 | } |
1508 | 1505 | ||
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c index 26c2e0a1a308..aabdc67c8555 100644 --- a/drivers/net/wireless/rt2x00/rt73usb.c +++ b/drivers/net/wireless/rt2x00/rt73usb.c | |||
@@ -1084,25 +1084,32 @@ static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev) | |||
1084 | return 0; | 1084 | return 0; |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev) | 1087 | static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
1088 | { | 1088 | { |
1089 | unsigned int i; | 1089 | unsigned int i; |
1090 | u16 eeprom; | ||
1091 | u8 reg_id; | ||
1092 | u8 value; | 1090 | u8 value; |
1093 | 1091 | ||
1094 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 1092 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
1095 | rt73usb_bbp_read(rt2x00dev, 0, &value); | 1093 | rt73usb_bbp_read(rt2x00dev, 0, &value); |
1096 | if ((value != 0xff) && (value != 0x00)) | 1094 | if ((value != 0xff) && (value != 0x00)) |
1097 | goto continue_csr_init; | 1095 | return 0; |
1098 | NOTICE(rt2x00dev, "Waiting for BBP register.\n"); | ||
1099 | udelay(REGISTER_BUSY_DELAY); | 1096 | udelay(REGISTER_BUSY_DELAY); |
1100 | } | 1097 | } |
1101 | 1098 | ||
1102 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); | 1099 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
1103 | return -EACCES; | 1100 | return -EACCES; |
1101 | } | ||
1102 | |||
1103 | static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev) | ||
1104 | { | ||
1105 | unsigned int i; | ||
1106 | u16 eeprom; | ||
1107 | u8 reg_id; | ||
1108 | u8 value; | ||
1109 | |||
1110 | if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev))) | ||
1111 | return -EACCES; | ||
1104 | 1112 | ||
1105 | continue_csr_init: | ||
1106 | rt73usb_bbp_write(rt2x00dev, 3, 0x80); | 1113 | rt73usb_bbp_write(rt2x00dev, 3, 0x80); |
1107 | rt73usb_bbp_write(rt2x00dev, 15, 0x30); | 1114 | rt73usb_bbp_write(rt2x00dev, 15, 0x30); |
1108 | rt73usb_bbp_write(rt2x00dev, 21, 0xc8); | 1115 | rt73usb_bbp_write(rt2x00dev, 21, 0xc8); |
@@ -1152,7 +1159,8 @@ static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev, | |||
1152 | 1159 | ||
1153 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); | 1160 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
1154 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, | 1161 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, |
1155 | state == STATE_RADIO_RX_OFF); | 1162 | (state == STATE_RADIO_RX_OFF) || |
1163 | (state == STATE_RADIO_RX_OFF_LINK)); | ||
1156 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); | 1164 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
1157 | } | 1165 | } |
1158 | 1166 | ||
@@ -1161,11 +1169,9 @@ static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev) | |||
1161 | /* | 1169 | /* |
1162 | * Initialize all registers. | 1170 | * Initialize all registers. |
1163 | */ | 1171 | */ |
1164 | if (rt73usb_init_registers(rt2x00dev) || | 1172 | if (unlikely(rt73usb_init_registers(rt2x00dev) || |
1165 | rt73usb_init_bbp(rt2x00dev)) { | 1173 | rt73usb_init_bbp(rt2x00dev))) |
1166 | ERROR(rt2x00dev, "Register initialization failed.\n"); | ||
1167 | return -EIO; | 1174 | return -EIO; |
1168 | } | ||
1169 | 1175 | ||
1170 | return 0; | 1176 | return 0; |
1171 | } | 1177 | } |
@@ -1187,7 +1193,6 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) | |||
1187 | u32 reg; | 1193 | u32 reg; |
1188 | unsigned int i; | 1194 | unsigned int i; |
1189 | char put_to_sleep; | 1195 | char put_to_sleep; |
1190 | char current_state; | ||
1191 | 1196 | ||
1192 | put_to_sleep = (state != STATE_AWAKE); | 1197 | put_to_sleep = (state != STATE_AWAKE); |
1193 | 1198 | ||
@@ -1203,16 +1208,12 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) | |||
1203 | */ | 1208 | */ |
1204 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { | 1209 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
1205 | rt73usb_register_read(rt2x00dev, MAC_CSR12, ®); | 1210 | rt73usb_register_read(rt2x00dev, MAC_CSR12, ®); |
1206 | current_state = | 1211 | state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); |
1207 | rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); | 1212 | if (state == !put_to_sleep) |
1208 | if (current_state == !put_to_sleep) | ||
1209 | return 0; | 1213 | return 0; |
1210 | msleep(10); | 1214 | msleep(10); |
1211 | } | 1215 | } |
1212 | 1216 | ||
1213 | NOTICE(rt2x00dev, "Device failed to enter state %d, " | ||
1214 | "current device state %d.\n", !put_to_sleep, current_state); | ||
1215 | |||
1216 | return -EBUSY; | 1217 | return -EBUSY; |
1217 | } | 1218 | } |
1218 | 1219 | ||
@@ -1230,11 +1231,13 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1230 | break; | 1231 | break; |
1231 | case STATE_RADIO_RX_ON: | 1232 | case STATE_RADIO_RX_ON: |
1232 | case STATE_RADIO_RX_ON_LINK: | 1233 | case STATE_RADIO_RX_ON_LINK: |
1233 | rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); | ||
1234 | break; | ||
1235 | case STATE_RADIO_RX_OFF: | 1234 | case STATE_RADIO_RX_OFF: |
1236 | case STATE_RADIO_RX_OFF_LINK: | 1235 | case STATE_RADIO_RX_OFF_LINK: |
1237 | rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); | 1236 | rt73usb_toggle_rx(rt2x00dev, state); |
1237 | break; | ||
1238 | case STATE_RADIO_IRQ_ON: | ||
1239 | case STATE_RADIO_IRQ_OFF: | ||
1240 | /* No support, but no error either */ | ||
1238 | break; | 1241 | break; |
1239 | case STATE_DEEP_SLEEP: | 1242 | case STATE_DEEP_SLEEP: |
1240 | case STATE_SLEEP: | 1243 | case STATE_SLEEP: |
@@ -1247,6 +1250,10 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev, | |||
1247 | break; | 1250 | break; |
1248 | } | 1251 | } |
1249 | 1252 | ||
1253 | if (unlikely(retval)) | ||
1254 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", | ||
1255 | state, retval); | ||
1256 | |||
1250 | return retval; | 1257 | return retval; |
1251 | } | 1258 | } |
1252 | 1259 | ||