forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth1394.c
1752 lines (1459 loc) · 47.2 KB
/
eth1394.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* eth1394.c -- IPv4 driver for Linux IEEE-1394 Subsystem
*
* Copyright (C) 2001-2003 Ben Collins <[email protected]>
* 2000 Bonin Franck <[email protected]>
* 2003 Steve Kinneberg <[email protected]>
*
* Mainly based on work by Emanuel Pirker and Andreas E. Bombe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* This driver intends to support RFC 2734, which describes a method for
* transporting IPv4 datagrams over IEEE-1394 serial busses.
*
* TODO:
* RFC 2734 related:
* - Add MCAP. Limited Multicast exists only to 224.0.0.1 and 224.0.0.2.
*
* Non-RFC 2734 related:
* - Handle fragmented skb's coming from the networking layer.
* - Move generic GASP reception to core 1394 code
* - Convert kmalloc/kfree for link fragments to use kmem_cache_* instead
* - Stability improvements
* - Performance enhancements
* - Consider garbage collecting old partial datagrams after X amount of time
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/tcp.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>
#include <linux/ethtool.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <asm/unaligned.h>
#include <net/arp.h>
#include "config_roms.h"
#include "csr1212.h"
#include "eth1394.h"
#include "highlevel.h"
#include "ieee1394.h"
#include "ieee1394_core.h"
#include "ieee1394_hotplug.h"
#include "ieee1394_transactions.h"
#include "ieee1394_types.h"
#include "iso.h"
#include "nodemgr.h"
#define ETH1394_PRINT_G(level, fmt, args...) \
printk(level "%s: " fmt, driver_name, ## args)
#define ETH1394_PRINT(level, dev_name, fmt, args...) \
printk(level "%s: %s: " fmt, driver_name, dev_name, ## args)
struct fragment_info {
struct list_head list;
int offset;
int len;
};
struct partial_datagram {
struct list_head list;
u16 dgl;
u16 dg_size;
u16 ether_type;
struct sk_buff *skb;
char *pbuf;
struct list_head frag_info;
};
struct pdg_list {
struct list_head list; /* partial datagram list per node */
unsigned int sz; /* partial datagram list size per node */
spinlock_t lock; /* partial datagram lock */
};
struct eth1394_host_info {
struct hpsb_host *host;
struct net_device *dev;
};
struct eth1394_node_ref {
struct unit_directory *ud;
struct list_head list;
};
struct eth1394_node_info {
u16 maxpayload; /* max payload */
u8 sspd; /* max speed */
u64 fifo; /* FIFO address */
struct pdg_list pdg; /* partial RX datagram lists */
int dgl; /* outgoing datagram label */
};
static const char driver_name[] = "eth1394";
static struct kmem_cache *packet_task_cache;
static struct hpsb_highlevel eth1394_highlevel;
/* Use common.lf to determine header len */
static const int hdr_type_len[] = {
sizeof(struct eth1394_uf_hdr),
sizeof(struct eth1394_ff_hdr),
sizeof(struct eth1394_sf_hdr),
sizeof(struct eth1394_sf_hdr)
};
static const u16 eth1394_speedto_maxpayload[] = {
/* S100, S200, S400, S800, S1600, S3200 */
512, 1024, 2048, 4096, 4096, 4096
};
MODULE_AUTHOR("Ben Collins ([email protected])");
MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)");
MODULE_LICENSE("GPL");
/*
* The max_partial_datagrams parameter is the maximum number of fragmented
* datagrams per node that eth1394 will keep in memory. Providing an upper
* bound allows us to limit the amount of memory that partial datagrams
* consume in the event that some partial datagrams are never completed.
*/
static int max_partial_datagrams = 25;
module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(max_partial_datagrams,
"Maximum number of partially received fragmented datagrams "
"(default = 25).");
static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, const void *daddr,
const void *saddr, unsigned len);
static int ether1394_rebuild_header(struct sk_buff *skb);
static int ether1394_header_parse(const struct sk_buff *skb,
unsigned char *haddr);
static int ether1394_header_cache(const struct neighbour *neigh,
struct hh_cache *hh);
static void ether1394_header_cache_update(struct hh_cache *hh,
const struct net_device *dev,
const unsigned char *haddr);
static int ether1394_tx(struct sk_buff *skb, struct net_device *dev);
static void ether1394_iso(struct hpsb_iso *iso);
static struct ethtool_ops ethtool_ops;
static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
quadlet_t *data, u64 addr, size_t len, u16 flags);
static void ether1394_add_host(struct hpsb_host *host);
static void ether1394_remove_host(struct hpsb_host *host);
static void ether1394_host_reset(struct hpsb_host *host);
/* Function for incoming 1394 packets */
static struct hpsb_address_ops addr_ops = {
.write = ether1394_write,
};
/* Ieee1394 highlevel driver functions */
static struct hpsb_highlevel eth1394_highlevel = {
.name = driver_name,
.add_host = ether1394_add_host,
.remove_host = ether1394_remove_host,
.host_reset = ether1394_host_reset,
};
static int ether1394_recv_init(struct eth1394_priv *priv)
{
unsigned int iso_buf_size;
/* FIXME: rawiso limits us to PAGE_SIZE */
iso_buf_size = min((unsigned int)PAGE_SIZE,
2 * (1U << (priv->host->csr.max_rec + 1)));
priv->iso = hpsb_iso_recv_init(priv->host,
ETHER1394_GASP_BUFFERS * iso_buf_size,
ETHER1394_GASP_BUFFERS,
priv->broadcast_channel,
HPSB_ISO_DMA_PACKET_PER_BUFFER,
1, ether1394_iso);
if (priv->iso == NULL) {
ETH1394_PRINT_G(KERN_ERR, "Failed to allocate IR context\n");
priv->bc_state = ETHER1394_BC_ERROR;
return -EAGAIN;
}
if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0)
priv->bc_state = ETHER1394_BC_STOPPED;
else
priv->bc_state = ETHER1394_BC_RUNNING;
return 0;
}
/* This is called after an "ifup" */
static int ether1394_open(struct net_device *dev)
{
struct eth1394_priv *priv = netdev_priv(dev);
int ret;
if (priv->bc_state == ETHER1394_BC_ERROR) {
ret = ether1394_recv_init(priv);
if (ret)
return ret;
}
netif_start_queue(dev);
return 0;
}
/* This is called after an "ifdown" */
static int ether1394_stop(struct net_device *dev)
{
/* flush priv->wake */
flush_scheduled_work();
netif_stop_queue(dev);
return 0;
}
/* Return statistics to the caller */
static struct net_device_stats *ether1394_stats(struct net_device *dev)
{
return &(((struct eth1394_priv *)netdev_priv(dev))->stats);
}
/* FIXME: What to do if we timeout? I think a host reset is probably in order,
* so that's what we do. Should we increment the stat counters too? */
static void ether1394_tx_timeout(struct net_device *dev)
{
struct hpsb_host *host =
((struct eth1394_priv *)netdev_priv(dev))->host;
ETH1394_PRINT(KERN_ERR, dev->name, "Timeout, resetting host\n");
ether1394_host_reset(host);
}
static inline int ether1394_max_mtu(struct hpsb_host* host)
{
return (1 << (host->csr.max_rec + 1))
- sizeof(union eth1394_hdr) - ETHER1394_GASP_OVERHEAD;
}
static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
{
int max_mtu;
if (new_mtu < 68)
return -EINVAL;
max_mtu = ether1394_max_mtu(
((struct eth1394_priv *)netdev_priv(dev))->host);
if (new_mtu > max_mtu) {
ETH1394_PRINT(KERN_INFO, dev->name,
"Local node constrains MTU to %d\n", max_mtu);
return -ERANGE;
}
dev->mtu = new_mtu;
return 0;
}
static void purge_partial_datagram(struct list_head *old)
{
struct partial_datagram *pd;
struct list_head *lh, *n;
struct fragment_info *fi;
pd = list_entry(old, struct partial_datagram, list);
list_for_each_safe(lh, n, &pd->frag_info) {
fi = list_entry(lh, struct fragment_info, list);
list_del(lh);
kfree(fi);
}
list_del(old);
kfree_skb(pd->skb);
kfree(pd);
}
/******************************************
* 1394 bus activity functions
******************************************/
static struct eth1394_node_ref *eth1394_find_node(struct list_head *inl,
struct unit_directory *ud)
{
struct eth1394_node_ref *node;
list_for_each_entry(node, inl, list)
if (node->ud == ud)
return node;
return NULL;
}
static struct eth1394_node_ref *eth1394_find_node_guid(struct list_head *inl,
u64 guid)
{
struct eth1394_node_ref *node;
list_for_each_entry(node, inl, list)
if (node->ud->ne->guid == guid)
return node;
return NULL;
}
static struct eth1394_node_ref *eth1394_find_node_nodeid(struct list_head *inl,
nodeid_t nodeid)
{
struct eth1394_node_ref *node;
list_for_each_entry(node, inl, list)
if (node->ud->ne->nodeid == nodeid)
return node;
return NULL;
}
static int eth1394_new_node(struct eth1394_host_info *hi,
struct unit_directory *ud)
{
struct eth1394_priv *priv;
struct eth1394_node_ref *new_node;
struct eth1394_node_info *node_info;
new_node = kmalloc(sizeof(*new_node), GFP_KERNEL);
if (!new_node)
return -ENOMEM;
node_info = kmalloc(sizeof(*node_info), GFP_KERNEL);
if (!node_info) {
kfree(new_node);
return -ENOMEM;
}
spin_lock_init(&node_info->pdg.lock);
INIT_LIST_HEAD(&node_info->pdg.list);
node_info->pdg.sz = 0;
node_info->fifo = CSR1212_INVALID_ADDR_SPACE;
ud->device.driver_data = node_info;
new_node->ud = ud;
priv = netdev_priv(hi->dev);
list_add_tail(&new_node->list, &priv->ip_node_list);
return 0;
}
static int eth1394_probe(struct device *dev)
{
struct unit_directory *ud;
struct eth1394_host_info *hi;
ud = container_of(dev, struct unit_directory, device);
hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
if (!hi)
return -ENOENT;
return eth1394_new_node(hi, ud);
}
static int eth1394_remove(struct device *dev)
{
struct unit_directory *ud;
struct eth1394_host_info *hi;
struct eth1394_priv *priv;
struct eth1394_node_ref *old_node;
struct eth1394_node_info *node_info;
struct list_head *lh, *n;
unsigned long flags;
ud = container_of(dev, struct unit_directory, device);
hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
if (!hi)
return -ENOENT;
priv = netdev_priv(hi->dev);
old_node = eth1394_find_node(&priv->ip_node_list, ud);
if (!old_node)
return 0;
list_del(&old_node->list);
kfree(old_node);
node_info = (struct eth1394_node_info*)ud->device.driver_data;
spin_lock_irqsave(&node_info->pdg.lock, flags);
/* The partial datagram list should be empty, but we'll just
* make sure anyway... */
list_for_each_safe(lh, n, &node_info->pdg.list)
purge_partial_datagram(lh);
spin_unlock_irqrestore(&node_info->pdg.lock, flags);
kfree(node_info);
ud->device.driver_data = NULL;
return 0;
}
static int eth1394_update(struct unit_directory *ud)
{
struct eth1394_host_info *hi;
struct eth1394_priv *priv;
struct eth1394_node_ref *node;
hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host);
if (!hi)
return -ENOENT;
priv = netdev_priv(hi->dev);
node = eth1394_find_node(&priv->ip_node_list, ud);
if (node)
return 0;
return eth1394_new_node(hi, ud);
}
static struct ieee1394_device_id eth1394_id_table[] = {
{
.match_flags = (IEEE1394_MATCH_SPECIFIER_ID |
IEEE1394_MATCH_VERSION),
.specifier_id = ETHER1394_GASP_SPECIFIER_ID,
.version = ETHER1394_GASP_VERSION,
},
{}
};
MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
static struct hpsb_protocol_driver eth1394_proto_driver = {
.name = driver_name,
.id_table = eth1394_id_table,
.update = eth1394_update,
.driver = {
.probe = eth1394_probe,
.remove = eth1394_remove,
},
};
static void ether1394_reset_priv(struct net_device *dev, int set_mtu)
{
unsigned long flags;
int i;
struct eth1394_priv *priv = netdev_priv(dev);
struct hpsb_host *host = priv->host;
u64 guid = get_unaligned((u64 *)&(host->csr.rom->bus_info_data[3]));
int max_speed = IEEE1394_SPEED_MAX;
spin_lock_irqsave(&priv->lock, flags);
memset(priv->ud_list, 0, sizeof(priv->ud_list));
priv->bc_maxpayload = 512;
/* Determine speed limit */
/* FIXME: This is broken for nodes with link speed < PHY speed,
* and it is suboptimal for S200B...S800B hardware.
* The result of nodemgr's speed probe should be used somehow. */
for (i = 0; i < host->node_count; i++) {
/* take care of S100B...S400B PHY ports */
if (host->speed[i] == SELFID_SPEED_UNKNOWN) {
max_speed = IEEE1394_SPEED_100;
break;
}
if (max_speed > host->speed[i])
max_speed = host->speed[i];
}
priv->bc_sspd = max_speed;
if (set_mtu) {
/* Use the RFC 2734 default 1500 octets or the maximum payload
* as initial MTU */
dev->mtu = min(1500, ether1394_max_mtu(host));
/* Set our hardware address while we're at it */
memcpy(dev->dev_addr, &guid, sizeof(u64));
memset(dev->broadcast, 0xff, sizeof(u64));
}
spin_unlock_irqrestore(&priv->lock, flags);
}
static const struct header_ops ether1394_header_ops = {
.create = ether1394_header,
.rebuild = ether1394_rebuild_header,
.cache = ether1394_header_cache,
.cache_update = ether1394_header_cache_update,
.parse = ether1394_header_parse,
};
static void ether1394_init_dev(struct net_device *dev)
{
dev->open = ether1394_open;
dev->stop = ether1394_stop;
dev->hard_start_xmit = ether1394_tx;
dev->get_stats = ether1394_stats;
dev->tx_timeout = ether1394_tx_timeout;
dev->change_mtu = ether1394_change_mtu;
dev->header_ops = ðer1394_header_ops;
SET_ETHTOOL_OPS(dev, ðtool_ops);
dev->watchdog_timeo = ETHER1394_TIMEOUT;
dev->flags = IFF_BROADCAST | IFF_MULTICAST;
dev->features = NETIF_F_HIGHDMA;
dev->addr_len = ETH1394_ALEN;
dev->hard_header_len = ETH1394_HLEN;
dev->type = ARPHRD_IEEE1394;
/* FIXME: This value was copied from ether_setup(). Is it too much? */
dev->tx_queue_len = 1000;
}
/*
* Wake the queue up after commonly encountered transmit failure conditions are
* hopefully over. Currently only tlabel exhaustion is accounted for.
*/
static void ether1394_wake_queue(struct work_struct *work)
{
struct eth1394_priv *priv;
struct hpsb_packet *packet;
priv = container_of(work, struct eth1394_priv, wake);
packet = hpsb_alloc_packet(0);
/* This is really bad, but unjam the queue anyway. */
if (!packet)
goto out;
packet->host = priv->host;
packet->node_id = priv->wake_node;
/*
* A transaction label is all we really want. If we get one, it almost
* always means we can get a lot more because the ieee1394 core recycled
* a whole batch of tlabels, at last.
*/
if (hpsb_get_tlabel(packet) == 0)
hpsb_free_tlabel(packet);
hpsb_free_packet(packet);
out:
netif_wake_queue(priv->wake_dev);
}
/*
* This function is called every time a card is found. It is generally called
* when the module is installed. This is where we add all of our ethernet
* devices. One for each host.
*/
static void ether1394_add_host(struct hpsb_host *host)
{
struct eth1394_host_info *hi = NULL;
struct net_device *dev = NULL;
struct eth1394_priv *priv;
u64 fifo_addr;
if (hpsb_config_rom_ip1394_add(host) != 0) {
ETH1394_PRINT_G(KERN_ERR, "Can't add IP-over-1394 ROM entry\n");
return;
}
fifo_addr = hpsb_allocate_and_register_addrspace(
ð1394_highlevel, host, &addr_ops,
ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN,
CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE);
if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
ETH1394_PRINT_G(KERN_ERR, "Cannot register CSR space\n");
hpsb_config_rom_ip1394_remove(host);
return;
}
dev = alloc_netdev(sizeof(*priv), "eth%d", ether1394_init_dev);
if (dev == NULL) {
ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
goto out;
}
SET_NETDEV_DEV(dev, &host->device);
priv = netdev_priv(dev);
INIT_LIST_HEAD(&priv->ip_node_list);
spin_lock_init(&priv->lock);
priv->host = host;
priv->local_fifo = fifo_addr;
INIT_WORK(&priv->wake, ether1394_wake_queue);
priv->wake_dev = dev;
hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi));
if (hi == NULL) {
ETH1394_PRINT_G(KERN_ERR, "Out of memory\n");
goto out;
}
ether1394_reset_priv(dev, 1);
if (register_netdev(dev)) {
ETH1394_PRINT_G(KERN_ERR, "Cannot register the driver\n");
goto out;
}
ETH1394_PRINT(KERN_INFO, dev->name, "IPv4 over IEEE 1394 (fw-host%d)\n",
host->id);
hi->host = host;
hi->dev = dev;
/* Ignore validity in hopes that it will be set in the future. It'll
* be checked when the eth device is opened. */
priv->broadcast_channel = host->csr.broadcast_channel & 0x3f;
ether1394_recv_init(priv);
return;
out:
if (dev)
free_netdev(dev);
if (hi)
hpsb_destroy_hostinfo(ð1394_highlevel, host);
hpsb_unregister_addrspace(ð1394_highlevel, host, fifo_addr);
hpsb_config_rom_ip1394_remove(host);
}
/* Remove a card from our list */
static void ether1394_remove_host(struct hpsb_host *host)
{
struct eth1394_host_info *hi;
struct eth1394_priv *priv;
hi = hpsb_get_hostinfo(ð1394_highlevel, host);
if (!hi)
return;
priv = netdev_priv(hi->dev);
hpsb_unregister_addrspace(ð1394_highlevel, host, priv->local_fifo);
hpsb_config_rom_ip1394_remove(host);
if (priv->iso)
hpsb_iso_shutdown(priv->iso);
unregister_netdev(hi->dev);
free_netdev(hi->dev);
}
/* A bus reset happened */
static void ether1394_host_reset(struct hpsb_host *host)
{
struct eth1394_host_info *hi;
struct eth1394_priv *priv;
struct net_device *dev;
struct list_head *lh, *n;
struct eth1394_node_ref *node;
struct eth1394_node_info *node_info;
unsigned long flags;
hi = hpsb_get_hostinfo(ð1394_highlevel, host);
/* This can happen for hosts that we don't use */
if (!hi)
return;
dev = hi->dev;
priv = netdev_priv(dev);
/* Reset our private host data, but not our MTU */
netif_stop_queue(dev);
ether1394_reset_priv(dev, 0);
list_for_each_entry(node, &priv->ip_node_list, list) {
node_info = node->ud->device.driver_data;
spin_lock_irqsave(&node_info->pdg.lock, flags);
list_for_each_safe(lh, n, &node_info->pdg.list)
purge_partial_datagram(lh);
INIT_LIST_HEAD(&(node_info->pdg.list));
node_info->pdg.sz = 0;
spin_unlock_irqrestore(&node_info->pdg.lock, flags);
}
netif_wake_queue(dev);
}
/******************************************
* HW Header net device functions
******************************************/
/* These functions have been adapted from net/ethernet/eth.c */
/* Create a fake MAC header for an arbitrary protocol layer.
* saddr=NULL means use device source address
* daddr=NULL means leave destination address (eg unresolved arp). */
static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, const void *daddr,
const void *saddr, unsigned len)
{
struct eth1394hdr *eth =
(struct eth1394hdr *)skb_push(skb, ETH1394_HLEN);
eth->h_proto = htons(type);
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
memset(eth->h_dest, 0, dev->addr_len);
return dev->hard_header_len;
}
if (daddr) {
memcpy(eth->h_dest, daddr, dev->addr_len);
return dev->hard_header_len;
}
return -dev->hard_header_len;
}
/* Rebuild the faked MAC header. This is called after an ARP
* (or in future other address resolution) has completed on this
* sk_buff. We now let ARP fill in the other fields.
*
* This routine CANNOT use cached dst->neigh!
* Really, it is used only when dst->neigh is wrong.
*/
static int ether1394_rebuild_header(struct sk_buff *skb)
{
struct eth1394hdr *eth = (struct eth1394hdr *)skb->data;
if (eth->h_proto == htons(ETH_P_IP))
return arp_find((unsigned char *)ð->h_dest, skb);
ETH1394_PRINT(KERN_DEBUG, skb->dev->name,
"unable to resolve type %04x addresses\n",
ntohs(eth->h_proto));
return 0;
}
static int ether1394_header_parse(const struct sk_buff *skb,
unsigned char *haddr)
{
memcpy(haddr, skb->dev->dev_addr, ETH1394_ALEN);
return ETH1394_ALEN;
}
static int ether1394_header_cache(const struct neighbour *neigh,
struct hh_cache *hh)
{
unsigned short type = hh->hh_type;
struct net_device *dev = neigh->dev;
struct eth1394hdr *eth =
(struct eth1394hdr *)((u8 *)hh->hh_data + 16 - ETH1394_HLEN);
if (type == htons(ETH_P_802_3))
return -1;
eth->h_proto = type;
memcpy(eth->h_dest, neigh->ha, dev->addr_len);
hh->hh_len = ETH1394_HLEN;
return 0;
}
/* Called by Address Resolution module to notify changes in address. */
static void ether1394_header_cache_update(struct hh_cache *hh,
const struct net_device *dev,
const unsigned char * haddr)
{
memcpy((u8 *)hh->hh_data + 16 - ETH1394_HLEN, haddr, dev->addr_len);
}
/******************************************
* Datagram reception code
******************************************/
/* Copied from net/ethernet/eth.c */
static u16 ether1394_type_trans(struct sk_buff *skb, struct net_device *dev)
{
struct eth1394hdr *eth;
unsigned char *rawp;
skb_reset_mac_header(skb);
skb_pull(skb, ETH1394_HLEN);
eth = eth1394_hdr(skb);
if (*eth->h_dest & 1) {
if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len) == 0)
skb->pkt_type = PACKET_BROADCAST;
#if 0
else
skb->pkt_type = PACKET_MULTICAST;
#endif
} else {
if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len))
skb->pkt_type = PACKET_OTHERHOST;
}
if (ntohs(eth->h_proto) >= 1536)
return eth->h_proto;
rawp = skb->data;
if (*(unsigned short *)rawp == 0xFFFF)
return htons(ETH_P_802_3);
return htons(ETH_P_802_2);
}
/* Parse an encapsulated IP1394 header into an ethernet frame packet.
* We also perform ARP translation here, if need be. */
static u16 ether1394_parse_encap(struct sk_buff *skb, struct net_device *dev,
nodeid_t srcid, nodeid_t destid,
u16 ether_type)
{
struct eth1394_priv *priv = netdev_priv(dev);
u64 dest_hw;
unsigned short ret = 0;
/* Setup our hw addresses. We use these to build the ethernet header. */
if (destid == (LOCAL_BUS | ALL_NODES))
dest_hw = ~0ULL; /* broadcast */
else
dest_hw = cpu_to_be64((u64)priv->host->csr.guid_hi << 32 |
priv->host->csr.guid_lo);
/* If this is an ARP packet, convert it. First, we want to make
* use of some of the fields, since they tell us a little bit
* about the sending machine. */
if (ether_type == htons(ETH_P_ARP)) {
struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data;
struct arphdr *arp = (struct arphdr *)skb->data;
unsigned char *arp_ptr = (unsigned char *)(arp + 1);
u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 |
ntohl(arp1394->fifo_lo);
u8 max_rec = min(priv->host->csr.max_rec,
(u8)(arp1394->max_rec));
int sspd = arp1394->sspd;
u16 maxpayload;
struct eth1394_node_ref *node;
struct eth1394_node_info *node_info;
__be64 guid;
/* Sanity check. MacOSX seems to be sending us 131 in this
* field (atleast on my Panther G5). Not sure why. */
if (sspd > 5 || sspd < 0)
sspd = 0;
maxpayload = min(eth1394_speedto_maxpayload[sspd],
(u16)(1 << (max_rec + 1)));
guid = get_unaligned(&arp1394->s_uniq_id);
node = eth1394_find_node_guid(&priv->ip_node_list,
be64_to_cpu(guid));
if (!node)
return 0;
node_info =
(struct eth1394_node_info *)node->ud->device.driver_data;
/* Update our speed/payload/fifo_offset table */
node_info->maxpayload = maxpayload;
node_info->sspd = sspd;
node_info->fifo = fifo_addr;
/* Now that we're done with the 1394 specific stuff, we'll
* need to alter some of the data. Believe it or not, all
* that needs to be done is sender_IP_address needs to be
* moved, the destination hardware address get stuffed
* in and the hardware address length set to 8.
*
* IMPORTANT: The code below overwrites 1394 specific data
* needed above so keep the munging of the data for the
* higher level IP stack last. */
arp->ar_hln = 8;
arp_ptr += arp->ar_hln; /* skip over sender unique id */
*(u32 *)arp_ptr = arp1394->sip; /* move sender IP addr */
arp_ptr += arp->ar_pln; /* skip over sender IP addr */
if (arp->ar_op == htons(ARPOP_REQUEST))
memset(arp_ptr, 0, sizeof(u64));
else
memcpy(arp_ptr, dev->dev_addr, sizeof(u64));
}
/* Now add the ethernet header. */
if (dev_hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL,
skb->len) >= 0)
ret = ether1394_type_trans(skb, dev);
return ret;
}
static int fragment_overlap(struct list_head *frag_list, int offset, int len)
{
struct fragment_info *fi;
int end = offset + len;
list_for_each_entry(fi, frag_list, list)
if (offset < fi->offset + fi->len && end > fi->offset)
return 1;
return 0;
}
static struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl)
{
struct partial_datagram *pd;
list_for_each_entry(pd, pdgl, list)
if (pd->dgl == dgl)
return &pd->list;
return NULL;
}
/* Assumes that new fragment does not overlap any existing fragments */
static int new_fragment(struct list_head *frag_info, int offset, int len)
{
struct list_head *lh;
struct fragment_info *fi, *fi2, *new;
list_for_each(lh, frag_info) {
fi = list_entry(lh, struct fragment_info, list);
if (fi->offset + fi->len == offset) {
/* The new fragment can be tacked on to the end */
fi->len += len;
/* Did the new fragment plug a hole? */
fi2 = list_entry(lh->next, struct fragment_info, list);
if (fi->offset + fi->len == fi2->offset) {
/* glue fragments together */
fi->len += fi2->len;
list_del(lh->next);
kfree(fi2);
}
return 0;
} else if (offset + len == fi->offset) {
/* The new fragment can be tacked on to the beginning */
fi->offset = offset;
fi->len += len;
/* Did the new fragment plug a hole? */
fi2 = list_entry(lh->prev, struct fragment_info, list);
if (fi2->offset + fi2->len == fi->offset) {
/* glue fragments together */
fi2->len += fi->len;
list_del(lh);
kfree(fi);
}
return 0;
} else if (offset > fi->offset + fi->len) {
break;
} else if (offset + len < fi->offset) {
lh = lh->prev;
break;
}
}
new = kmalloc(sizeof(*new), GFP_ATOMIC);
if (!new)
return -ENOMEM;
new->offset = offset;
new->len = len;
list_add(&new->list, lh);
return 0;
}
static int new_partial_datagram(struct net_device *dev, struct list_head *pdgl,
int dgl, int dg_size, char *frag_buf,
int frag_off, int frag_len)
{
struct partial_datagram *new;
new = kmalloc(sizeof(*new), GFP_ATOMIC);
if (!new)
return -ENOMEM;
INIT_LIST_HEAD(&new->frag_info);