firewire: net: allow for unordered unit discovery

Decouple the creation and destruction of the net_device from the order
of discovery and removal of nodes with RFC 2734 unit directories since
there is no reliable order. The net_device is now created when the
first RFC 2734 unit on a card is discovered, and destroyed when the last
RFC 2734 unit on a card went away. This includes all remote units as
well as the local unit, which is therefore tracked as a peer now too.

Also, locking around the list of peers is slightly extended to guard
against peer removal. As a side effect, fwnet_peer.pdg_lock has become
superfluous and is deleted.

Peer data (max_rec, speed, node ID, generation) are updated more
carefully.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>

+216 -262
-2
drivers/firewire/core-card.c
··· 429 429 card->local_node = NULL; 430 430 431 431 INIT_DELAYED_WORK(&card->work, fw_card_bm_work); 432 - card->netdev = NULL; 433 - INIT_LIST_HEAD(&card->peer_list); 434 432 } 435 433 EXPORT_SYMBOL(fw_card_initialize); 436 434
+216 -256
drivers/firewire/net.c
··· 18 18 #include <linux/mod_devicetable.h> 19 19 #include <linux/module.h> 20 20 #include <linux/moduleparam.h> 21 + #include <linux/mutex.h> 21 22 #include <linux/netdevice.h> 22 23 #include <linux/skbuff.h> 24 + #include <linux/spinlock.h> 23 25 24 26 #include <asm/unaligned.h> 25 27 #include <net/arp.h> ··· 137 135 u16 datagram_size; 138 136 }; 139 137 140 - /* 141 - * We keep one of these for each IPv4 capable device attached to a fw_card. 142 - * The list of them is stored in the fw_card structure rather than in the 143 - * fwnet_device because the remote IPv4 nodes may be probed before the card is, 144 - * so we need a place to store them before the fwnet_device structure is 145 - * allocated. 146 - */ 147 - struct fwnet_peer { 148 - struct list_head peer_link; 149 - /* guid of the remote peer */ 150 - u64 guid; 151 - /* FIFO address to transmit datagrams to, or FWNET_NO_FIFO_ADDR */ 152 - u64 fifo; 153 - 154 - spinlock_t pdg_lock; /* partial datagram lock */ 155 - /* List of partial datagrams received from this peer */ 156 - struct list_head pd_list; 157 - /* Number of entries in pd_list at the moment */ 158 - unsigned pdg_size; 159 - 160 - /* max payload to transmit to this remote peer */ 161 - /* This already includes the RFC2374_FRAG_HDR_SIZE overhead */ 162 - u16 max_payload; 163 - /* outgoing datagram label */ 164 - u16 datagram_label; 165 - /* Current node_id of the remote peer */ 166 - u16 node_id; 167 - /* current generation of the remote peer */ 168 - u8 generation; 169 - /* max speed that this peer can receive at */ 170 - u8 xmt_speed; 171 - }; 138 + static DEFINE_MUTEX(fwnet_device_mutex); 139 + static LIST_HEAD(fwnet_device_list); 172 140 173 141 struct fwnet_device { 142 + struct list_head dev_link; 174 143 spinlock_t lock; 175 144 enum { 176 145 FWNET_BROADCAST_ERROR, ··· 179 206 /* List of packets that have been sent but not yet acked */ 180 207 struct list_head sent_list; 181 208 209 + struct list_head peer_list; 182 210 struct fw_card *card; 211 + struct net_device *netdev; 212 + }; 213 + 214 + struct fwnet_peer { 215 + struct list_head peer_link; 216 + struct fwnet_device *dev; 217 + u64 guid; 218 + u64 fifo; 219 + 220 + /* guarded by dev->lock */ 221 + struct list_head pd_list; /* received partial datagrams */ 222 + unsigned pdg_size; /* pd_list size */ 223 + 224 + u16 datagram_label; /* outgoing datagram label */ 225 + unsigned max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ 226 + int node_id; 227 + int generation; 228 + unsigned speed; 183 229 }; 184 230 185 231 /* This is our task struct. It's used for the packet complete callback. */ ··· 471 479 return fi->len == pd->datagram_size; 472 480 } 473 481 474 - static int fwnet_peer_new(struct fw_card *card, struct fw_device *device) 475 - { 476 - struct fwnet_peer *peer; 477 - 478 - peer = kmalloc(sizeof(*peer), GFP_KERNEL); 479 - if (!peer) { 480 - fw_error("out of memory\n"); 481 - 482 - return -ENOMEM; 483 - } 484 - peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 485 - peer->fifo = FWNET_NO_FIFO_ADDR; 486 - INIT_LIST_HEAD(&peer->pd_list); 487 - spin_lock_init(&peer->pdg_lock); 488 - peer->pdg_size = 0; 489 - peer->generation = device->generation; 490 - rmb(); 491 - peer->node_id = device->node_id; 492 - /* FIXME what should it really be? */ 493 - peer->max_payload = IEEE1394_MAX_PAYLOAD_S100 - RFC2374_UNFRAG_HDR_SIZE; 494 - peer->datagram_label = 0U; 495 - peer->xmt_speed = device->max_speed; 496 - list_add_tail(&peer->peer_link, &card->peer_list); 497 - 498 - return 0; 499 - } 500 - 501 - /* FIXME caller must take the lock, or peer needs to be reference-counted */ 482 + /* caller must hold dev->lock */ 502 483 static struct fwnet_peer *fwnet_peer_find_by_guid(struct fwnet_device *dev, 503 484 u64 guid) 504 485 { 505 - struct fwnet_peer *p, *peer = NULL; 506 - unsigned long flags; 507 - 508 - spin_lock_irqsave(&dev->lock, flags); 509 - list_for_each_entry(p, &dev->card->peer_list, peer_link) 510 - if (p->guid == guid) { 511 - peer = p; 512 - break; 513 - } 514 - spin_unlock_irqrestore(&dev->lock, flags); 515 - 516 - return peer; 517 - } 518 - 519 - /* FIXME caller must take the lock, or peer needs to be reference-counted */ 520 - /* FIXME node_id doesn't mean anything without generation */ 521 - static struct fwnet_peer *fwnet_peer_find_by_node_id(struct fwnet_device *dev, 522 - u16 node_id) 523 - { 524 - struct fwnet_peer *p, *peer = NULL; 525 - unsigned long flags; 526 - 527 - spin_lock_irqsave(&dev->lock, flags); 528 - list_for_each_entry(p, &dev->card->peer_list, peer_link) 529 - if (p->node_id == node_id) { 530 - peer = p; 531 - break; 532 - } 533 - spin_unlock_irqrestore(&dev->lock, flags); 534 - 535 - return peer; 536 - } 537 - 538 - /* FIXME */ 539 - static void fwnet_peer_delete(struct fw_card *card, struct fw_device *device) 540 - { 541 - struct net_device *net; 542 - struct fwnet_device *dev; 543 486 struct fwnet_peer *peer; 544 - u64 guid; 545 - unsigned long flags; 546 - struct fwnet_partial_datagram *pd, *pd_next; 547 487 548 - guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 549 - net = card->netdev; 550 - if (net) 551 - dev = netdev_priv(net); 552 - else 553 - dev = NULL; 554 - if (dev) 555 - spin_lock_irqsave(&dev->lock, flags); 488 + list_for_each_entry(peer, &dev->peer_list, peer_link) 489 + if (peer->guid == guid) 490 + return peer; 556 491 557 - list_for_each_entry(peer, &card->peer_list, peer_link) { 558 - if (peer->guid == guid) { 559 - list_del(&peer->peer_link); 560 - list_for_each_entry_safe(pd, pd_next, &peer->pd_list, 561 - pd_link) 562 - fwnet_pd_delete(pd); 563 - break; 564 - } 565 - } 566 - if (dev) 567 - spin_unlock_irqrestore(&dev->lock, flags); 492 + return NULL; 568 493 } 494 + 495 + /* caller must hold dev->lock */ 496 + static struct fwnet_peer *fwnet_peer_find_by_node_id(struct fwnet_device *dev, 497 + int node_id, int generation) 498 + { 499 + struct fwnet_peer *peer; 500 + 501 + list_for_each_entry(peer, &dev->peer_list, peer_link) 502 + if (peer->node_id == node_id && 503 + peer->generation == generation) 504 + return peer; 505 + 506 + return NULL; 507 + } 508 + 509 + /* See IEEE 1394-2008 table 6-4, table 8-8, table 16-18. */ 510 + static unsigned fwnet_max_payload(unsigned max_rec, unsigned speed) 511 + { 512 + max_rec = min(max_rec, speed + 8); 513 + max_rec = min(max_rec, 0xbU); /* <= 4096 */ 514 + if (max_rec < 8) { 515 + fw_notify("max_rec %x out of range\n", max_rec); 516 + max_rec = 8; 517 + } 518 + 519 + return (1 << (max_rec + 1)) - RFC2374_FRAG_HDR_SIZE; 520 + } 521 + 569 522 570 523 static int fwnet_finish_incoming_packet(struct net_device *net, 571 524 struct sk_buff *skb, u16 source_node_id, ··· 543 606 unsigned char *arp_ptr; 544 607 u64 fifo_addr; 545 608 u64 peer_guid; 546 - u8 max_rec; 547 - u8 sspd; 609 + unsigned sspd; 548 610 u16 max_payload; 549 611 struct fwnet_peer *peer; 550 - static const u16 fwnet_speed_to_max_payload[] = { 551 - /* S100, S200, S400, S800, S1600, S3200 */ 552 - 512, 1024, 2048, 4096, 4096, 4096 553 - }; 612 + unsigned long flags; 554 613 555 - arp1394 = (struct rfc2734_arp *)skb->data; 556 - arp = (struct arphdr *)skb->data; 557 - arp_ptr = (unsigned char *)(arp + 1); 558 - fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 559 - | ntohl(arp1394->fifo_lo); 560 - max_rec = dev->card->max_receive; 561 - if (arp1394->max_rec < max_rec) 562 - max_rec = arp1394->max_rec; 614 + arp1394 = (struct rfc2734_arp *)skb->data; 615 + arp = (struct arphdr *)skb->data; 616 + arp_ptr = (unsigned char *)(arp + 1); 617 + peer_guid = get_unaligned_be64(&arp1394->s_uniq_id); 618 + fifo_addr = (u64)get_unaligned_be16(&arp1394->fifo_hi) << 32 619 + | get_unaligned_be32(&arp1394->fifo_lo); 620 + 563 621 sspd = arp1394->sspd; 564 622 /* Sanity check. OS X 10.3 PPC reportedly sends 131. */ 565 623 if (sspd > SCODE_3200) { 566 624 fw_notify("sspd %x out of range\n", sspd); 567 - sspd = 0; 625 + sspd = SCODE_3200; 568 626 } 627 + max_payload = fwnet_max_payload(arp1394->max_rec, sspd); 569 628 570 - max_payload = min(fwnet_speed_to_max_payload[sspd], 571 - (u16)(1 << (max_rec + 1))) - RFC2374_UNFRAG_HDR_SIZE; 572 - 573 - peer_guid = get_unaligned_be64(&arp1394->s_uniq_id); 629 + spin_lock_irqsave(&dev->lock, flags); 574 630 peer = fwnet_peer_find_by_guid(dev, peer_guid); 631 + if (peer) { 632 + peer->fifo = fifo_addr; 633 + 634 + if (peer->speed > sspd) 635 + peer->speed = sspd; 636 + if (peer->max_payload > max_payload) 637 + peer->max_payload = max_payload; 638 + } 639 + spin_unlock_irqrestore(&dev->lock, flags); 640 + 575 641 if (!peer) { 576 642 fw_notify("No peer for ARP packet from %016llx\n", 577 643 (unsigned long long)peer_guid); 578 644 goto failed_proto; 579 645 } 580 - 581 - /* FIXME don't use card->generation */ 582 - if (peer->node_id != source_node_id || 583 - peer->generation != dev->card->generation) { 584 - fw_notify("Internal error: peer->node_id (%x) != " 585 - "source_node_id (%x) or peer->generation (%x)" 586 - " != dev->card->generation(%x)\n", 587 - peer->node_id, source_node_id, 588 - peer->generation, dev->card->generation); 589 - peer->node_id = source_node_id; 590 - peer->generation = dev->card->generation; 591 - } 592 - 593 - /* FIXME: for debugging */ 594 - if (sspd > SCODE_400) 595 - sspd = SCODE_400; 596 - /* Update our speed/payload/fifo_offset table */ 597 - /* 598 - * FIXME: this does not handle cases where two high-speed endpoints must use a slower speed because of 599 - * a lower speed hub between them. We need to look at the actual topology map here. 600 - */ 601 - peer->fifo = fifo_addr; 602 - peer->max_payload = max_payload; 603 - /* 604 - * Only allow speeds to go down from their initial value. 605 - * Otherwise a local peer that can only do S400 or slower may 606 - * be told to transmit at S800 to a faster remote peer. 607 - */ 608 - if (peer->xmt_speed > sspd) 609 - peer->xmt_speed = sspd; 610 646 611 647 /* 612 648 * Now that we're done with the 1394 specific stuff, we'll ··· 674 764 } 675 765 676 766 static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, 677 - u16 source_node_id, bool is_broadcast) 767 + int source_node_id, int generation, 768 + bool is_broadcast) 678 769 { 679 770 struct sk_buff *skb; 680 - struct net_device *net; 771 + struct net_device *net = dev->netdev; 681 772 struct rfc2734_header hdr; 682 773 unsigned lf; 683 774 unsigned long flags; ··· 689 778 u16 datagram_label; 690 779 int retval; 691 780 u16 ether_type; 692 - 693 - net = dev->card->netdev; 694 781 695 782 hdr.w0 = be32_to_cpu(buf[0]); 696 783 lf = fwnet_get_hdr_lf(&hdr); ··· 728 819 } 729 820 datagram_label = fwnet_get_hdr_dgl(&hdr); 730 821 dg_size = fwnet_get_hdr_dg_size(&hdr); /* ??? + 1 */ 731 - peer = fwnet_peer_find_by_node_id(dev, source_node_id); 732 822 733 - spin_lock_irqsave(&peer->pdg_lock, flags); 823 + spin_lock_irqsave(&dev->lock, flags); 824 + 825 + peer = fwnet_peer_find_by_node_id(dev, source_node_id, generation); 826 + if (!peer) 827 + goto bad_proto; 734 828 735 829 pd = fwnet_pd_find(peer, datagram_label); 736 830 if (pd == NULL) { ··· 788 876 skb = skb_get(pd->skb); 789 877 fwnet_pd_delete(pd); 790 878 791 - spin_unlock_irqrestore(&peer->pdg_lock, flags); 879 + spin_unlock_irqrestore(&dev->lock, flags); 792 880 793 881 return fwnet_finish_incoming_packet(net, skb, source_node_id, 794 882 false, ether_type); ··· 797 885 * Datagram is not complete, we're done for the 798 886 * moment. 799 887 */ 800 - spin_unlock_irqrestore(&peer->pdg_lock, flags); 888 + spin_unlock_irqrestore(&dev->lock, flags); 801 889 802 890 return 0; 803 891 804 892 bad_proto: 805 - spin_unlock_irqrestore(&peer->pdg_lock, flags); 893 + spin_unlock_irqrestore(&dev->lock, flags); 806 894 807 895 if (netif_queue_stopped(net)) 808 896 netif_wake_queue(net); ··· 828 916 return; 829 917 } 830 918 831 - status = fwnet_incoming_packet(dev, payload, length, source, false); 919 + status = fwnet_incoming_packet(dev, payload, length, 920 + source, generation, false); 832 921 if (status != 0) { 833 922 fw_error("Incoming packet failure\n"); 834 923 fw_send_response(card, r, RCODE_CONFLICT_ERROR); ··· 879 966 buf_ptr += 2; 880 967 length -= IEEE1394_GASP_HDR_SIZE; 881 968 fwnet_incoming_packet(dev, buf_ptr, length, 882 - source_node_id, true); 969 + source_node_id, -1, true); 883 970 } 884 971 885 972 packet.payload_length = dev->rcv_buffer_size; ··· 986 1073 unsigned tx_len; 987 1074 struct rfc2734_header *bufhdr; 988 1075 unsigned long flags; 989 - struct net_device *net; 990 1076 991 1077 dev = ptask->dev; 992 1078 tx_len = ptask->max_payload; ··· 1049 1137 list_add_tail(&ptask->pt_link, &dev->sent_list); 1050 1138 spin_unlock_irqrestore(&dev->lock, flags); 1051 1139 1052 - net = dev->card->netdev; 1053 - net->trans_start = jiffies; 1140 + dev->netdev->trans_start = jiffies; 1054 1141 1055 1142 return 0; 1056 1143 } ··· 1205 1294 u16 dg_size; 1206 1295 u16 *datagram_label_ptr; 1207 1296 struct fwnet_packet_task *ptask; 1208 - struct fwnet_peer *peer = NULL; 1297 + struct fwnet_peer *peer; 1298 + unsigned long flags; 1209 1299 1210 1300 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC); 1211 1301 if (ptask == NULL) ··· 1226 1314 proto = hdr_buf.h_proto; 1227 1315 dg_size = skb->len; 1228 1316 1317 + /* serialize access to peer, including peer->datagram_label */ 1318 + spin_lock_irqsave(&dev->lock, flags); 1319 + 1229 1320 /* 1230 1321 * Set the transmission type for the packet. ARP packets and IP 1231 1322 * broadcast packets are sent via GASP. ··· 1237 1322 || proto == htons(ETH_P_ARP) 1238 1323 || (proto == htons(ETH_P_IP) 1239 1324 && IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)))) { 1240 - max_payload = dev->broadcast_xmt_max_payload; 1325 + max_payload = dev->broadcast_xmt_max_payload; 1241 1326 datagram_label_ptr = &dev->broadcast_xmt_datagramlabel; 1242 1327 1243 - ptask->fifo_addr = FWNET_NO_FIFO_ADDR; 1244 - ptask->generation = 0; 1245 - ptask->dest_node = IEEE1394_ALL_NODES; 1246 - ptask->speed = SCODE_100; 1328 + ptask->fifo_addr = FWNET_NO_FIFO_ADDR; 1329 + ptask->generation = 0; 1330 + ptask->dest_node = IEEE1394_ALL_NODES; 1331 + ptask->speed = SCODE_100; 1247 1332 } else { 1248 1333 __be64 guid = get_unaligned((__be64 *)hdr_buf.h_dest); 1249 1334 u8 generation; 1250 1335 1251 1336 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid)); 1252 - if (!peer) 1253 - goto fail; 1337 + if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR) 1338 + goto fail_unlock; 1254 1339 1255 - if (peer->fifo == FWNET_NO_FIFO_ADDR) 1256 - goto fail; 1257 - 1258 - generation = peer->generation; 1259 - smp_rmb(); 1260 - dest_node = peer->node_id; 1261 - 1262 - max_payload = peer->max_payload; 1340 + generation = peer->generation; 1341 + dest_node = peer->node_id; 1342 + max_payload = peer->max_payload; 1263 1343 datagram_label_ptr = &peer->datagram_label; 1264 1344 1265 - ptask->fifo_addr = peer->fifo; 1266 - ptask->generation = generation; 1267 - ptask->dest_node = dest_node; 1268 - ptask->speed = peer->xmt_speed; 1345 + ptask->fifo_addr = peer->fifo; 1346 + ptask->generation = generation; 1347 + ptask->dest_node = dest_node; 1348 + ptask->speed = peer->speed; 1269 1349 } 1270 1350 1271 1351 /* If this is an ARP packet, convert it */ ··· 1303 1393 ptask->outstanding_pkts = DIV_ROUND_UP(dg_size, max_payload); 1304 1394 max_payload += RFC2374_FRAG_HDR_SIZE; 1305 1395 } 1396 + 1397 + spin_unlock_irqrestore(&dev->lock, flags); 1398 + 1306 1399 ptask->max_payload = max_payload; 1307 1400 fwnet_send_packet(ptask); 1308 1401 1309 1402 return NETDEV_TX_OK; 1310 1403 1404 + fail_unlock: 1405 + spin_unlock_irqrestore(&dev->lock, flags); 1311 1406 fail: 1312 1407 if (ptask) 1313 1408 kmem_cache_free(fwnet_packet_task_cache, ptask); ··· 1382 1467 SET_ETHTOOL_OPS(net, &fwnet_ethtool_ops); 1383 1468 } 1384 1469 1385 - /* FIXME create netdev upon first fw_unit of a card, not upon local fw_unit */ 1470 + /* caller must hold fwnet_device_mutex */ 1471 + static struct fwnet_device *fwnet_dev_find(struct fw_card *card) 1472 + { 1473 + struct fwnet_device *dev; 1474 + 1475 + list_for_each_entry(dev, &fwnet_device_list, dev_link) 1476 + if (dev->card == card) 1477 + return dev; 1478 + 1479 + return NULL; 1480 + } 1481 + 1482 + static int fwnet_add_peer(struct fwnet_device *dev, 1483 + struct fw_unit *unit, struct fw_device *device) 1484 + { 1485 + struct fwnet_peer *peer; 1486 + 1487 + peer = kmalloc(sizeof(*peer), GFP_KERNEL); 1488 + if (!peer) 1489 + return -ENOMEM; 1490 + 1491 + unit->device.driver_data = peer; 1492 + peer->dev = dev; 1493 + peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 1494 + peer->fifo = FWNET_NO_FIFO_ADDR; 1495 + INIT_LIST_HEAD(&peer->pd_list); 1496 + peer->pdg_size = 0; 1497 + peer->datagram_label = 0; 1498 + peer->speed = device->max_speed; 1499 + peer->max_payload = fwnet_max_payload(device->max_rec, peer->speed); 1500 + 1501 + peer->generation = device->generation; 1502 + smp_rmb(); 1503 + peer->node_id = device->node_id; 1504 + 1505 + spin_lock_irq(&dev->lock); 1506 + list_add_tail(&peer->peer_link, &dev->peer_list); 1507 + spin_unlock_irq(&dev->lock); 1508 + 1509 + return 0; 1510 + } 1511 + 1386 1512 static int fwnet_probe(struct device *_dev) 1387 1513 { 1388 1514 struct fw_unit *unit = fw_unit(_dev); ··· 1432 1476 struct net_device *net; 1433 1477 struct fwnet_device *dev; 1434 1478 unsigned max_mtu; 1479 + bool new_netdev; 1480 + int ret; 1435 1481 1436 - if (!device->is_local) { 1437 - int added; 1482 + mutex_lock(&fwnet_device_mutex); 1438 1483 1439 - added = fwnet_peer_new(card, device); 1440 - return added; 1484 + dev = fwnet_dev_find(card); 1485 + if (dev) { 1486 + new_netdev = false; 1487 + net = dev->netdev; 1488 + goto have_dev; 1441 1489 } 1490 + 1491 + new_netdev = true; 1442 1492 net = alloc_netdev(sizeof(*dev), "firewire%d", fwnet_init_dev); 1443 1493 if (net == NULL) { 1444 - fw_error("out of memory\n"); 1494 + ret = -ENOMEM; 1445 1495 goto out; 1446 1496 } 1447 1497 ··· 1462 1500 1463 1501 dev->local_fifo = FWNET_NO_FIFO_ADDR; 1464 1502 1465 - /* INIT_WORK(&dev->wake, fwnet_handle_queue);*/ 1466 1503 INIT_LIST_HEAD(&dev->packet_list); 1467 1504 INIT_LIST_HEAD(&dev->broadcasted_list); 1468 1505 INIT_LIST_HEAD(&dev->sent_list); 1506 + INIT_LIST_HEAD(&dev->peer_list); 1469 1507 1470 1508 dev->card = card; 1509 + dev->netdev = net; 1471 1510 1472 1511 /* 1473 1512 * Use the RFC 2734 default 1500 octets or the maximum payload ··· 1481 1518 /* Set our hardware address while we're at it */ 1482 1519 put_unaligned_be64(card->guid, net->dev_addr); 1483 1520 put_unaligned_be64(~0ULL, net->broadcast); 1484 - if (register_netdev(net)) { 1521 + ret = register_netdev(net); 1522 + if (ret) { 1485 1523 fw_error("Cannot register the driver\n"); 1486 1524 goto out; 1487 1525 } 1488 1526 1527 + list_add_tail(&dev->dev_link, &fwnet_device_list); 1489 1528 fw_notify("%s: IPv4 over FireWire on device %016llx\n", 1490 1529 net->name, (unsigned long long)card->guid); 1491 - card->netdev = net; 1492 - 1493 - return 0; 1530 + have_dev: 1531 + ret = fwnet_add_peer(dev, unit, device); 1532 + if (ret && new_netdev) { 1533 + unregister_netdev(net); 1534 + list_del(&dev->dev_link); 1535 + } 1494 1536 out: 1495 - if (net) 1537 + if (ret && new_netdev) 1496 1538 free_netdev(net); 1497 1539 1498 - return -ENOENT; 1540 + mutex_unlock(&fwnet_device_mutex); 1541 + 1542 + return ret; 1543 + } 1544 + 1545 + static void fwnet_remove_peer(struct fwnet_peer *peer) 1546 + { 1547 + struct fwnet_partial_datagram *pd, *pd_next; 1548 + 1549 + spin_lock_irq(&peer->dev->lock); 1550 + list_del(&peer->peer_link); 1551 + spin_unlock_irq(&peer->dev->lock); 1552 + 1553 + list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link) 1554 + fwnet_pd_delete(pd); 1555 + 1556 + kfree(peer); 1499 1557 } 1500 1558 1501 1559 static int fwnet_remove(struct device *_dev) 1502 1560 { 1503 - struct fw_unit *unit = fw_unit(_dev); 1504 - struct fw_device *device = fw_parent_device(unit); 1505 - struct fw_card *card = device->card; 1561 + struct fwnet_peer *peer = _dev->driver_data; 1562 + struct fwnet_device *dev = peer->dev; 1506 1563 struct net_device *net; 1507 - struct fwnet_device *dev; 1508 - struct fwnet_peer *peer; 1509 - struct fwnet_partial_datagram *pd, *pd_next; 1510 1564 struct fwnet_packet_task *ptask, *pt_next; 1511 1565 1512 - if (!device->is_local) { 1513 - fwnet_peer_delete(card, device); 1566 + mutex_lock(&fwnet_device_mutex); 1514 1567 1515 - return 0; 1516 - } 1568 + fwnet_remove_peer(peer); 1517 1569 1518 - net = card->netdev; 1519 - if (net) { 1520 - dev = netdev_priv(net); 1570 + if (list_empty(&dev->peer_list)) { 1571 + net = dev->netdev; 1521 1572 unregister_netdev(net); 1522 1573 1523 1574 if (dev->local_fifo != FWNET_NO_FIFO_ADDR) ··· 1557 1580 dev_kfree_skb_any(ptask->skb); 1558 1581 kmem_cache_free(fwnet_packet_task_cache, ptask); 1559 1582 } 1560 - list_for_each_entry(peer, &card->peer_list, peer_link) { 1561 - if (peer->pdg_size) { 1562 - list_for_each_entry_safe(pd, pd_next, 1563 - &peer->pd_list, pd_link) 1564 - fwnet_pd_delete(pd); 1565 - peer->pdg_size = 0; 1566 - } 1567 - peer->fifo = FWNET_NO_FIFO_ADDR; 1568 - } 1569 1583 free_netdev(net); 1570 - card->netdev = NULL; 1571 1584 } 1585 + 1586 + mutex_unlock(&fwnet_device_mutex); 1572 1587 1573 1588 return 0; 1574 1589 } ··· 1572 1603 static void fwnet_update(struct fw_unit *unit) 1573 1604 { 1574 1605 struct fw_device *device = fw_parent_device(unit); 1575 - struct net_device *net = device->card->netdev; 1576 - struct fwnet_device *dev; 1577 - struct fwnet_peer *peer; 1578 - u64 guid; 1606 + struct fwnet_peer *peer = unit->device.driver_data; 1607 + int generation; 1579 1608 1580 - if (net && !device->is_local) { 1581 - dev = netdev_priv(net); 1582 - guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 1583 - peer = fwnet_peer_find_by_guid(dev, guid); 1584 - if (!peer) { 1585 - fw_error("fwnet_update: no peer for device %016llx\n", 1586 - (unsigned long long)guid); 1587 - return; 1588 - } 1589 - peer->generation = device->generation; 1590 - rmb(); 1591 - peer->node_id = device->node_id; 1592 - } 1609 + generation = device->generation; 1610 + 1611 + spin_lock_irq(&peer->dev->lock); 1612 + peer->node_id = device->node_id; 1613 + peer->generation = generation; 1614 + spin_unlock_irq(&peer->dev->lock); 1593 1615 } 1594 1616 1595 1617 static const struct ieee1394_device_id fwnet_id_table[] = {
-4
include/linux/firewire.h
··· 131 131 bool broadcast_channel_allocated; 132 132 u32 broadcast_channel; 133 133 u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; 134 - 135 - /* firewire-net driver data */ 136 - void *netdev; 137 - struct list_head peer_list; 138 134 }; 139 135 140 136 static inline struct fw_card *fw_card_get(struct fw_card *card)