diff options
Diffstat (limited to 'drivers/net/sky2.c')
-rw-r--r-- | drivers/net/sky2.c | 601 |
1 files changed, 320 insertions, 281 deletions
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c index 67249c3c9f50..dfff8e56a51e 100644 --- a/drivers/net/sky2.c +++ b/drivers/net/sky2.c | |||
@@ -50,7 +50,7 @@ | |||
50 | #include "sky2.h" | 50 | #include "sky2.h" |
51 | 51 | ||
52 | #define DRV_NAME "sky2" | 52 | #define DRV_NAME "sky2" |
53 | #define DRV_VERSION "1.26" | 53 | #define DRV_VERSION "1.27" |
54 | #define PFX DRV_NAME " " | 54 | #define PFX DRV_NAME " " |
55 | 55 | ||
56 | /* | 56 | /* |
@@ -251,6 +251,8 @@ static void sky2_power_on(struct sky2_hw *hw) | |||
251 | 251 | ||
252 | sky2_pci_write32(hw, PCI_CFG_REG_1, 0); | 252 | sky2_pci_write32(hw, PCI_CFG_REG_1, 0); |
253 | 253 | ||
254 | sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON); | ||
255 | |||
254 | /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ | 256 | /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ |
255 | reg = sky2_read32(hw, B2_GP_IO); | 257 | reg = sky2_read32(hw, B2_GP_IO); |
256 | reg |= GLB_GPIO_STAT_RACE_DIS; | 258 | reg |= GLB_GPIO_STAT_RACE_DIS; |
@@ -731,7 +733,6 @@ static void sky2_wol_init(struct sky2_port *sky2) | |||
731 | unsigned port = sky2->port; | 733 | unsigned port = sky2->port; |
732 | enum flow_control save_mode; | 734 | enum flow_control save_mode; |
733 | u16 ctrl; | 735 | u16 ctrl; |
734 | u32 reg1; | ||
735 | 736 | ||
736 | /* Bring hardware out of reset */ | 737 | /* Bring hardware out of reset */ |
737 | sky2_write16(hw, B0_CTST, CS_RST_CLR); | 738 | sky2_write16(hw, B0_CTST, CS_RST_CLR); |
@@ -782,14 +783,11 @@ static void sky2_wol_init(struct sky2_port *sky2) | |||
782 | ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; | 783 | ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; |
783 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); | 784 | sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); |
784 | 785 | ||
785 | /* Turn on legacy PCI-Express PME mode */ | 786 | /* Disable PiG firmware */ |
786 | reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); | 787 | sky2_write16(hw, B0_CTST, Y2_HW_WOL_OFF); |
787 | reg1 |= PCI_Y2_PME_LEGACY; | ||
788 | sky2_pci_write32(hw, PCI_DEV_REG1, reg1); | ||
789 | 788 | ||
790 | /* block receiver */ | 789 | /* block receiver */ |
791 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); | 790 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
792 | |||
793 | } | 791 | } |
794 | 792 | ||
795 | static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) | 793 | static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) |
@@ -800,29 +798,15 @@ static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) | |||
800 | hw->chip_rev != CHIP_REV_YU_EX_A0) || | 798 | hw->chip_rev != CHIP_REV_YU_EX_A0) || |
801 | hw->chip_id >= CHIP_ID_YUKON_FE_P) { | 799 | hw->chip_id >= CHIP_ID_YUKON_FE_P) { |
802 | /* Yukon-Extreme B0 and further Extreme devices */ | 800 | /* Yukon-Extreme B0 and further Extreme devices */ |
803 | /* enable Store & Forward mode for TX */ | 801 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); |
804 | 802 | } else if (dev->mtu > ETH_DATA_LEN) { | |
805 | if (dev->mtu <= ETH_DATA_LEN) | 803 | /* set Tx GMAC FIFO Almost Empty Threshold */ |
806 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), | 804 | sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), |
807 | TX_JUMBO_DIS | TX_STFW_ENA); | 805 | (ECU_JUMBO_WM << 16) | ECU_AE_THR); |
808 | |||
809 | else | ||
810 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), | ||
811 | TX_JUMBO_ENA| TX_STFW_ENA); | ||
812 | } else { | ||
813 | if (dev->mtu <= ETH_DATA_LEN) | ||
814 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); | ||
815 | else { | ||
816 | /* set Tx GMAC FIFO Almost Empty Threshold */ | ||
817 | sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), | ||
818 | (ECU_JUMBO_WM << 16) | ECU_AE_THR); | ||
819 | 806 | ||
820 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS); | 807 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS); |
821 | 808 | } else | |
822 | /* Can't do offload because of lack of store/forward */ | 809 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); |
823 | dev->features &= ~(NETIF_F_TSO | NETIF_F_SG | NETIF_F_ALL_CSUM); | ||
824 | } | ||
825 | } | ||
826 | } | 810 | } |
827 | 811 | ||
828 | static void sky2_mac_init(struct sky2_hw *hw, unsigned port) | 812 | static void sky2_mac_init(struct sky2_hw *hw, unsigned port) |
@@ -1065,6 +1049,40 @@ static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) | |||
1065 | return le; | 1049 | return le; |
1066 | } | 1050 | } |
1067 | 1051 | ||
1052 | static unsigned sky2_get_rx_threshold(struct sky2_port* sky2) | ||
1053 | { | ||
1054 | unsigned size; | ||
1055 | |||
1056 | /* Space needed for frame data + headers rounded up */ | ||
1057 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); | ||
1058 | |||
1059 | /* Stopping point for hardware truncation */ | ||
1060 | return (size - 8) / sizeof(u32); | ||
1061 | } | ||
1062 | |||
1063 | static unsigned sky2_get_rx_data_size(struct sky2_port* sky2) | ||
1064 | { | ||
1065 | struct rx_ring_info *re; | ||
1066 | unsigned size; | ||
1067 | |||
1068 | /* Space needed for frame data + headers rounded up */ | ||
1069 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); | ||
1070 | |||
1071 | sky2->rx_nfrags = size >> PAGE_SHIFT; | ||
1072 | BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); | ||
1073 | |||
1074 | /* Compute residue after pages */ | ||
1075 | size -= sky2->rx_nfrags << PAGE_SHIFT; | ||
1076 | |||
1077 | /* Optimize to handle small packets and headers */ | ||
1078 | if (size < copybreak) | ||
1079 | size = copybreak; | ||
1080 | if (size < ETH_HLEN) | ||
1081 | size = ETH_HLEN; | ||
1082 | |||
1083 | return size; | ||
1084 | } | ||
1085 | |||
1068 | /* Build description to hardware for one receive segment */ | 1086 | /* Build description to hardware for one receive segment */ |
1069 | static void sky2_rx_add(struct sky2_port *sky2, u8 op, | 1087 | static void sky2_rx_add(struct sky2_port *sky2, u8 op, |
1070 | dma_addr_t map, unsigned len) | 1088 | dma_addr_t map, unsigned len) |
@@ -1103,18 +1121,39 @@ static int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re, | |||
1103 | int i; | 1121 | int i; |
1104 | 1122 | ||
1105 | re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE); | 1123 | re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE); |
1106 | if (unlikely(pci_dma_mapping_error(pdev, re->data_addr))) | 1124 | if (pci_dma_mapping_error(pdev, re->data_addr)) |
1107 | return -EIO; | 1125 | goto mapping_error; |
1108 | 1126 | ||
1109 | pci_unmap_len_set(re, data_size, size); | 1127 | pci_unmap_len_set(re, data_size, size); |
1110 | 1128 | ||
1111 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) | 1129 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
1112 | re->frag_addr[i] = pci_map_page(pdev, | 1130 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
1113 | skb_shinfo(skb)->frags[i].page, | 1131 | |
1114 | skb_shinfo(skb)->frags[i].page_offset, | 1132 | re->frag_addr[i] = pci_map_page(pdev, frag->page, |
1115 | skb_shinfo(skb)->frags[i].size, | 1133 | frag->page_offset, |
1134 | frag->size, | ||
1116 | PCI_DMA_FROMDEVICE); | 1135 | PCI_DMA_FROMDEVICE); |
1136 | |||
1137 | if (pci_dma_mapping_error(pdev, re->frag_addr[i])) | ||
1138 | goto map_page_error; | ||
1139 | } | ||
1117 | return 0; | 1140 | return 0; |
1141 | |||
1142 | map_page_error: | ||
1143 | while (--i >= 0) { | ||
1144 | pci_unmap_page(pdev, re->frag_addr[i], | ||
1145 | skb_shinfo(skb)->frags[i].size, | ||
1146 | PCI_DMA_FROMDEVICE); | ||
1147 | } | ||
1148 | |||
1149 | pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size), | ||
1150 | PCI_DMA_FROMDEVICE); | ||
1151 | |||
1152 | mapping_error: | ||
1153 | if (net_ratelimit()) | ||
1154 | dev_warn(&pdev->dev, "%s: rx mapping error\n", | ||
1155 | skb->dev->name); | ||
1156 | return -EIO; | ||
1118 | } | 1157 | } |
1119 | 1158 | ||
1120 | static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re) | 1159 | static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re) |
@@ -1324,8 +1363,32 @@ static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq) | |||
1324 | sky2_put_idx(sky2->hw, rxq, sky2->rx_put); | 1363 | sky2_put_idx(sky2->hw, rxq, sky2->rx_put); |
1325 | } | 1364 | } |
1326 | 1365 | ||
1366 | static int sky2_alloc_rx_skbs(struct sky2_port *sky2) | ||
1367 | { | ||
1368 | struct sky2_hw *hw = sky2->hw; | ||
1369 | unsigned i; | ||
1370 | |||
1371 | sky2->rx_data_size = sky2_get_rx_data_size(sky2); | ||
1372 | |||
1373 | /* Fill Rx ring */ | ||
1374 | for (i = 0; i < sky2->rx_pending; i++) { | ||
1375 | struct rx_ring_info *re = sky2->rx_ring + i; | ||
1376 | |||
1377 | re->skb = sky2_rx_alloc(sky2); | ||
1378 | if (!re->skb) | ||
1379 | return -ENOMEM; | ||
1380 | |||
1381 | if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) { | ||
1382 | dev_kfree_skb(re->skb); | ||
1383 | re->skb = NULL; | ||
1384 | return -ENOMEM; | ||
1385 | } | ||
1386 | } | ||
1387 | return 0; | ||
1388 | } | ||
1389 | |||
1327 | /* | 1390 | /* |
1328 | * Allocate and setup receiver buffer pool. | 1391 | * Setup receiver buffer pool. |
1329 | * Normal case this ends up creating one list element for skb | 1392 | * Normal case this ends up creating one list element for skb |
1330 | * in the receive ring. Worst case if using large MTU and each | 1393 | * in the receive ring. Worst case if using large MTU and each |
1331 | * allocation falls on a different 64 bit region, that results | 1394 | * allocation falls on a different 64 bit region, that results |
@@ -1333,12 +1396,12 @@ static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq) | |||
1333 | * One element is used for checksum enable/disable, and one | 1396 | * One element is used for checksum enable/disable, and one |
1334 | * extra to avoid wrap. | 1397 | * extra to avoid wrap. |
1335 | */ | 1398 | */ |
1336 | static int sky2_rx_start(struct sky2_port *sky2) | 1399 | static void sky2_rx_start(struct sky2_port *sky2) |
1337 | { | 1400 | { |
1338 | struct sky2_hw *hw = sky2->hw; | 1401 | struct sky2_hw *hw = sky2->hw; |
1339 | struct rx_ring_info *re; | 1402 | struct rx_ring_info *re; |
1340 | unsigned rxq = rxqaddr[sky2->port]; | 1403 | unsigned rxq = rxqaddr[sky2->port]; |
1341 | unsigned i, size, thresh; | 1404 | unsigned i, thresh; |
1342 | 1405 | ||
1343 | sky2->rx_put = sky2->rx_next = 0; | 1406 | sky2->rx_put = sky2->rx_next = 0; |
1344 | sky2_qset(hw, rxq); | 1407 | sky2_qset(hw, rxq); |
@@ -1359,40 +1422,9 @@ static int sky2_rx_start(struct sky2_port *sky2) | |||
1359 | if (!(hw->flags & SKY2_HW_NEW_LE)) | 1422 | if (!(hw->flags & SKY2_HW_NEW_LE)) |
1360 | rx_set_checksum(sky2); | 1423 | rx_set_checksum(sky2); |
1361 | 1424 | ||
1362 | /* Space needed for frame data + headers rounded up */ | 1425 | /* submit Rx ring */ |
1363 | size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); | ||
1364 | |||
1365 | /* Stopping point for hardware truncation */ | ||
1366 | thresh = (size - 8) / sizeof(u32); | ||
1367 | |||
1368 | sky2->rx_nfrags = size >> PAGE_SHIFT; | ||
1369 | BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); | ||
1370 | |||
1371 | /* Compute residue after pages */ | ||
1372 | size -= sky2->rx_nfrags << PAGE_SHIFT; | ||
1373 | |||
1374 | /* Optimize to handle small packets and headers */ | ||
1375 | if (size < copybreak) | ||
1376 | size = copybreak; | ||
1377 | if (size < ETH_HLEN) | ||
1378 | size = ETH_HLEN; | ||
1379 | |||
1380 | sky2->rx_data_size = size; | ||
1381 | |||
1382 | /* Fill Rx ring */ | ||
1383 | for (i = 0; i < sky2->rx_pending; i++) { | 1426 | for (i = 0; i < sky2->rx_pending; i++) { |
1384 | re = sky2->rx_ring + i; | 1427 | re = sky2->rx_ring + i; |
1385 | |||
1386 | re->skb = sky2_rx_alloc(sky2); | ||
1387 | if (!re->skb) | ||
1388 | goto nomem; | ||
1389 | |||
1390 | if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) { | ||
1391 | dev_kfree_skb(re->skb); | ||
1392 | re->skb = NULL; | ||
1393 | goto nomem; | ||
1394 | } | ||
1395 | |||
1396 | sky2_rx_submit(sky2, re); | 1428 | sky2_rx_submit(sky2, re); |
1397 | } | 1429 | } |
1398 | 1430 | ||
@@ -1402,6 +1434,7 @@ static int sky2_rx_start(struct sky2_port *sky2) | |||
1402 | * the register is limited to 9 bits, so if you do frames > 2052 | 1434 | * the register is limited to 9 bits, so if you do frames > 2052 |
1403 | * you better get the MTU right! | 1435 | * you better get the MTU right! |
1404 | */ | 1436 | */ |
1437 | thresh = sky2_get_rx_threshold(sky2); | ||
1405 | if (thresh > 0x1ff) | 1438 | if (thresh > 0x1ff) |
1406 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); | 1439 | sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); |
1407 | else { | 1440 | else { |
@@ -1433,13 +1466,6 @@ static int sky2_rx_start(struct sky2_port *sky2) | |||
1433 | sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST), | 1466 | sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST), |
1434 | TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN); | 1467 | TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN); |
1435 | } | 1468 | } |
1436 | |||
1437 | |||
1438 | |||
1439 | return 0; | ||
1440 | nomem: | ||
1441 | sky2_rx_clean(sky2); | ||
1442 | return -ENOMEM; | ||
1443 | } | 1469 | } |
1444 | 1470 | ||
1445 | static int sky2_alloc_buffers(struct sky2_port *sky2) | 1471 | static int sky2_alloc_buffers(struct sky2_port *sky2) |
@@ -1470,7 +1496,7 @@ static int sky2_alloc_buffers(struct sky2_port *sky2) | |||
1470 | if (!sky2->rx_ring) | 1496 | if (!sky2->rx_ring) |
1471 | goto nomem; | 1497 | goto nomem; |
1472 | 1498 | ||
1473 | return 0; | 1499 | return sky2_alloc_rx_skbs(sky2); |
1474 | nomem: | 1500 | nomem: |
1475 | return -ENOMEM; | 1501 | return -ENOMEM; |
1476 | } | 1502 | } |
@@ -1479,6 +1505,8 @@ static void sky2_free_buffers(struct sky2_port *sky2) | |||
1479 | { | 1505 | { |
1480 | struct sky2_hw *hw = sky2->hw; | 1506 | struct sky2_hw *hw = sky2->hw; |
1481 | 1507 | ||
1508 | sky2_rx_clean(sky2); | ||
1509 | |||
1482 | if (sky2->rx_le) { | 1510 | if (sky2->rx_le) { |
1483 | pci_free_consistent(hw->pdev, RX_LE_BYTES, | 1511 | pci_free_consistent(hw->pdev, RX_LE_BYTES, |
1484 | sky2->rx_le, sky2->rx_le_map); | 1512 | sky2->rx_le, sky2->rx_le_map); |
@@ -1497,16 +1525,16 @@ static void sky2_free_buffers(struct sky2_port *sky2) | |||
1497 | sky2->rx_ring = NULL; | 1525 | sky2->rx_ring = NULL; |
1498 | } | 1526 | } |
1499 | 1527 | ||
1500 | /* Bring up network interface. */ | 1528 | static void sky2_hw_up(struct sky2_port *sky2) |
1501 | static int sky2_up(struct net_device *dev) | ||
1502 | { | 1529 | { |
1503 | struct sky2_port *sky2 = netdev_priv(dev); | ||
1504 | struct sky2_hw *hw = sky2->hw; | 1530 | struct sky2_hw *hw = sky2->hw; |
1505 | unsigned port = sky2->port; | 1531 | unsigned port = sky2->port; |
1506 | u32 imask, ramsize; | 1532 | u32 ramsize; |
1507 | int cap, err; | 1533 | int cap; |
1508 | struct net_device *otherdev = hw->dev[sky2->port^1]; | 1534 | struct net_device *otherdev = hw->dev[sky2->port^1]; |
1509 | 1535 | ||
1536 | tx_init(sky2); | ||
1537 | |||
1510 | /* | 1538 | /* |
1511 | * On dual port PCI-X card, there is an problem where status | 1539 | * On dual port PCI-X card, there is an problem where status |
1512 | * can be received out of order due to split transactions | 1540 | * can be received out of order due to split transactions |
@@ -1518,16 +1546,7 @@ static int sky2_up(struct net_device *dev) | |||
1518 | cmd = sky2_pci_read16(hw, cap + PCI_X_CMD); | 1546 | cmd = sky2_pci_read16(hw, cap + PCI_X_CMD); |
1519 | cmd &= ~PCI_X_CMD_MAX_SPLIT; | 1547 | cmd &= ~PCI_X_CMD_MAX_SPLIT; |
1520 | sky2_pci_write16(hw, cap + PCI_X_CMD, cmd); | 1548 | sky2_pci_write16(hw, cap + PCI_X_CMD, cmd); |
1521 | 1549 | } | |
1522 | } | ||
1523 | |||
1524 | netif_carrier_off(dev); | ||
1525 | |||
1526 | err = sky2_alloc_buffers(sky2); | ||
1527 | if (err) | ||
1528 | goto err_out; | ||
1529 | |||
1530 | tx_init(sky2); | ||
1531 | 1550 | ||
1532 | sky2_mac_init(hw, port); | 1551 | sky2_mac_init(hw, port); |
1533 | 1552 | ||
@@ -1536,7 +1555,7 @@ static int sky2_up(struct net_device *dev) | |||
1536 | if (ramsize > 0) { | 1555 | if (ramsize > 0) { |
1537 | u32 rxspace; | 1556 | u32 rxspace; |
1538 | 1557 | ||
1539 | pr_debug(PFX "%s: ram buffer %dK\n", dev->name, ramsize); | 1558 | pr_debug(PFX "%s: ram buffer %dK\n", sky2->netdev->name, ramsize); |
1540 | if (ramsize < 16) | 1559 | if (ramsize < 16) |
1541 | rxspace = ramsize / 2; | 1560 | rxspace = ramsize / 2; |
1542 | else | 1561 | else |
@@ -1568,10 +1587,26 @@ static int sky2_up(struct net_device *dev) | |||
1568 | sky2_set_vlan_mode(hw, port, sky2->vlgrp != NULL); | 1587 | sky2_set_vlan_mode(hw, port, sky2->vlgrp != NULL); |
1569 | #endif | 1588 | #endif |
1570 | 1589 | ||
1571 | err = sky2_rx_start(sky2); | 1590 | sky2_rx_start(sky2); |
1591 | } | ||
1592 | |||
1593 | /* Bring up network interface. */ | ||
1594 | static int sky2_up(struct net_device *dev) | ||
1595 | { | ||
1596 | struct sky2_port *sky2 = netdev_priv(dev); | ||
1597 | struct sky2_hw *hw = sky2->hw; | ||
1598 | unsigned port = sky2->port; | ||
1599 | u32 imask; | ||
1600 | int err; | ||
1601 | |||
1602 | netif_carrier_off(dev); | ||
1603 | |||
1604 | err = sky2_alloc_buffers(sky2); | ||
1572 | if (err) | 1605 | if (err) |
1573 | goto err_out; | 1606 | goto err_out; |
1574 | 1607 | ||
1608 | sky2_hw_up(sky2); | ||
1609 | |||
1575 | /* Enable interrupts from phy/mac for port */ | 1610 | /* Enable interrupts from phy/mac for port */ |
1576 | imask = sky2_read32(hw, B0_IMSK); | 1611 | imask = sky2_read32(hw, B0_IMSK); |
1577 | imask |= portirq_msk[port]; | 1612 | imask |= portirq_msk[port]; |
@@ -1845,10 +1880,6 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done) | |||
1845 | 1880 | ||
1846 | sky2->tx_cons = idx; | 1881 | sky2->tx_cons = idx; |
1847 | smp_mb(); | 1882 | smp_mb(); |
1848 | |||
1849 | /* Wake unless it's detached, and called e.g. from sky2_down() */ | ||
1850 | if (tx_avail(sky2) > MAX_SKB_TX_LE + 4 && netif_device_present(dev)) | ||
1851 | netif_wake_queue(dev); | ||
1852 | } | 1883 | } |
1853 | 1884 | ||
1854 | static void sky2_tx_reset(struct sky2_hw *hw, unsigned port) | 1885 | static void sky2_tx_reset(struct sky2_hw *hw, unsigned port) |
@@ -1873,21 +1904,11 @@ static void sky2_tx_reset(struct sky2_hw *hw, unsigned port) | |||
1873 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); | 1904 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); |
1874 | } | 1905 | } |
1875 | 1906 | ||
1876 | /* Network shutdown */ | 1907 | static void sky2_hw_down(struct sky2_port *sky2) |
1877 | static int sky2_down(struct net_device *dev) | ||
1878 | { | 1908 | { |
1879 | struct sky2_port *sky2 = netdev_priv(dev); | ||
1880 | struct sky2_hw *hw = sky2->hw; | 1909 | struct sky2_hw *hw = sky2->hw; |
1881 | unsigned port = sky2->port; | 1910 | unsigned port = sky2->port; |
1882 | u16 ctrl; | 1911 | u16 ctrl; |
1883 | u32 imask; | ||
1884 | |||
1885 | /* Never really got started! */ | ||
1886 | if (!sky2->tx_le) | ||
1887 | return 0; | ||
1888 | |||
1889 | if (netif_msg_ifdown(sky2)) | ||
1890 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); | ||
1891 | 1912 | ||
1892 | /* Force flow control off */ | 1913 | /* Force flow control off */ |
1893 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); | 1914 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
@@ -1920,15 +1941,6 @@ static int sky2_down(struct net_device *dev) | |||
1920 | 1941 | ||
1921 | sky2_rx_stop(sky2); | 1942 | sky2_rx_stop(sky2); |
1922 | 1943 | ||
1923 | /* Disable port IRQ */ | ||
1924 | imask = sky2_read32(hw, B0_IMSK); | ||
1925 | imask &= ~portirq_msk[port]; | ||
1926 | sky2_write32(hw, B0_IMSK, imask); | ||
1927 | sky2_read32(hw, B0_IMSK); | ||
1928 | |||
1929 | synchronize_irq(hw->pdev->irq); | ||
1930 | napi_synchronize(&hw->napi); | ||
1931 | |||
1932 | spin_lock_bh(&sky2->phy_lock); | 1944 | spin_lock_bh(&sky2->phy_lock); |
1933 | sky2_phy_power_down(hw, port); | 1945 | sky2_phy_power_down(hw, port); |
1934 | spin_unlock_bh(&sky2->phy_lock); | 1946 | spin_unlock_bh(&sky2->phy_lock); |
@@ -1937,8 +1949,30 @@ static int sky2_down(struct net_device *dev) | |||
1937 | 1949 | ||
1938 | /* Free any pending frames stuck in HW queue */ | 1950 | /* Free any pending frames stuck in HW queue */ |
1939 | sky2_tx_complete(sky2, sky2->tx_prod); | 1951 | sky2_tx_complete(sky2, sky2->tx_prod); |
1952 | } | ||
1940 | 1953 | ||
1941 | sky2_rx_clean(sky2); | 1954 | /* Network shutdown */ |
1955 | static int sky2_down(struct net_device *dev) | ||
1956 | { | ||
1957 | struct sky2_port *sky2 = netdev_priv(dev); | ||
1958 | struct sky2_hw *hw = sky2->hw; | ||
1959 | |||
1960 | /* Never really got started! */ | ||
1961 | if (!sky2->tx_le) | ||
1962 | return 0; | ||
1963 | |||
1964 | if (netif_msg_ifdown(sky2)) | ||
1965 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); | ||
1966 | |||
1967 | /* Disable port IRQ */ | ||
1968 | sky2_write32(hw, B0_IMSK, | ||
1969 | sky2_read32(hw, B0_IMSK) & ~portirq_msk[sky2->port]); | ||
1970 | sky2_read32(hw, B0_IMSK); | ||
1971 | |||
1972 | synchronize_irq(hw->pdev->irq); | ||
1973 | napi_synchronize(&hw->napi); | ||
1974 | |||
1975 | sky2_hw_down(sky2); | ||
1942 | 1976 | ||
1943 | sky2_free_buffers(sky2); | 1977 | sky2_free_buffers(sky2); |
1944 | 1978 | ||
@@ -2187,14 +2221,20 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu) | |||
2187 | u16 ctl, mode; | 2221 | u16 ctl, mode; |
2188 | u32 imask; | 2222 | u32 imask; |
2189 | 2223 | ||
2224 | /* MTU size outside the spec */ | ||
2190 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) | 2225 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) |
2191 | return -EINVAL; | 2226 | return -EINVAL; |
2192 | 2227 | ||
2228 | /* MTU > 1500 on yukon FE and FE+ not allowed */ | ||
2193 | if (new_mtu > ETH_DATA_LEN && | 2229 | if (new_mtu > ETH_DATA_LEN && |
2194 | (hw->chip_id == CHIP_ID_YUKON_FE || | 2230 | (hw->chip_id == CHIP_ID_YUKON_FE || |
2195 | hw->chip_id == CHIP_ID_YUKON_FE_P)) | 2231 | hw->chip_id == CHIP_ID_YUKON_FE_P)) |
2196 | return -EINVAL; | 2232 | return -EINVAL; |
2197 | 2233 | ||
2234 | /* TSO, etc on Yukon Ultra and MTU > 1500 not supported */ | ||
2235 | if (new_mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U) | ||
2236 | dev->features &= ~(NETIF_F_TSO|NETIF_F_SG|NETIF_F_ALL_CSUM); | ||
2237 | |||
2198 | if (!netif_running(dev)) { | 2238 | if (!netif_running(dev)) { |
2199 | dev->mtu = new_mtu; | 2239 | dev->mtu = new_mtu; |
2200 | return 0; | 2240 | return 0; |
@@ -2229,7 +2269,11 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu) | |||
2229 | 2269 | ||
2230 | sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD); | 2270 | sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD); |
2231 | 2271 | ||
2232 | err = sky2_rx_start(sky2); | 2272 | err = sky2_alloc_rx_skbs(sky2); |
2273 | if (!err) | ||
2274 | sky2_rx_start(sky2); | ||
2275 | else | ||
2276 | sky2_rx_clean(sky2); | ||
2233 | sky2_write32(hw, B0_IMSK, imask); | 2277 | sky2_write32(hw, B0_IMSK, imask); |
2234 | 2278 | ||
2235 | sky2_read32(hw, B0_Y2_SP_LISR); | 2279 | sky2_read32(hw, B0_Y2_SP_LISR); |
@@ -2306,30 +2350,32 @@ static struct sk_buff *receive_new(struct sky2_port *sky2, | |||
2306 | struct rx_ring_info *re, | 2350 | struct rx_ring_info *re, |
2307 | unsigned int length) | 2351 | unsigned int length) |
2308 | { | 2352 | { |
2309 | struct sk_buff *skb, *nskb; | 2353 | struct sk_buff *skb; |
2354 | struct rx_ring_info nre; | ||
2310 | unsigned hdr_space = sky2->rx_data_size; | 2355 | unsigned hdr_space = sky2->rx_data_size; |
2311 | 2356 | ||
2312 | /* Don't be tricky about reusing pages (yet) */ | 2357 | nre.skb = sky2_rx_alloc(sky2); |
2313 | nskb = sky2_rx_alloc(sky2); | 2358 | if (unlikely(!nre.skb)) |
2314 | if (unlikely(!nskb)) | 2359 | goto nobuf; |
2315 | return NULL; | 2360 | |
2361 | if (sky2_rx_map_skb(sky2->hw->pdev, &nre, hdr_space)) | ||
2362 | goto nomap; | ||
2316 | 2363 | ||
2317 | skb = re->skb; | 2364 | skb = re->skb; |
2318 | sky2_rx_unmap_skb(sky2->hw->pdev, re); | 2365 | sky2_rx_unmap_skb(sky2->hw->pdev, re); |
2319 | |||
2320 | prefetch(skb->data); | 2366 | prefetch(skb->data); |
2321 | re->skb = nskb; | 2367 | *re = nre; |
2322 | if (sky2_rx_map_skb(sky2->hw->pdev, re, hdr_space)) { | ||
2323 | dev_kfree_skb(nskb); | ||
2324 | re->skb = skb; | ||
2325 | return NULL; | ||
2326 | } | ||
2327 | 2368 | ||
2328 | if (skb_shinfo(skb)->nr_frags) | 2369 | if (skb_shinfo(skb)->nr_frags) |
2329 | skb_put_frags(skb, hdr_space, length); | 2370 | skb_put_frags(skb, hdr_space, length); |
2330 | else | 2371 | else |
2331 | skb_put(skb, length); | 2372 | skb_put(skb, length); |
2332 | return skb; | 2373 | return skb; |
2374 | |||
2375 | nomap: | ||
2376 | dev_kfree_skb(nre.skb); | ||
2377 | nobuf: | ||
2378 | return NULL; | ||
2333 | } | 2379 | } |
2334 | 2380 | ||
2335 | /* | 2381 | /* |
@@ -2381,6 +2427,9 @@ okay: | |||
2381 | skb = receive_copy(sky2, re, length); | 2427 | skb = receive_copy(sky2, re, length); |
2382 | else | 2428 | else |
2383 | skb = receive_new(sky2, re, length); | 2429 | skb = receive_new(sky2, re, length); |
2430 | |||
2431 | dev->stats.rx_dropped += (skb == NULL); | ||
2432 | |||
2384 | resubmit: | 2433 | resubmit: |
2385 | sky2_rx_submit(sky2, re); | 2434 | sky2_rx_submit(sky2, re); |
2386 | 2435 | ||
@@ -2421,8 +2470,13 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last) | |||
2421 | { | 2470 | { |
2422 | struct sky2_port *sky2 = netdev_priv(dev); | 2471 | struct sky2_port *sky2 = netdev_priv(dev); |
2423 | 2472 | ||
2424 | if (netif_running(dev)) | 2473 | if (netif_running(dev)) { |
2425 | sky2_tx_complete(sky2, last); | 2474 | sky2_tx_complete(sky2, last); |
2475 | |||
2476 | /* Wake unless it's detached, and called e.g. from sky2_down() */ | ||
2477 | if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) | ||
2478 | netif_wake_queue(dev); | ||
2479 | } | ||
2426 | } | 2480 | } |
2427 | 2481 | ||
2428 | static inline void sky2_skb_rx(const struct sky2_port *sky2, | 2482 | static inline void sky2_skb_rx(const struct sky2_port *sky2, |
@@ -2458,6 +2512,32 @@ static inline void sky2_rx_done(struct sky2_hw *hw, unsigned port, | |||
2458 | } | 2512 | } |
2459 | } | 2513 | } |
2460 | 2514 | ||
2515 | static void sky2_rx_checksum(struct sky2_port *sky2, u32 status) | ||
2516 | { | ||
2517 | /* If this happens then driver assuming wrong format for chip type */ | ||
2518 | BUG_ON(sky2->hw->flags & SKY2_HW_NEW_LE); | ||
2519 | |||
2520 | /* Both checksum counters are programmed to start at | ||
2521 | * the same offset, so unless there is a problem they | ||
2522 | * should match. This failure is an early indication that | ||
2523 | * hardware receive checksumming won't work. | ||
2524 | */ | ||
2525 | if (likely((u16)(status >> 16) == (u16)status)) { | ||
2526 | struct sk_buff *skb = sky2->rx_ring[sky2->rx_next].skb; | ||
2527 | skb->ip_summed = CHECKSUM_COMPLETE; | ||
2528 | skb->csum = le16_to_cpu(status); | ||
2529 | } else { | ||
2530 | dev_notice(&sky2->hw->pdev->dev, | ||
2531 | "%s: receive checksum problem (status = %#x)\n", | ||
2532 | sky2->netdev->name, status); | ||
2533 | |||
2534 | /* Disable checksum offload */ | ||
2535 | sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM; | ||
2536 | sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), | ||
2537 | BMU_DIS_RX_CHKSUM); | ||
2538 | } | ||
2539 | } | ||
2540 | |||
2461 | /* Process status response ring */ | 2541 | /* Process status response ring */ |
2462 | static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) | 2542 | static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) |
2463 | { | 2543 | { |
@@ -2492,11 +2572,10 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) | |||
2492 | case OP_RXSTAT: | 2572 | case OP_RXSTAT: |
2493 | total_packets[port]++; | 2573 | total_packets[port]++; |
2494 | total_bytes[port] += length; | 2574 | total_bytes[port] += length; |
2575 | |||
2495 | skb = sky2_receive(dev, length, status); | 2576 | skb = sky2_receive(dev, length, status); |
2496 | if (unlikely(!skb)) { | 2577 | if (!skb) |
2497 | dev->stats.rx_dropped++; | ||
2498 | break; | 2578 | break; |
2499 | } | ||
2500 | 2579 | ||
2501 | /* This chip reports checksum status differently */ | 2580 | /* This chip reports checksum status differently */ |
2502 | if (hw->flags & SKY2_HW_NEW_LE) { | 2581 | if (hw->flags & SKY2_HW_NEW_LE) { |
@@ -2527,37 +2606,8 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) | |||
2527 | /* fall through */ | 2606 | /* fall through */ |
2528 | #endif | 2607 | #endif |
2529 | case OP_RXCHKS: | 2608 | case OP_RXCHKS: |
2530 | if (!(sky2->flags & SKY2_FLAG_RX_CHECKSUM)) | 2609 | if (likely(sky2->flags & SKY2_FLAG_RX_CHECKSUM)) |
2531 | break; | 2610 | sky2_rx_checksum(sky2, status); |
2532 | |||
2533 | /* If this happens then driver assuming wrong format */ | ||
2534 | if (unlikely(hw->flags & SKY2_HW_NEW_LE)) { | ||
2535 | if (net_ratelimit()) | ||
2536 | printk(KERN_NOTICE "%s: unexpected" | ||
2537 | " checksum status\n", | ||
2538 | dev->name); | ||
2539 | break; | ||
2540 | } | ||
2541 | |||
2542 | /* Both checksum counters are programmed to start at | ||
2543 | * the same offset, so unless there is a problem they | ||
2544 | * should match. This failure is an early indication that | ||
2545 | * hardware receive checksumming won't work. | ||
2546 | */ | ||
2547 | if (likely(status >> 16 == (status & 0xffff))) { | ||
2548 | skb = sky2->rx_ring[sky2->rx_next].skb; | ||
2549 | skb->ip_summed = CHECKSUM_COMPLETE; | ||
2550 | skb->csum = le16_to_cpu(status); | ||
2551 | } else { | ||
2552 | printk(KERN_NOTICE PFX "%s: hardware receive " | ||
2553 | "checksum problem (status = %#x)\n", | ||
2554 | dev->name, status); | ||
2555 | sky2->flags &= ~SKY2_FLAG_RX_CHECKSUM; | ||
2556 | |||
2557 | sky2_write32(sky2->hw, | ||
2558 | Q_ADDR(rxqaddr[port], Q_CSR), | ||
2559 | BMU_DIS_RX_CHKSUM); | ||
2560 | } | ||
2561 | break; | 2611 | break; |
2562 | 2612 | ||
2563 | case OP_TXINDEXLE: | 2613 | case OP_TXINDEXLE: |
@@ -3010,11 +3060,20 @@ static void sky2_reset(struct sky2_hw *hw) | |||
3010 | u32 hwe_mask = Y2_HWE_ALL_MASK; | 3060 | u32 hwe_mask = Y2_HWE_ALL_MASK; |
3011 | 3061 | ||
3012 | /* disable ASF */ | 3062 | /* disable ASF */ |
3013 | if (hw->chip_id == CHIP_ID_YUKON_EX) { | 3063 | if (hw->chip_id == CHIP_ID_YUKON_EX |
3064 | || hw->chip_id == CHIP_ID_YUKON_SUPR) { | ||
3065 | sky2_write32(hw, CPU_WDOG, 0); | ||
3014 | status = sky2_read16(hw, HCU_CCSR); | 3066 | status = sky2_read16(hw, HCU_CCSR); |
3015 | status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE | | 3067 | status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE | |
3016 | HCU_CCSR_UC_STATE_MSK); | 3068 | HCU_CCSR_UC_STATE_MSK); |
3069 | /* | ||
3070 | * CPU clock divider shouldn't be used because | ||
3071 | * - ASF firmware may malfunction | ||
3072 | * - Yukon-Supreme: Parallel FLASH doesn't support divided clocks | ||
3073 | */ | ||
3074 | status &= ~HCU_CCSR_CPU_CLK_DIVIDE_MSK; | ||
3017 | sky2_write16(hw, HCU_CCSR, status); | 3075 | sky2_write16(hw, HCU_CCSR, status); |
3076 | sky2_write32(hw, CPU_WDOG, 0); | ||
3018 | } else | 3077 | } else |
3019 | sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); | 3078 | sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); |
3020 | sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); | 3079 | sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); |
@@ -3097,7 +3156,7 @@ static void sky2_reset(struct sky2_hw *hw) | |||
3097 | /* check if PSMv2 was running before */ | 3156 | /* check if PSMv2 was running before */ |
3098 | reg = sky2_pci_read16(hw, PSM_CONFIG_REG3); | 3157 | reg = sky2_pci_read16(hw, PSM_CONFIG_REG3); |
3099 | if (reg & PCI_EXP_LNKCTL_ASPMC) { | 3158 | if (reg & PCI_EXP_LNKCTL_ASPMC) { |
3100 | int cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); | 3159 | cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
3101 | /* restore the PCIe Link Control register */ | 3160 | /* restore the PCIe Link Control register */ |
3102 | sky2_pci_write16(hw, cap + PCI_EXP_LNKCTL, reg); | 3161 | sky2_pci_write16(hw, cap + PCI_EXP_LNKCTL, reg); |
3103 | } | 3162 | } |
@@ -3188,7 +3247,9 @@ static void sky2_reset(struct sky2_hw *hw) | |||
3188 | static void sky2_detach(struct net_device *dev) | 3247 | static void sky2_detach(struct net_device *dev) |
3189 | { | 3248 | { |
3190 | if (netif_running(dev)) { | 3249 | if (netif_running(dev)) { |
3250 | netif_tx_lock(dev); | ||
3191 | netif_device_detach(dev); /* stop txq */ | 3251 | netif_device_detach(dev); /* stop txq */ |
3252 | netif_tx_unlock(dev); | ||
3192 | sky2_down(dev); | 3253 | sky2_down(dev); |
3193 | } | 3254 | } |
3194 | } | 3255 | } |
@@ -3216,48 +3277,53 @@ static int sky2_reattach(struct net_device *dev) | |||
3216 | static void sky2_restart(struct work_struct *work) | 3277 | static void sky2_restart(struct work_struct *work) |
3217 | { | 3278 | { |
3218 | struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work); | 3279 | struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work); |
3280 | u32 imask; | ||
3219 | int i; | 3281 | int i; |
3220 | 3282 | ||
3221 | rtnl_lock(); | 3283 | rtnl_lock(); |
3222 | for (i = 0; i < hw->ports; i++) | ||
3223 | sky2_detach(hw->dev[i]); | ||
3224 | 3284 | ||
3225 | napi_disable(&hw->napi); | 3285 | napi_disable(&hw->napi); |
3286 | synchronize_irq(hw->pdev->irq); | ||
3287 | imask = sky2_read32(hw, B0_IMSK); | ||
3226 | sky2_write32(hw, B0_IMSK, 0); | 3288 | sky2_write32(hw, B0_IMSK, 0); |
3227 | sky2_reset(hw); | ||
3228 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); | ||
3229 | napi_enable(&hw->napi); | ||
3230 | 3289 | ||
3231 | for (i = 0; i < hw->ports; i++) | 3290 | for (i = 0; i < hw->ports; i++) { |
3232 | sky2_reattach(hw->dev[i]); | 3291 | struct net_device *dev = hw->dev[i]; |
3292 | struct sky2_port *sky2 = netdev_priv(dev); | ||
3233 | 3293 | ||
3234 | rtnl_unlock(); | 3294 | if (!netif_running(dev)) |
3235 | } | 3295 | continue; |
3236 | 3296 | ||
3237 | static inline u8 sky2_wol_supported(const struct sky2_hw *hw) | 3297 | netif_carrier_off(dev); |
3238 | { | 3298 | netif_tx_disable(dev); |
3239 | return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; | 3299 | sky2_hw_down(sky2); |
3240 | } | 3300 | } |
3241 | 3301 | ||
3242 | static void sky2_hw_set_wol(struct sky2_hw *hw) | 3302 | sky2_reset(hw); |
3243 | { | ||
3244 | int wol = 0; | ||
3245 | int i; | ||
3246 | 3303 | ||
3247 | for (i = 0; i < hw->ports; i++) { | 3304 | for (i = 0; i < hw->ports; i++) { |
3248 | struct net_device *dev = hw->dev[i]; | 3305 | struct net_device *dev = hw->dev[i]; |
3249 | struct sky2_port *sky2 = netdev_priv(dev); | 3306 | struct sky2_port *sky2 = netdev_priv(dev); |
3250 | 3307 | ||
3251 | if (sky2->wol) | 3308 | if (!netif_running(dev)) |
3252 | wol = 1; | 3309 | continue; |
3310 | |||
3311 | sky2_hw_up(sky2); | ||
3312 | netif_wake_queue(dev); | ||
3253 | } | 3313 | } |
3254 | 3314 | ||
3255 | if (hw->chip_id == CHIP_ID_YUKON_EC_U || | 3315 | sky2_write32(hw, B0_IMSK, imask); |
3256 | hw->chip_id == CHIP_ID_YUKON_EX || | 3316 | sky2_read32(hw, B0_IMSK); |
3257 | hw->chip_id == CHIP_ID_YUKON_FE_P) | 3317 | |
3258 | sky2_write32(hw, B0_CTST, wol ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF); | 3318 | sky2_read32(hw, B0_Y2_SP_LISR); |
3319 | napi_enable(&hw->napi); | ||
3320 | |||
3321 | rtnl_unlock(); | ||
3322 | } | ||
3259 | 3323 | ||
3260 | device_set_wakeup_enable(&hw->pdev->dev, wol); | 3324 | static inline u8 sky2_wol_supported(const struct sky2_hw *hw) |
3325 | { | ||
3326 | return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; | ||
3261 | } | 3327 | } |
3262 | 3328 | ||
3263 | static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | 3329 | static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
@@ -3278,11 +3344,6 @@ static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | |||
3278 | return -EOPNOTSUPP; | 3344 | return -EOPNOTSUPP; |
3279 | 3345 | ||
3280 | sky2->wol = wol->wolopts; | 3346 | sky2->wol = wol->wolopts; |
3281 | |||
3282 | sky2_hw_set_wol(hw); | ||
3283 | |||
3284 | if (!netif_running(dev)) | ||
3285 | sky2_wol_init(sky2); | ||
3286 | return 0; | 3347 | return 0; |
3287 | } | 3348 | } |
3288 | 3349 | ||
@@ -3593,7 +3654,7 @@ static void sky2_set_multicast(struct net_device *dev) | |||
3593 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); | 3654 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
3594 | else if (dev->flags & IFF_ALLMULTI) | 3655 | else if (dev->flags & IFF_ALLMULTI) |
3595 | memset(filter, 0xff, sizeof(filter)); | 3656 | memset(filter, 0xff, sizeof(filter)); |
3596 | else if (dev->mc_count == 0 && !rx_pause) | 3657 | else if (netdev_mc_empty(dev) && !rx_pause) |
3597 | reg &= ~GM_RXCR_MCF_ENA; | 3658 | reg &= ~GM_RXCR_MCF_ENA; |
3598 | else { | 3659 | else { |
3599 | int i; | 3660 | int i; |
@@ -3602,7 +3663,7 @@ static void sky2_set_multicast(struct net_device *dev) | |||
3602 | if (rx_pause) | 3663 | if (rx_pause) |
3603 | sky2_add_filter(filter, pause_mc_addr); | 3664 | sky2_add_filter(filter, pause_mc_addr); |
3604 | 3665 | ||
3605 | for (i = 0; list && i < dev->mc_count; i++, list = list->next) | 3666 | for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next) |
3606 | sky2_add_filter(filter, list->dmi_addr); | 3667 | sky2_add_filter(filter, list->dmi_addr); |
3607 | } | 3668 | } |
3608 | 3669 | ||
@@ -3864,6 +3925,50 @@ static int sky2_get_regs_len(struct net_device *dev) | |||
3864 | return 0x4000; | 3925 | return 0x4000; |
3865 | } | 3926 | } |
3866 | 3927 | ||
3928 | static int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b) | ||
3929 | { | ||
3930 | /* This complicated switch statement is to make sure and | ||
3931 | * only access regions that are unreserved. | ||
3932 | * Some blocks are only valid on dual port cards. | ||
3933 | */ | ||
3934 | switch (b) { | ||
3935 | /* second port */ | ||
3936 | case 5: /* Tx Arbiter 2 */ | ||
3937 | case 9: /* RX2 */ | ||
3938 | case 14 ... 15: /* TX2 */ | ||
3939 | case 17: case 19: /* Ram Buffer 2 */ | ||
3940 | case 22 ... 23: /* Tx Ram Buffer 2 */ | ||
3941 | case 25: /* Rx MAC Fifo 1 */ | ||
3942 | case 27: /* Tx MAC Fifo 2 */ | ||
3943 | case 31: /* GPHY 2 */ | ||
3944 | case 40 ... 47: /* Pattern Ram 2 */ | ||
3945 | case 52: case 54: /* TCP Segmentation 2 */ | ||
3946 | case 112 ... 116: /* GMAC 2 */ | ||
3947 | return hw->ports > 1; | ||
3948 | |||
3949 | case 0: /* Control */ | ||
3950 | case 2: /* Mac address */ | ||
3951 | case 4: /* Tx Arbiter 1 */ | ||
3952 | case 7: /* PCI express reg */ | ||
3953 | case 8: /* RX1 */ | ||
3954 | case 12 ... 13: /* TX1 */ | ||
3955 | case 16: case 18:/* Rx Ram Buffer 1 */ | ||
3956 | case 20 ... 21: /* Tx Ram Buffer 1 */ | ||
3957 | case 24: /* Rx MAC Fifo 1 */ | ||
3958 | case 26: /* Tx MAC Fifo 1 */ | ||
3959 | case 28 ... 29: /* Descriptor and status unit */ | ||
3960 | case 30: /* GPHY 1*/ | ||
3961 | case 32 ... 39: /* Pattern Ram 1 */ | ||
3962 | case 48: case 50: /* TCP Segmentation 1 */ | ||
3963 | case 56 ... 60: /* PCI space */ | ||
3964 | case 80 ... 84: /* GMAC 1 */ | ||
3965 | return 1; | ||
3966 | |||
3967 | default: | ||
3968 | return 0; | ||
3969 | } | ||
3970 | } | ||
3971 | |||
3867 | /* | 3972 | /* |
3868 | * Returns copy of control register region | 3973 | * Returns copy of control register region |
3869 | * Note: ethtool_get_regs always provides full size (16k) buffer | 3974 | * Note: ethtool_get_regs always provides full size (16k) buffer |
@@ -3878,55 +3983,13 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, | |||
3878 | regs->version = 1; | 3983 | regs->version = 1; |
3879 | 3984 | ||
3880 | for (b = 0; b < 128; b++) { | 3985 | for (b = 0; b < 128; b++) { |
3881 | /* This complicated switch statement is to make sure and | 3986 | /* skip poisonous diagnostic ram region in block 3 */ |
3882 | * only access regions that are unreserved. | 3987 | if (b == 3) |
3883 | * Some blocks are only valid on dual port cards. | ||
3884 | * and block 3 has some special diagnostic registers that | ||
3885 | * are poison. | ||
3886 | */ | ||
3887 | switch (b) { | ||
3888 | case 3: | ||
3889 | /* skip diagnostic ram region */ | ||
3890 | memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10); | 3988 | memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10); |
3891 | break; | 3989 | else if (sky2_reg_access_ok(sky2->hw, b)) |
3892 | |||
3893 | /* dual port cards only */ | ||
3894 | case 5: /* Tx Arbiter 2 */ | ||
3895 | case 9: /* RX2 */ | ||
3896 | case 14 ... 15: /* TX2 */ | ||
3897 | case 17: case 19: /* Ram Buffer 2 */ | ||
3898 | case 22 ... 23: /* Tx Ram Buffer 2 */ | ||
3899 | case 25: /* Rx MAC Fifo 1 */ | ||
3900 | case 27: /* Tx MAC Fifo 2 */ | ||
3901 | case 31: /* GPHY 2 */ | ||
3902 | case 40 ... 47: /* Pattern Ram 2 */ | ||
3903 | case 52: case 54: /* TCP Segmentation 2 */ | ||
3904 | case 112 ... 116: /* GMAC 2 */ | ||
3905 | if (sky2->hw->ports == 1) | ||
3906 | goto reserved; | ||
3907 | /* fall through */ | ||
3908 | case 0: /* Control */ | ||
3909 | case 2: /* Mac address */ | ||
3910 | case 4: /* Tx Arbiter 1 */ | ||
3911 | case 7: /* PCI express reg */ | ||
3912 | case 8: /* RX1 */ | ||
3913 | case 12 ... 13: /* TX1 */ | ||
3914 | case 16: case 18:/* Rx Ram Buffer 1 */ | ||
3915 | case 20 ... 21: /* Tx Ram Buffer 1 */ | ||
3916 | case 24: /* Rx MAC Fifo 1 */ | ||
3917 | case 26: /* Tx MAC Fifo 1 */ | ||
3918 | case 28 ... 29: /* Descriptor and status unit */ | ||
3919 | case 30: /* GPHY 1*/ | ||
3920 | case 32 ... 39: /* Pattern Ram 1 */ | ||
3921 | case 48: case 50: /* TCP Segmentation 1 */ | ||
3922 | case 56 ... 60: /* PCI space */ | ||
3923 | case 80 ... 84: /* GMAC 1 */ | ||
3924 | memcpy_fromio(p, io, 128); | 3990 | memcpy_fromio(p, io, 128); |
3925 | break; | 3991 | else |
3926 | default: | ||
3927 | reserved: | ||
3928 | memset(p, 0, 128); | 3992 | memset(p, 0, 128); |
3929 | } | ||
3930 | 3993 | ||
3931 | p += 128; | 3994 | p += 128; |
3932 | io += 128; | 3995 | io += 128; |
@@ -4774,7 +4837,6 @@ static void __devexit sky2_remove(struct pci_dev *pdev) | |||
4774 | pci_set_drvdata(pdev, NULL); | 4837 | pci_set_drvdata(pdev, NULL); |
4775 | } | 4838 | } |
4776 | 4839 | ||
4777 | #ifdef CONFIG_PM | ||
4778 | static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) | 4840 | static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) |
4779 | { | 4841 | { |
4780 | struct sky2_hw *hw = pci_get_drvdata(pdev); | 4842 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
@@ -4799,6 +4861,8 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) | |||
4799 | wol |= sky2->wol; | 4861 | wol |= sky2->wol; |
4800 | } | 4862 | } |
4801 | 4863 | ||
4864 | device_set_wakeup_enable(&pdev->dev, wol != 0); | ||
4865 | |||
4802 | sky2_write32(hw, B0_IMSK, 0); | 4866 | sky2_write32(hw, B0_IMSK, 0); |
4803 | napi_disable(&hw->napi); | 4867 | napi_disable(&hw->napi); |
4804 | sky2_power_aux(hw); | 4868 | sky2_power_aux(hw); |
@@ -4811,6 +4875,7 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) | |||
4811 | return 0; | 4875 | return 0; |
4812 | } | 4876 | } |
4813 | 4877 | ||
4878 | #ifdef CONFIG_PM | ||
4814 | static int sky2_resume(struct pci_dev *pdev) | 4879 | static int sky2_resume(struct pci_dev *pdev) |
4815 | { | 4880 | { |
4816 | struct sky2_hw *hw = pci_get_drvdata(pdev); | 4881 | struct sky2_hw *hw = pci_get_drvdata(pdev); |
@@ -4830,10 +4895,11 @@ static int sky2_resume(struct pci_dev *pdev) | |||
4830 | pci_enable_wake(pdev, PCI_D0, 0); | 4895 | pci_enable_wake(pdev, PCI_D0, 0); |
4831 | 4896 | ||
4832 | /* Re-enable all clocks */ | 4897 | /* Re-enable all clocks */ |
4833 | if (hw->chip_id == CHIP_ID_YUKON_EX || | 4898 | err = pci_write_config_dword(pdev, PCI_DEV_REG3, 0); |
4834 | hw->chip_id == CHIP_ID_YUKON_EC_U || | 4899 | if (err) { |
4835 | hw->chip_id == CHIP_ID_YUKON_FE_P) | 4900 | dev_err(&pdev->dev, "PCI write config failed\n"); |
4836 | sky2_pci_write32(hw, PCI_DEV_REG3, 0); | 4901 | goto out; |
4902 | } | ||
4837 | 4903 | ||
4838 | sky2_reset(hw); | 4904 | sky2_reset(hw); |
4839 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); | 4905 | sky2_write32(hw, B0_IMSK, Y2_IS_BASE); |
@@ -4859,34 +4925,7 @@ out: | |||
4859 | 4925 | ||
4860 | static void sky2_shutdown(struct pci_dev *pdev) | 4926 | static void sky2_shutdown(struct pci_dev *pdev) |
4861 | { | 4927 | { |
4862 | struct sky2_hw *hw = pci_get_drvdata(pdev); | 4928 | sky2_suspend(pdev, PMSG_SUSPEND); |
4863 | int i, wol = 0; | ||
4864 | |||
4865 | if (!hw) | ||
4866 | return; | ||
4867 | |||
4868 | rtnl_lock(); | ||
4869 | del_timer_sync(&hw->watchdog_timer); | ||
4870 | |||
4871 | for (i = 0; i < hw->ports; i++) { | ||
4872 | struct net_device *dev = hw->dev[i]; | ||
4873 | struct sky2_port *sky2 = netdev_priv(dev); | ||
4874 | |||
4875 | if (sky2->wol) { | ||
4876 | wol = 1; | ||
4877 | sky2_wol_init(sky2); | ||
4878 | } | ||
4879 | } | ||
4880 | |||
4881 | if (wol) | ||
4882 | sky2_power_aux(hw); | ||
4883 | rtnl_unlock(); | ||
4884 | |||
4885 | pci_enable_wake(pdev, PCI_D3hot, wol); | ||
4886 | pci_enable_wake(pdev, PCI_D3cold, wol); | ||
4887 | |||
4888 | pci_disable_device(pdev); | ||
4889 | pci_set_power_state(pdev, PCI_D3hot); | ||
4890 | } | 4929 | } |
4891 | 4930 | ||
4892 | static struct pci_driver sky2_driver = { | 4931 | static struct pci_driver sky2_driver = { |