aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firewire/net.c')
-rw-r--r--drivers/firewire/net.c227
1 files changed, 137 insertions, 90 deletions
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 33f8421c71cc..b9762d07198d 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/bug.h> 9#include <linux/bug.h>
10#include <linux/delay.h>
10#include <linux/device.h> 11#include <linux/device.h>
11#include <linux/ethtool.h> 12#include <linux/ethtool.h>
12#include <linux/firewire.h> 13#include <linux/firewire.h>
@@ -27,8 +28,14 @@
27#include <asm/unaligned.h> 28#include <asm/unaligned.h>
28#include <net/arp.h> 29#include <net/arp.h>
29 30
30#define FWNET_MAX_FRAGMENTS 25 /* arbitrary limit */ 31/* rx limits */
31#define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16 * 1024 ? 4 : 2) 32#define FWNET_MAX_FRAGMENTS 30 /* arbitrary, > TX queue depth */
33#define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16*1024 ? 4 : 2)
34
35/* tx limits */
36#define FWNET_MAX_QUEUED_DATAGRAMS 20 /* < 64 = number of tlabels */
37#define FWNET_MIN_QUEUED_DATAGRAMS 10 /* should keep AT DMA busy enough */
38#define FWNET_TX_QUEUE_LEN FWNET_MAX_QUEUED_DATAGRAMS /* ? */
32 39
33#define IEEE1394_BROADCAST_CHANNEL 31 40#define IEEE1394_BROADCAST_CHANNEL 31
34#define IEEE1394_ALL_NODES (0xffc0 | 0x003f) 41#define IEEE1394_ALL_NODES (0xffc0 | 0x003f)
@@ -170,16 +177,10 @@ struct fwnet_device {
170 struct fw_address_handler handler; 177 struct fw_address_handler handler;
171 u64 local_fifo; 178 u64 local_fifo;
172 179
173 /* List of packets to be sent */ 180 /* Number of tx datagrams that have been queued but not yet acked */
174 struct list_head packet_list; 181 int queued_datagrams;
175 /*
176 * List of packets that were broadcasted. When we get an ISO interrupt
177 * one of them has been sent
178 */
179 struct list_head broadcasted_list;
180 /* List of packets that have been sent but not yet acked */
181 struct list_head sent_list;
182 182
183 int peer_count;
183 struct list_head peer_list; 184 struct list_head peer_list;
184 struct fw_card *card; 185 struct fw_card *card;
185 struct net_device *netdev; 186 struct net_device *netdev;
@@ -190,13 +191,14 @@ struct fwnet_peer {
190 struct fwnet_device *dev; 191 struct fwnet_device *dev;
191 u64 guid; 192 u64 guid;
192 u64 fifo; 193 u64 fifo;
194 __be32 ip;
193 195
194 /* guarded by dev->lock */ 196 /* guarded by dev->lock */
195 struct list_head pd_list; /* received partial datagrams */ 197 struct list_head pd_list; /* received partial datagrams */
196 unsigned pdg_size; /* pd_list size */ 198 unsigned pdg_size; /* pd_list size */
197 199
198 u16 datagram_label; /* outgoing datagram label */ 200 u16 datagram_label; /* outgoing datagram label */
199 unsigned max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ 201 u16 max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */
200 int node_id; 202 int node_id;
201 int generation; 203 int generation;
202 unsigned speed; 204 unsigned speed;
@@ -204,22 +206,18 @@ struct fwnet_peer {
204 206
205/* This is our task struct. It's used for the packet complete callback. */ 207/* This is our task struct. It's used for the packet complete callback. */
206struct fwnet_packet_task { 208struct fwnet_packet_task {
207 /*
208 * ptask can actually be on dev->packet_list, dev->broadcasted_list,
209 * or dev->sent_list depending on its current state.
210 */
211 struct list_head pt_link;
212 struct fw_transaction transaction; 209 struct fw_transaction transaction;
213 struct rfc2734_header hdr; 210 struct rfc2734_header hdr;
214 struct sk_buff *skb; 211 struct sk_buff *skb;
215 struct fwnet_device *dev; 212 struct fwnet_device *dev;
216 213
217 int outstanding_pkts; 214 int outstanding_pkts;
218 unsigned max_payload;
219 u64 fifo_addr; 215 u64 fifo_addr;
220 u16 dest_node; 216 u16 dest_node;
217 u16 max_payload;
221 u8 generation; 218 u8 generation;
222 u8 speed; 219 u8 speed;
220 u8 enqueued;
223}; 221};
224 222
225/* 223/*
@@ -455,7 +453,7 @@ static bool fwnet_pd_update(struct fwnet_peer *peer,
455 memcpy(pd->pbuf + frag_off, frag_buf, frag_len); 453 memcpy(pd->pbuf + frag_off, frag_buf, frag_len);
456 454
457 /* 455 /*
458 * Move list entry to beginnig of list so that oldest partial 456 * Move list entry to beginning of list so that oldest partial
459 * datagrams percolate to the end of the list 457 * datagrams percolate to the end of the list
460 */ 458 */
461 list_move_tail(&pd->pd_link, &peer->pd_list); 459 list_move_tail(&pd->pd_link, &peer->pd_list);
@@ -573,6 +571,8 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
573 peer->speed = sspd; 571 peer->speed = sspd;
574 if (peer->max_payload > max_payload) 572 if (peer->max_payload > max_payload)
575 peer->max_payload = max_payload; 573 peer->max_payload = max_payload;
574
575 peer->ip = arp1394->sip;
576 } 576 }
577 spin_unlock_irqrestore(&dev->lock, flags); 577 spin_unlock_irqrestore(&dev->lock, flags);
578 578
@@ -651,8 +651,6 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
651 net->stats.rx_packets++; 651 net->stats.rx_packets++;
652 net->stats.rx_bytes += skb->len; 652 net->stats.rx_bytes += skb->len;
653 } 653 }
654 if (netif_queue_stopped(net))
655 netif_wake_queue(net);
656 654
657 return 0; 655 return 0;
658 656
@@ -661,8 +659,6 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
661 net->stats.rx_dropped++; 659 net->stats.rx_dropped++;
662 660
663 dev_kfree_skb_any(skb); 661 dev_kfree_skb_any(skb);
664 if (netif_queue_stopped(net))
665 netif_wake_queue(net);
666 662
667 return -ENOENT; 663 return -ENOENT;
668} 664}
@@ -794,15 +790,10 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
794 * Datagram is not complete, we're done for the 790 * Datagram is not complete, we're done for the
795 * moment. 791 * moment.
796 */ 792 */
797 spin_unlock_irqrestore(&dev->lock, flags); 793 retval = 0;
798
799 return 0;
800 fail: 794 fail:
801 spin_unlock_irqrestore(&dev->lock, flags); 795 spin_unlock_irqrestore(&dev->lock, flags);
802 796
803 if (netif_queue_stopped(net))
804 netif_wake_queue(net);
805
806 return retval; 797 return retval;
807} 798}
808 799
@@ -890,7 +881,9 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
890 881
891 spin_unlock_irqrestore(&dev->lock, flags); 882 spin_unlock_irqrestore(&dev->lock, flags);
892 883
893 if (retval < 0) 884 if (retval >= 0)
885 fw_iso_context_queue_flush(dev->broadcast_rcv_context);
886 else
894 fw_error("requeue failed\n"); 887 fw_error("requeue failed\n");
895} 888}
896 889
@@ -902,11 +895,19 @@ static void fwnet_free_ptask(struct fwnet_packet_task *ptask)
902 kmem_cache_free(fwnet_packet_task_cache, ptask); 895 kmem_cache_free(fwnet_packet_task_cache, ptask);
903} 896}
904 897
898/* Caller must hold dev->lock. */
899static void dec_queued_datagrams(struct fwnet_device *dev)
900{
901 if (--dev->queued_datagrams == FWNET_MIN_QUEUED_DATAGRAMS)
902 netif_wake_queue(dev->netdev);
903}
904
905static int fwnet_send_packet(struct fwnet_packet_task *ptask); 905static int fwnet_send_packet(struct fwnet_packet_task *ptask);
906 906
907static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask) 907static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
908{ 908{
909 struct fwnet_device *dev = ptask->dev; 909 struct fwnet_device *dev = ptask->dev;
910 struct sk_buff *skb = ptask->skb;
910 unsigned long flags; 911 unsigned long flags;
911 bool free; 912 bool free;
912 913
@@ -915,10 +916,14 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
915 ptask->outstanding_pkts--; 916 ptask->outstanding_pkts--;
916 917
917 /* Check whether we or the networking TX soft-IRQ is last user. */ 918 /* Check whether we or the networking TX soft-IRQ is last user. */
918 free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link)); 919 free = (ptask->outstanding_pkts == 0 && ptask->enqueued);
920 if (free)
921 dec_queued_datagrams(dev);
919 922
920 if (ptask->outstanding_pkts == 0) 923 if (ptask->outstanding_pkts == 0) {
921 list_del(&ptask->pt_link); 924 dev->netdev->stats.tx_packets++;
925 dev->netdev->stats.tx_bytes += skb->len;
926 }
922 927
923 spin_unlock_irqrestore(&dev->lock, flags); 928 spin_unlock_irqrestore(&dev->lock, flags);
924 929
@@ -927,7 +932,6 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
927 u16 fg_off; 932 u16 fg_off;
928 u16 datagram_label; 933 u16 datagram_label;
929 u16 lf; 934 u16 lf;
930 struct sk_buff *skb;
931 935
932 /* Update the ptask to point to the next fragment and send it */ 936 /* Update the ptask to point to the next fragment and send it */
933 lf = fwnet_get_hdr_lf(&ptask->hdr); 937 lf = fwnet_get_hdr_lf(&ptask->hdr);
@@ -954,7 +958,7 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
954 datagram_label = fwnet_get_hdr_dgl(&ptask->hdr); 958 datagram_label = fwnet_get_hdr_dgl(&ptask->hdr);
955 break; 959 break;
956 } 960 }
957 skb = ptask->skb; 961
958 skb_pull(skb, ptask->max_payload); 962 skb_pull(skb, ptask->max_payload);
959 if (ptask->outstanding_pkts > 1) { 963 if (ptask->outstanding_pkts > 1) {
960 fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG, 964 fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG,
@@ -971,18 +975,52 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
971 fwnet_free_ptask(ptask); 975 fwnet_free_ptask(ptask);
972} 976}
973 977
978static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask)
979{
980 struct fwnet_device *dev = ptask->dev;
981 unsigned long flags;
982 bool free;
983
984 spin_lock_irqsave(&dev->lock, flags);
985
986 /* One fragment failed; don't try to send remaining fragments. */
987 ptask->outstanding_pkts = 0;
988
989 /* Check whether we or the networking TX soft-IRQ is last user. */
990 free = ptask->enqueued;
991 if (free)
992 dec_queued_datagrams(dev);
993
994 dev->netdev->stats.tx_dropped++;
995 dev->netdev->stats.tx_errors++;
996
997 spin_unlock_irqrestore(&dev->lock, flags);
998
999 if (free)
1000 fwnet_free_ptask(ptask);
1001}
1002
974static void fwnet_write_complete(struct fw_card *card, int rcode, 1003static void fwnet_write_complete(struct fw_card *card, int rcode,
975 void *payload, size_t length, void *data) 1004 void *payload, size_t length, void *data)
976{ 1005{
977 struct fwnet_packet_task *ptask; 1006 struct fwnet_packet_task *ptask = data;
978 1007 static unsigned long j;
979 ptask = data; 1008 static int last_rcode, errors_skipped;
980 1009
981 if (rcode == RCODE_COMPLETE) 1010 if (rcode == RCODE_COMPLETE) {
982 fwnet_transmit_packet_done(ptask); 1011 fwnet_transmit_packet_done(ptask);
983 else 1012 } else {
984 fw_error("fwnet_write_complete: failed: %x\n", rcode); 1013 fwnet_transmit_packet_failed(ptask);
985 /* ??? error recovery */ 1014
1015 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) {
1016 fw_error("fwnet_write_complete: "
1017 "failed: %x (skipped %d)\n", rcode, errors_skipped);
1018
1019 errors_skipped = 0;
1020 last_rcode = rcode;
1021 } else
1022 errors_skipped++;
1023 }
986} 1024}
987 1025
988static int fwnet_send_packet(struct fwnet_packet_task *ptask) 1026static int fwnet_send_packet(struct fwnet_packet_task *ptask)
@@ -1040,9 +1078,11 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
1040 spin_lock_irqsave(&dev->lock, flags); 1078 spin_lock_irqsave(&dev->lock, flags);
1041 1079
1042 /* If the AT tasklet already ran, we may be last user. */ 1080 /* If the AT tasklet already ran, we may be last user. */
1043 free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1081 free = (ptask->outstanding_pkts == 0 && !ptask->enqueued);
1044 if (!free) 1082 if (!free)
1045 list_add_tail(&ptask->pt_link, &dev->broadcasted_list); 1083 ptask->enqueued = true;
1084 else
1085 dec_queued_datagrams(dev);
1046 1086
1047 spin_unlock_irqrestore(&dev->lock, flags); 1087 spin_unlock_irqrestore(&dev->lock, flags);
1048 1088
@@ -1057,9 +1097,11 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
1057 spin_lock_irqsave(&dev->lock, flags); 1097 spin_lock_irqsave(&dev->lock, flags);
1058 1098
1059 /* If the AT tasklet already ran, we may be last user. */ 1099 /* If the AT tasklet already ran, we may be last user. */
1060 free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1100 free = (ptask->outstanding_pkts == 0 && !ptask->enqueued);
1061 if (!free) 1101 if (!free)
1062 list_add_tail(&ptask->pt_link, &dev->sent_list); 1102 ptask->enqueued = true;
1103 else
1104 dec_queued_datagrams(dev);
1063 1105
1064 spin_unlock_irqrestore(&dev->lock, flags); 1106 spin_unlock_irqrestore(&dev->lock, flags);
1065 1107
@@ -1186,6 +1228,14 @@ static int fwnet_broadcast_start(struct fwnet_device *dev)
1186 return retval; 1228 return retval;
1187} 1229}
1188 1230
1231static void set_carrier_state(struct fwnet_device *dev)
1232{
1233 if (dev->peer_count > 1)
1234 netif_carrier_on(dev->netdev);
1235 else
1236 netif_carrier_off(dev->netdev);
1237}
1238
1189/* ifup */ 1239/* ifup */
1190static int fwnet_open(struct net_device *net) 1240static int fwnet_open(struct net_device *net)
1191{ 1241{
@@ -1199,6 +1249,10 @@ static int fwnet_open(struct net_device *net)
1199 } 1249 }
1200 netif_start_queue(net); 1250 netif_start_queue(net);
1201 1251
1252 spin_lock_irq(&dev->lock);
1253 set_carrier_state(dev);
1254 spin_unlock_irq(&dev->lock);
1255
1202 return 0; 1256 return 0;
1203} 1257}
1204 1258
@@ -1225,6 +1279,15 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1225 struct fwnet_peer *peer; 1279 struct fwnet_peer *peer;
1226 unsigned long flags; 1280 unsigned long flags;
1227 1281
1282 spin_lock_irqsave(&dev->lock, flags);
1283
1284 /* Can this happen? */
1285 if (netif_queue_stopped(dev->netdev)) {
1286 spin_unlock_irqrestore(&dev->lock, flags);
1287
1288 return NETDEV_TX_BUSY;
1289 }
1290
1228 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC); 1291 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC);
1229 if (ptask == NULL) 1292 if (ptask == NULL)
1230 goto fail; 1293 goto fail;
@@ -1243,9 +1306,6 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1243 proto = hdr_buf.h_proto; 1306 proto = hdr_buf.h_proto;
1244 dg_size = skb->len; 1307 dg_size = skb->len;
1245 1308
1246 /* serialize access to peer, including peer->datagram_label */
1247 spin_lock_irqsave(&dev->lock, flags);
1248
1249 /* 1309 /*
1250 * Set the transmission type for the packet. ARP packets and IP 1310 * Set the transmission type for the packet. ARP packets and IP
1251 * broadcast packets are sent via GASP. 1311 * broadcast packets are sent via GASP.
@@ -1267,7 +1327,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1267 1327
1268 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid)); 1328 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid));
1269 if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR) 1329 if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR)
1270 goto fail_unlock; 1330 goto fail;
1271 1331
1272 generation = peer->generation; 1332 generation = peer->generation;
1273 dest_node = peer->node_id; 1333 dest_node = peer->node_id;
@@ -1321,18 +1381,21 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1321 max_payload += RFC2374_FRAG_HDR_SIZE; 1381 max_payload += RFC2374_FRAG_HDR_SIZE;
1322 } 1382 }
1323 1383
1384 if (++dev->queued_datagrams == FWNET_MAX_QUEUED_DATAGRAMS)
1385 netif_stop_queue(dev->netdev);
1386
1324 spin_unlock_irqrestore(&dev->lock, flags); 1387 spin_unlock_irqrestore(&dev->lock, flags);
1325 1388
1326 ptask->max_payload = max_payload; 1389 ptask->max_payload = max_payload;
1327 INIT_LIST_HEAD(&ptask->pt_link); 1390 ptask->enqueued = 0;
1328 1391
1329 fwnet_send_packet(ptask); 1392 fwnet_send_packet(ptask);
1330 1393
1331 return NETDEV_TX_OK; 1394 return NETDEV_TX_OK;
1332 1395
1333 fail_unlock:
1334 spin_unlock_irqrestore(&dev->lock, flags);
1335 fail: 1396 fail:
1397 spin_unlock_irqrestore(&dev->lock, flags);
1398
1336 if (ptask) 1399 if (ptask)
1337 kmem_cache_free(fwnet_packet_task_cache, ptask); 1400 kmem_cache_free(fwnet_packet_task_cache, ptask);
1338 1401
@@ -1361,15 +1424,8 @@ static int fwnet_change_mtu(struct net_device *net, int new_mtu)
1361 return 0; 1424 return 0;
1362} 1425}
1363 1426
1364static void fwnet_get_drvinfo(struct net_device *net,
1365 struct ethtool_drvinfo *info)
1366{
1367 strcpy(info->driver, KBUILD_MODNAME);
1368 strcpy(info->bus_info, "ieee1394");
1369}
1370
1371static const struct ethtool_ops fwnet_ethtool_ops = { 1427static const struct ethtool_ops fwnet_ethtool_ops = {
1372 .get_drvinfo = fwnet_get_drvinfo, 1428 .get_link = ethtool_op_get_link,
1373}; 1429};
1374 1430
1375static const struct net_device_ops fwnet_netdev_ops = { 1431static const struct net_device_ops fwnet_netdev_ops = {
@@ -1389,8 +1445,8 @@ static void fwnet_init_dev(struct net_device *net)
1389 net->addr_len = FWNET_ALEN; 1445 net->addr_len = FWNET_ALEN;
1390 net->hard_header_len = FWNET_HLEN; 1446 net->hard_header_len = FWNET_HLEN;
1391 net->type = ARPHRD_IEEE1394; 1447 net->type = ARPHRD_IEEE1394;
1392 net->tx_queue_len = 10; 1448 net->tx_queue_len = FWNET_TX_QUEUE_LEN;
1393 SET_ETHTOOL_OPS(net, &fwnet_ethtool_ops); 1449 net->ethtool_ops = &fwnet_ethtool_ops;
1394} 1450}
1395 1451
1396/* caller must hold fwnet_device_mutex */ 1452/* caller must hold fwnet_device_mutex */
@@ -1419,6 +1475,7 @@ static int fwnet_add_peer(struct fwnet_device *dev,
1419 peer->dev = dev; 1475 peer->dev = dev;
1420 peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 1476 peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
1421 peer->fifo = FWNET_NO_FIFO_ADDR; 1477 peer->fifo = FWNET_NO_FIFO_ADDR;
1478 peer->ip = 0;
1422 INIT_LIST_HEAD(&peer->pd_list); 1479 INIT_LIST_HEAD(&peer->pd_list);
1423 peer->pdg_size = 0; 1480 peer->pdg_size = 0;
1424 peer->datagram_label = 0; 1481 peer->datagram_label = 0;
@@ -1431,6 +1488,8 @@ static int fwnet_add_peer(struct fwnet_device *dev,
1431 1488
1432 spin_lock_irq(&dev->lock); 1489 spin_lock_irq(&dev->lock);
1433 list_add_tail(&peer->peer_link, &dev->peer_list); 1490 list_add_tail(&peer->peer_link, &dev->peer_list);
1491 dev->peer_count++;
1492 set_carrier_state(dev);
1434 spin_unlock_irq(&dev->lock); 1493 spin_unlock_irq(&dev->lock);
1435 1494
1436 return 0; 1495 return 0;
@@ -1470,14 +1529,9 @@ static int fwnet_probe(struct device *_dev)
1470 dev->broadcast_rcv_context = NULL; 1529 dev->broadcast_rcv_context = NULL;
1471 dev->broadcast_xmt_max_payload = 0; 1530 dev->broadcast_xmt_max_payload = 0;
1472 dev->broadcast_xmt_datagramlabel = 0; 1531 dev->broadcast_xmt_datagramlabel = 0;
1473
1474 dev->local_fifo = FWNET_NO_FIFO_ADDR; 1532 dev->local_fifo = FWNET_NO_FIFO_ADDR;
1475 1533 dev->queued_datagrams = 0;
1476 INIT_LIST_HEAD(&dev->packet_list);
1477 INIT_LIST_HEAD(&dev->broadcasted_list);
1478 INIT_LIST_HEAD(&dev->sent_list);
1479 INIT_LIST_HEAD(&dev->peer_list); 1534 INIT_LIST_HEAD(&dev->peer_list);
1480
1481 dev->card = card; 1535 dev->card = card;
1482 dev->netdev = net; 1536 dev->netdev = net;
1483 1537
@@ -1516,13 +1570,15 @@ static int fwnet_probe(struct device *_dev)
1516 return ret; 1570 return ret;
1517} 1571}
1518 1572
1519static void fwnet_remove_peer(struct fwnet_peer *peer) 1573static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
1520{ 1574{
1521 struct fwnet_partial_datagram *pd, *pd_next; 1575 struct fwnet_partial_datagram *pd, *pd_next;
1522 1576
1523 spin_lock_irq(&peer->dev->lock); 1577 spin_lock_irq(&dev->lock);
1524 list_del(&peer->peer_link); 1578 list_del(&peer->peer_link);
1525 spin_unlock_irq(&peer->dev->lock); 1579 dev->peer_count--;
1580 set_carrier_state(dev);
1581 spin_unlock_irq(&dev->lock);
1526 1582
1527 list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link) 1583 list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
1528 fwnet_pd_delete(pd); 1584 fwnet_pd_delete(pd);
@@ -1535,14 +1591,17 @@ static int fwnet_remove(struct device *_dev)
1535 struct fwnet_peer *peer = dev_get_drvdata(_dev); 1591 struct fwnet_peer *peer = dev_get_drvdata(_dev);
1536 struct fwnet_device *dev = peer->dev; 1592 struct fwnet_device *dev = peer->dev;
1537 struct net_device *net; 1593 struct net_device *net;
1538 struct fwnet_packet_task *ptask, *pt_next; 1594 int i;
1539 1595
1540 mutex_lock(&fwnet_device_mutex); 1596 mutex_lock(&fwnet_device_mutex);
1541 1597
1542 fwnet_remove_peer(peer); 1598 net = dev->netdev;
1599 if (net && peer->ip)
1600 arp_invalidate(net, peer->ip);
1601
1602 fwnet_remove_peer(peer, dev);
1543 1603
1544 if (list_empty(&dev->peer_list)) { 1604 if (list_empty(&dev->peer_list)) {
1545 net = dev->netdev;
1546 unregister_netdev(net); 1605 unregister_netdev(net);
1547 1606
1548 if (dev->local_fifo != FWNET_NO_FIFO_ADDR) 1607 if (dev->local_fifo != FWNET_NO_FIFO_ADDR)
@@ -1553,21 +1612,9 @@ static int fwnet_remove(struct device *_dev)
1553 dev->card); 1612 dev->card);
1554 fw_iso_context_destroy(dev->broadcast_rcv_context); 1613 fw_iso_context_destroy(dev->broadcast_rcv_context);
1555 } 1614 }
1556 list_for_each_entry_safe(ptask, pt_next, 1615 for (i = 0; dev->queued_datagrams && i < 5; i++)
1557 &dev->packet_list, pt_link) { 1616 ssleep(1);
1558 dev_kfree_skb_any(ptask->skb); 1617 WARN_ON(dev->queued_datagrams);
1559 kmem_cache_free(fwnet_packet_task_cache, ptask);
1560 }
1561 list_for_each_entry_safe(ptask, pt_next,
1562 &dev->broadcasted_list, pt_link) {
1563 dev_kfree_skb_any(ptask->skb);
1564 kmem_cache_free(fwnet_packet_task_cache, ptask);
1565 }
1566 list_for_each_entry_safe(ptask, pt_next,
1567 &dev->sent_list, pt_link) {
1568 dev_kfree_skb_any(ptask->skb);
1569 kmem_cache_free(fwnet_packet_task_cache, ptask);
1570 }
1571 list_del(&dev->dev_link); 1618 list_del(&dev->dev_link);
1572 1619
1573 free_netdev(net); 1620 free_netdev(net);