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/wireless/rt2x00/rt61pci.c | |
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/wireless/rt2x00/rt61pci.c')
-rw-r--r-- | drivers/net/wireless/rt2x00/rt61pci.c | 61 |
1 files changed, 29 insertions, 32 deletions
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 | ||