Merge branch 'fwnet' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6

* 'fwnet' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6:
firewire: net: throttle TX queue before running out of tlabels
firewire: net: replace lists by counters
firewire: net: fix memory leaks
firewire: net: count stats.tx_packets and stats.tx_bytes

+90 -70
+90 -70
drivers/firewire/net.c
··· 7 7 */ 8 8 9 9 #include <linux/bug.h> 10 + #include <linux/delay.h> 10 11 #include <linux/device.h> 11 12 #include <linux/firewire.h> 12 13 #include <linux/firewire-constants.h> ··· 27 26 #include <asm/unaligned.h> 28 27 #include <net/arp.h> 29 28 30 - #define FWNET_MAX_FRAGMENTS 25 /* arbitrary limit */ 31 - #define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16 * 1024 ? 4 : 2) 29 + /* rx limits */ 30 + #define FWNET_MAX_FRAGMENTS 30 /* arbitrary, > TX queue depth */ 31 + #define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16*1024 ? 4 : 2) 32 + 33 + /* tx limits */ 34 + #define FWNET_MAX_QUEUED_DATAGRAMS 20 /* < 64 = number of tlabels */ 35 + #define FWNET_MIN_QUEUED_DATAGRAMS 10 /* should keep AT DMA busy enough */ 36 + #define FWNET_TX_QUEUE_LEN FWNET_MAX_QUEUED_DATAGRAMS /* ? */ 32 37 33 38 #define IEEE1394_BROADCAST_CHANNEL 31 34 39 #define IEEE1394_ALL_NODES (0xffc0 | 0x003f) ··· 176 169 struct fw_address_handler handler; 177 170 u64 local_fifo; 178 171 179 - /* List of packets to be sent */ 180 - struct list_head packet_list; 181 - /* 182 - * List of packets that were broadcasted. When we get an ISO interrupt 183 - * one of them has been sent 184 - */ 185 - struct list_head broadcasted_list; 186 - /* List of packets that have been sent but not yet acked */ 187 - struct list_head sent_list; 172 + /* Number of tx datagrams that have been queued but not yet acked */ 173 + int queued_datagrams; 188 174 189 175 struct list_head peer_list; 190 176 struct fw_card *card; ··· 195 195 unsigned pdg_size; /* pd_list size */ 196 196 197 197 u16 datagram_label; /* outgoing datagram label */ 198 - unsigned max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ 198 + u16 max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ 199 199 int node_id; 200 200 int generation; 201 201 unsigned speed; ··· 203 203 204 204 /* This is our task struct. It's used for the packet complete callback. */ 205 205 struct fwnet_packet_task { 206 - /* 207 - * ptask can actually be on dev->packet_list, dev->broadcasted_list, 208 - * or dev->sent_list depending on its current state. 209 - */ 210 - struct list_head pt_link; 211 206 struct fw_transaction transaction; 212 207 struct rfc2734_header hdr; 213 208 struct sk_buff *skb; 214 209 struct fwnet_device *dev; 215 210 216 211 int outstanding_pkts; 217 - unsigned max_payload; 218 212 u64 fifo_addr; 219 213 u16 dest_node; 214 + u16 max_payload; 220 215 u8 generation; 221 216 u8 speed; 217 + u8 enqueued; 222 218 }; 223 219 224 220 /* ··· 646 650 net->stats.rx_packets++; 647 651 net->stats.rx_bytes += skb->len; 648 652 } 649 - if (netif_queue_stopped(net)) 650 - netif_wake_queue(net); 651 653 652 654 return 0; 653 655 ··· 654 660 net->stats.rx_dropped++; 655 661 656 662 dev_kfree_skb_any(skb); 657 - if (netif_queue_stopped(net)) 658 - netif_wake_queue(net); 659 663 660 664 return -ENOENT; 661 665 } ··· 785 793 * Datagram is not complete, we're done for the 786 794 * moment. 787 795 */ 788 - spin_unlock_irqrestore(&dev->lock, flags); 789 - 790 - return 0; 796 + retval = 0; 791 797 fail: 792 798 spin_unlock_irqrestore(&dev->lock, flags); 793 - 794 - if (netif_queue_stopped(net)) 795 - netif_wake_queue(net); 796 799 797 800 return retval; 798 801 } ··· 888 901 kmem_cache_free(fwnet_packet_task_cache, ptask); 889 902 } 890 903 904 + /* Caller must hold dev->lock. */ 905 + static void dec_queued_datagrams(struct fwnet_device *dev) 906 + { 907 + if (--dev->queued_datagrams == FWNET_MIN_QUEUED_DATAGRAMS) 908 + netif_wake_queue(dev->netdev); 909 + } 910 + 891 911 static int fwnet_send_packet(struct fwnet_packet_task *ptask); 892 912 893 913 static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask) 894 914 { 895 915 struct fwnet_device *dev = ptask->dev; 916 + struct sk_buff *skb = ptask->skb; 896 917 unsigned long flags; 897 918 bool free; 898 919 ··· 909 914 ptask->outstanding_pkts--; 910 915 911 916 /* Check whether we or the networking TX soft-IRQ is last user. */ 912 - free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link)); 917 + free = (ptask->outstanding_pkts == 0 && ptask->enqueued); 918 + if (free) 919 + dec_queued_datagrams(dev); 913 920 914 - if (ptask->outstanding_pkts == 0) 915 - list_del(&ptask->pt_link); 921 + if (ptask->outstanding_pkts == 0) { 922 + dev->netdev->stats.tx_packets++; 923 + dev->netdev->stats.tx_bytes += skb->len; 924 + } 916 925 917 926 spin_unlock_irqrestore(&dev->lock, flags); 918 927 ··· 925 926 u16 fg_off; 926 927 u16 datagram_label; 927 928 u16 lf; 928 - struct sk_buff *skb; 929 929 930 930 /* Update the ptask to point to the next fragment and send it */ 931 931 lf = fwnet_get_hdr_lf(&ptask->hdr); ··· 951 953 datagram_label = fwnet_get_hdr_dgl(&ptask->hdr); 952 954 break; 953 955 } 954 - skb = ptask->skb; 956 + 955 957 skb_pull(skb, ptask->max_payload); 956 958 if (ptask->outstanding_pkts > 1) { 957 959 fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG, ··· 968 970 fwnet_free_ptask(ptask); 969 971 } 970 972 973 + static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask) 974 + { 975 + struct fwnet_device *dev = ptask->dev; 976 + unsigned long flags; 977 + bool free; 978 + 979 + spin_lock_irqsave(&dev->lock, flags); 980 + 981 + /* One fragment failed; don't try to send remaining fragments. */ 982 + ptask->outstanding_pkts = 0; 983 + 984 + /* Check whether we or the networking TX soft-IRQ is last user. */ 985 + free = ptask->enqueued; 986 + if (free) 987 + dec_queued_datagrams(dev); 988 + 989 + dev->netdev->stats.tx_dropped++; 990 + dev->netdev->stats.tx_errors++; 991 + 992 + spin_unlock_irqrestore(&dev->lock, flags); 993 + 994 + if (free) 995 + fwnet_free_ptask(ptask); 996 + } 997 + 971 998 static void fwnet_write_complete(struct fw_card *card, int rcode, 972 999 void *payload, size_t length, void *data) 973 1000 { ··· 1000 977 1001 978 ptask = data; 1002 979 1003 - if (rcode == RCODE_COMPLETE) 980 + if (rcode == RCODE_COMPLETE) { 1004 981 fwnet_transmit_packet_done(ptask); 1005 - else 982 + } else { 1006 983 fw_error("fwnet_write_complete: failed: %x\n", rcode); 1007 - /* ??? error recovery */ 984 + fwnet_transmit_packet_failed(ptask); 985 + } 1008 986 } 1009 987 1010 988 static int fwnet_send_packet(struct fwnet_packet_task *ptask) ··· 1063 1039 spin_lock_irqsave(&dev->lock, flags); 1064 1040 1065 1041 /* If the AT tasklet already ran, we may be last user. */ 1066 - free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1042 + free = (ptask->outstanding_pkts == 0 && !ptask->enqueued); 1067 1043 if (!free) 1068 - list_add_tail(&ptask->pt_link, &dev->broadcasted_list); 1044 + ptask->enqueued = true; 1045 + else 1046 + dec_queued_datagrams(dev); 1069 1047 1070 1048 spin_unlock_irqrestore(&dev->lock, flags); 1071 1049 ··· 1082 1056 spin_lock_irqsave(&dev->lock, flags); 1083 1057 1084 1058 /* If the AT tasklet already ran, we may be last user. */ 1085 - free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1059 + free = (ptask->outstanding_pkts == 0 && !ptask->enqueued); 1086 1060 if (!free) 1087 - list_add_tail(&ptask->pt_link, &dev->sent_list); 1061 + ptask->enqueued = true; 1062 + else 1063 + dec_queued_datagrams(dev); 1088 1064 1089 1065 spin_unlock_irqrestore(&dev->lock, flags); 1090 1066 ··· 1252 1224 struct fwnet_peer *peer; 1253 1225 unsigned long flags; 1254 1226 1227 + spin_lock_irqsave(&dev->lock, flags); 1228 + 1229 + /* Can this happen? */ 1230 + if (netif_queue_stopped(dev->netdev)) { 1231 + spin_unlock_irqrestore(&dev->lock, flags); 1232 + 1233 + return NETDEV_TX_BUSY; 1234 + } 1235 + 1255 1236 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC); 1256 1237 if (ptask == NULL) 1257 1238 goto fail; ··· 1278 1241 1279 1242 proto = hdr_buf.h_proto; 1280 1243 dg_size = skb->len; 1281 - 1282 - /* serialize access to peer, including peer->datagram_label */ 1283 - spin_lock_irqsave(&dev->lock, flags); 1284 1244 1285 1245 /* 1286 1246 * Set the transmission type for the packet. ARP packets and IP ··· 1300 1266 1301 1267 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid)); 1302 1268 if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR) 1303 - goto fail_unlock; 1269 + goto fail; 1304 1270 1305 1271 generation = peer->generation; 1306 1272 dest_node = peer->node_id; ··· 1354 1320 max_payload += RFC2374_FRAG_HDR_SIZE; 1355 1321 } 1356 1322 1323 + if (++dev->queued_datagrams == FWNET_MAX_QUEUED_DATAGRAMS) 1324 + netif_stop_queue(dev->netdev); 1325 + 1357 1326 spin_unlock_irqrestore(&dev->lock, flags); 1358 1327 1359 1328 ptask->max_payload = max_payload; 1360 - INIT_LIST_HEAD(&ptask->pt_link); 1329 + ptask->enqueued = 0; 1361 1330 1362 1331 fwnet_send_packet(ptask); 1363 1332 1364 1333 return NETDEV_TX_OK; 1365 1334 1366 - fail_unlock: 1367 - spin_unlock_irqrestore(&dev->lock, flags); 1368 1335 fail: 1336 + spin_unlock_irqrestore(&dev->lock, flags); 1337 + 1369 1338 if (ptask) 1370 1339 kmem_cache_free(fwnet_packet_task_cache, ptask); 1371 1340 ··· 1414 1377 net->addr_len = FWNET_ALEN; 1415 1378 net->hard_header_len = FWNET_HLEN; 1416 1379 net->type = ARPHRD_IEEE1394; 1417 - net->tx_queue_len = 10; 1380 + net->tx_queue_len = FWNET_TX_QUEUE_LEN; 1418 1381 } 1419 1382 1420 1383 /* caller must hold fwnet_device_mutex */ ··· 1494 1457 dev->broadcast_rcv_context = NULL; 1495 1458 dev->broadcast_xmt_max_payload = 0; 1496 1459 dev->broadcast_xmt_datagramlabel = 0; 1497 - 1498 1460 dev->local_fifo = FWNET_NO_FIFO_ADDR; 1499 - 1500 - INIT_LIST_HEAD(&dev->packet_list); 1501 - INIT_LIST_HEAD(&dev->broadcasted_list); 1502 - INIT_LIST_HEAD(&dev->sent_list); 1461 + dev->queued_datagrams = 0; 1503 1462 INIT_LIST_HEAD(&dev->peer_list); 1504 - 1505 1463 dev->card = card; 1506 1464 dev->netdev = net; 1507 1465 ··· 1554 1522 struct fwnet_peer *peer = dev_get_drvdata(_dev); 1555 1523 struct fwnet_device *dev = peer->dev; 1556 1524 struct net_device *net; 1557 - struct fwnet_packet_task *ptask, *pt_next; 1525 + int i; 1558 1526 1559 1527 mutex_lock(&fwnet_device_mutex); 1560 1528 ··· 1572 1540 dev->card); 1573 1541 fw_iso_context_destroy(dev->broadcast_rcv_context); 1574 1542 } 1575 - list_for_each_entry_safe(ptask, pt_next, 1576 - &dev->packet_list, pt_link) { 1577 - dev_kfree_skb_any(ptask->skb); 1578 - kmem_cache_free(fwnet_packet_task_cache, ptask); 1579 - } 1580 - list_for_each_entry_safe(ptask, pt_next, 1581 - &dev->broadcasted_list, pt_link) { 1582 - dev_kfree_skb_any(ptask->skb); 1583 - kmem_cache_free(fwnet_packet_task_cache, ptask); 1584 - } 1585 - list_for_each_entry_safe(ptask, pt_next, 1586 - &dev->sent_list, pt_link) { 1587 - dev_kfree_skb_any(ptask->skb); 1588 - kmem_cache_free(fwnet_packet_task_cache, ptask); 1589 - } 1543 + for (i = 0; dev->queued_datagrams && i < 5; i++) 1544 + ssleep(1); 1545 + WARN_ON(dev->queued_datagrams); 1590 1546 list_del(&dev->dev_link); 1591 1547 1592 1548 free_netdev(net);