2 * linux/drivers/i2o/i2o_lan.c
4 * I2O LAN CLASS OSM Prototyping, July 16th 1999
6 * (C) Copyright 1999 University of Helsinki,
7 * Department of Computer Science
9 * This code is still under development / test.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
16 * Authors: Auvo Häkkinen <Auvo.Hakkinen@cs.Helsinki.FI>
17 * Juha Sievänen <Juha.Sievanen@cs.Helsinki.FI>
18 * Deepak Saxena <deepak@plexity.net>
20 * Tested: in FDDI environment (using SysKonnect's DDM)
21 * in Ethernet environment (using Intel 82558 DDM proto)
23 * TODO: batch mode networking
24 * - we've not been able to test batch replies and
26 * error checking / timeouts
27 * code / test for other LAN classes
30 #include <linux/config.h>
31 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/fddidevice.h>
36 #include <linux/skbuff.h>
37 #include <linux/if_arp.h>
38 #include <linux/malloc.h>
39 #include <linux/trdevice.h>
40 #include <linux/init.h>
41 #include <linux/spinlock.h>
44 #include <linux/errno.h>
46 #include <linux/i2o.h>
51 #define dprintk(s, args...) printk(s, ## args)
53 #define dprintk(s, args...)
56 #define MAX_LAN_CARDS 4
57 static struct net_device
*i2o_landevs
[MAX_LAN_CARDS
+1];
58 static int unit
= -1; /* device unit number */
60 struct i2o_lan_local
{
62 struct i2o_device
*i2o_dev
;
63 int reply_flag
; /* needed by scalar/table queries */
64 u32 packet_tresh
; /* treshold for incoming skb's */
65 struct fddi_statistics stats
; /* see also struct net_device_stats */
66 unsigned short (*type_trans
)(struct sk_buff
*, struct net_device
*);
68 * Due to way that interrupts can pile up, we need to keep track
69 * of buckets ourselves. Otherwise we'll end up flooding
70 * the DDM with buckets.
75 /* function prototypes */
76 static int i2o_lan_receive_post(struct net_device
*dev
);
77 static int i2o_lan_receive_post_reply(struct net_device
*dev
, struct i2o_message
*m
);
78 static void i2o_lan_release_buckets(u32
*msg
, struct i2o_lan_local
*priv
);
83 static u32 bucketpost
= I2O_BUCKET_COUNT
;
84 static u32 bucketthresh
= I2O_BUCKET_THRESH
;
85 static u32 rx_copybreak
= 200;
87 static void i2o_lan_reply(struct i2o_handler
*h
, struct i2o_controller
*iop
,
88 struct i2o_message
*m
)
91 u8 unit
= (u8
)(msg
[2]>>16); // InitiatorContext
92 struct net_device
*dev
= i2o_landevs
[unit
];
93 struct i2o_lan_local
*priv
;
96 priv
= (struct i2o_lan_local
*)dev
->priv
;
100 dprintk("Unit: %d Function: %#x\n",
103 if (msg
[0] & (1<<13)) // Fail bit is set
105 printk(KERN_ERR
"IOP failed to process the msg:\n");
106 printk(KERN_ERR
" Cmd = 0x%02X, InitiatorTid = %d, TargetTid = %d\n",
107 (msg
[1] >> 24) & 0xFF, (msg
[1] >> 12) & 0xFFF, msg
[1] & 0xFFF);
108 printk(KERN_ERR
" FailureCode = 0x%02X\n Severity = 0x%02X\n "
109 "LowestVersion = 0x%02X\n HighestVersion = 0x%02X\n",
110 msg
[4] >> 24, (msg
[4] >> 16) & 0xFF,
111 (msg
[4] >> 8) & 0xFF, msg
[4] & 0xFF);
112 printk(KERN_ERR
" FailingHostUnit = 0x%04X\n FailingIOP = 0x%03X\n",
113 msg
[5] >> 16, msg
[5] & 0xFFF);
118 if (msg
[4] >> 24) /* ReqStatus != SUCCESS */
120 i2o_report_status(KERN_INFO
, dev
->name
, msg
);
122 switch (msg
[1] >> 24) {
123 case LAN_RECEIVE_POST
:
129 i2o_lan_receive_post_reply(dev
,m
);
134 // Something VERY wrong if this is happening
135 printk( KERN_WARNING
"i2olan: Device %s rejected bucket post\n", dev
->name
);
136 i2o_lan_release_buckets(msg
,priv
);
141 i2o_lan_release_buckets(msg
,priv
);
147 case LAN_PACKET_SEND
:
150 u8 trl_count
= msg
[3] & 0x000000FF;
152 do { // The HDM has handled the outgoing packet
153 dev_kfree_skb((struct sk_buff
*)msg
[4 + trl_count
]);
154 dprintk(KERN_INFO
"%s: Request skb freed (trl_count=%d).\n",
155 dev
->name
,trl_count
);
156 } while (--trl_count
);
159 mark_bh(NET_BH
); /* inform upper layers */
165 if (msg
[2] & 0x80000000) // reply to a UtilParamsGet/Set
167 int *flag
= (int *)msg
[3]; // flag for i2o_post_wait
168 if (msg
[4] >> 24) // ReqStatus != SUCCESS
170 *flag
= -(msg
[4] & 0xFFFF); // DetailedStatus
173 *flag
= I2O_POST_WAIT_OK
;
178 void i2o_lan_release_buckets(u32
*msg
, struct i2o_lan_local
*priv
)
180 u8 trl_count
= (u8
)(msg
[3] & 0x000000FF);
185 dprintk("%s: Releasing unused sk_buff %p\n",dev
->name
,
186 (struct sk_buff
*)(*pskb
));
187 dev_kfree_skb((struct sk_buff
*)(*pskb
));
190 priv
->bucket_count
--;
195 static struct i2o_handler i2o_lan_handler
=
202 static int lan_context
;
205 static int i2o_lan_receive_post_reply(struct net_device
*dev
, struct i2o_message
*m
)
208 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
209 struct i2o_bucket_descriptor
*bucket
= (struct i2o_bucket_descriptor
*)&msg
[6];
210 struct i2o_packet_info
*packet
;
212 u8 trl_count
= msg
[3] & 0x000000FF;
213 struct sk_buff
*skb
, *newskb
;
216 dprintk(KERN_INFO
"TrlFlags = 0x%02X, TrlElementSize = %d, TrlCount = %d\n"
217 "msgsize = %d, buckets_remaining = %d\n",
218 msg
[3]>>24, msg
[3]&0x0000FF00, trl_count
, msg
[0]>>16, msg
[5]);
221 dprintk(KERN_INFO
"Buckets_remaining = %d, bucket_count = %d\n",
222 msg
[5], priv
->bucket_count
);
225 skb
= (struct sk_buff
*)(bucket
->context
);
226 packet
= (struct i2o_packet_info
*)bucket
->packet_info
;
227 priv
->bucket_count
--;
229 dprintk(KERN
)INFO
"flags = 0x%02X, offset = 0x%06X, status = 0x%02X, length = %d\n",
230 packet
->flags
, packet
->offset
, packet
->status
, packet
->len
);
232 if (packet
->len
< rx_copybreak
) {
233 newskb
= (struct sk_buff
*)
234 dev_alloc_skb(packet
->len
+2);
236 skb_reserve(newskb
,2);
237 memcpy(skb_put(newskb
,packet
->len
),
238 skb
->data
, packet
->len
);
240 newskb
->protocol
= priv
->type_trans(newskb
, dev
);
243 dev_kfree_skb(skb
); // FIXME: reuse this skb?
246 printk("I2OLAN-%s: Can't allocate skb.\n", dev
->name
);
251 skb_put(skb
,packet
->len
);
253 skb
->protocol
= priv
->type_trans(skb
, dev
);
257 dprintk(KERN_INFO
"%s: Incoming packet (%d bytes) delivered "
258 "to upper level.\n",dev
->name
,packet
->len
);
260 bucket
++; // to next Packet Descriptor Block
261 } while (--trl_count
);
263 if (priv
->bucket_count
<= bucketthresh
) // BucketsRemaining
265 dprintk("Bucket_count = %d, ",priv
->bucket_count
);
266 i2o_lan_receive_post(dev
);
270 if((msg
[4]& 0x0000ffff) == 0x05) // I2O_LAN_RECEIVE_OVERRUN
272 printk("Bucket overrun! priv->bucketcount = %d\n",
279 /* ====================================================
280 * Interface to i2o: functions to send lan class request
285 * i2o_lan_receive_post(): Post buckets to receive packets.
287 static int i2o_lan_receive_post(struct net_device
*dev
)
289 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
290 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
291 struct i2o_controller
*iop
= i2o_dev
->controller
;
295 u32 bucket_len
= (dev
->mtu
+ dev
->hard_header_len
);
297 int n_elems
= (iop
->inbound_size
- 16 ) / 12; /* msg header + SGLs */
301 while (total
< bucketpost
)
303 m
= I2O_POST_READ32(iop
);
306 msg
= bus_to_virt(iop
->mem_offset
+ m
);
308 bucket_count
= (total
+ n_elems
< bucketpost
)
310 : bucketpost
- total
;
312 msg
[0] = I2O_MESSAGE_SIZE(4 + 3 * bucket_count
) | SGL_OFFSET_4
;
313 msg
[1] = LAN_RECEIVE_POST
<<24 | HOST_TID
<<12 | i2o_dev
->id
;
314 msg
[2] = priv
->unit
<< 16 | lan_context
; // InitiatorContext
315 msg
[3] = bucket_count
; // BucketCount
317 for (i
= 0; i
< bucket_count
; i
++)
319 skb
= dev_alloc_skb(bucket_len
+ 2);
324 priv
->bucket_count
++;
326 msg
[4 + 3*i
] = 0x51000000 | bucket_len
;
327 msg
[5 + 3*i
] = (u32
)skb
;
328 msg
[6 + 3*i
] = virt_to_bus(skb
->data
);
330 msg
[4 + 3*i
- 3] |= 0x80000000; // set LE flag
331 i2o_post_message(iop
,m
);
333 dprintk(KERN_INFO
"%s: Sending %d buckets (size %d) to LAN HDM.\n",
334 dev
->name
, bucket_count
, bucket_len
);
336 total
+= bucket_count
;
343 * i2o_lan_reset(): Reset the LAN adapter into the operational state and
344 * restore it to full operation.
346 static int i2o_lan_reset(struct net_device
*dev
)
348 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
349 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
350 struct i2o_controller
*iop
= i2o_dev
->controller
;
353 msg
[0] = FIVE_WORD_MSG_SIZE
| SGL_OFFSET_0
;
354 msg
[1] = LAN_RESET
<<24 | HOST_TID
<<12 | i2o_dev
->id
;
355 msg
[2] = priv
->unit
<< 16 | lan_context
; // InitiatorContext
356 msg
[3] = 0; // TransactionContext
357 msg
[4] = 1 << 16; // return posted buckets
359 if (i2o_post_this(iop
, i2o_dev
->id
, msg
, sizeof(msg
)) < 0)
366 * i2o_lan_suspend(): Put LAN adapter into a safe, non-active state.
367 * Reply to any LAN class message with status error_no_data_transfer
370 static int i2o_lan_suspend(struct net_device
*dev
)
372 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
373 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
374 struct i2o_controller
*iop
= i2o_dev
->controller
;
377 dprintk( "%s: LAN SUSPEND MESSAGE\n", dev
->name
);
378 msg
[0] = FIVE_WORD_MSG_SIZE
| SGL_OFFSET_0
;
379 msg
[1] = LAN_SUSPEND
<<24 | HOST_TID
<<12 | i2o_dev
->id
;
380 msg
[2] = priv
->unit
<< 16 | lan_context
; // InitiatorContext
381 msg
[3] = 0; // TransactionContext
382 msg
[4] = 1 << 16; // return posted buckets
384 if (i2o_post_this(iop
, i2o_dev
->id
, msg
, sizeof(msg
)) < 0)
391 * Set DDM into batch mode.
393 static void i2o_set_batch_mode(struct net_device
*dev
)
397 * NOTE: we have not been able to test batch mode
398 * since HDMs we have, don't implement it
401 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
402 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
403 struct i2o_controller
*iop
= i2o_dev
->controller
;
406 /* set LAN_BATCH_CONTROL attributes */
408 // enable batch mode, toggle automatically
410 // val = 0x00000001; // turn off batch mode
411 if (i2o_set_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0003, 0,
412 &val
, 4, &priv
->reply_flag
) <0)
413 printk(KERN_WARNING
"Unable to enter I2O LAN batch mode.\n");
415 dprintk(KERN_INFO
"%s: I2O LAN batch mode enabled.\n",dev
->name
);
416 // dprintk(KERN_INFO "%s: I2O LAN batch mode disabled.\n",dev->name);
418 * When PacketOrphanlimit is same as the maximum packet length,
419 * the packets will never be split into two separate buckets
422 /* set LAN_OPERATION attributes */
424 val
= dev
->mtu
+ dev
->hard_header_len
; // PacketOrphanLimit
425 if (i2o_set_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0004, 2,
426 &val
, 4, &priv
->reply_flag
) < 0)
427 printk(KERN_WARNING
"i2o_lan: Unable to set PacketOrphanLimit.\n");
429 dprintk(KERN_INFO
"%s: PacketOrphanLimit set to %d\n",
436 * i2o_lan_open(): Open the device to send/receive packets via
437 * the network device.
439 static int i2o_lan_open(struct net_device
*dev
)
441 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
442 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
443 struct i2o_controller
*iop
= i2o_dev
->controller
;
445 /* if (i2o_issue_claim(iop, i2o_dev->id, priv->unit << 16 | lan_context, 1,
446 &priv->reply_flag) < 0)
448 if(i2o_claim_device(i2o_dev
, &i2o_lan_handler
, I2O_CLAIM_PRIMARY
))
450 printk(KERN_WARNING
"%s: Unable to claim the I2O LAN device.\n", dev
->name
);
453 dprintk(KERN_INFO
"%s: I2O LAN device claimed (tid=%d).\n", dev
->name
, i2o_dev
->id
);
460 priv
->packet_tresh
= dev
->mtu
- (dev
->mtu
>> 3);
462 i2o_set_batch_mode(dev
);
463 i2o_lan_receive_post(dev
);
471 * i2o_lan_close(): End the transfering.
473 static int i2o_lan_close(struct net_device
*dev
)
475 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
476 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
477 struct i2o_controller
*iop
= i2o_dev
->controller
;
482 // This is the right place for LanSuspend, but it seems to cause
483 // a kernel crash when we are using 82558 HDM proto
485 i2o_lan_suspend(dev
);
488 if (i2o_issue_claim(iop, i2o_dev->id, priv->unit << 16 | lan_context, 0,
489 &priv->reply_flag) < 0)
492 if(i2o_release_device(i2o_dev
, &i2o_lan_handler
, I2O_CLAIM_PRIMARY
))
493 printk(KERN_WARNING
"%s: Unable to unclaim I2O LAN device "
494 "(tid=%d)\n", dev
->name
, i2o_dev
->id
);
502 * i2o_lan_sdu_send(): Send a packet, MAC header added by the HDM.
503 * Must be supported by Fibre Channel, optional for Ethernet/802.3,
506 static int i2o_lan_sdu_send(struct sk_buff
*skb
, struct net_device
*dev
)
510 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
511 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
512 struct i2o_controller
*iop
= i2o_dev
->controller
;
515 dprintk(KERN_INFO
"LanSDUSend called, skb->len = %d\n", skb
->len
);
517 m
= I2O_POST_READ32(iop
);
523 msg
= bus_to_virt(iop
->mem_offset
+ m
);
525 msg
[0] = NINE_WORD_MSG_SIZE
| SGL_OFFSET_4
;
526 msg
[1] = LAN_SDU_SEND
<<24 | HOST_TID
<<12 | i2o_dev
->id
;
527 msg
[2] = priv
->unit
<< 16 | lan_context
; // IntiatorContext
528 msg
[3] = 1<<4; // TransmitControlWord: suppress CRC generation
530 // create a simple SGL, see fig. 3-26
531 // D7 = 1101 0111 = LE eob 0 1 LA dir bc1 bc0
533 msg
[4] = 0xD7000000 | (skb
->len
); // no MAC hdr included
534 msg
[5] = (u32
)skb
; // TransactionContext
535 memcpy(&msg
[6], skb
->data
, 8); // Destination MAC Addr ??
536 msg
[7] &= 0x0000FFFF; // followed by two bytes zeros
537 msg
[8] = virt_to_bus(skb
->data
);
538 dev
->trans_start
= jiffies
;
539 i2o_post_message(iop
,m
);
541 dprintk(KERN_INFO
"%s: Packet (%d bytes) sent to network.\n",
548 * i2o_lan_packet_send(): Send a packet as is, including the MAC header.
550 * Must be supported by Ethernet/802.3, Token Ring, FDDI, optional for
553 static int i2o_lan_packet_send(struct sk_buff
*skb
, struct net_device
*dev
)
555 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
556 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
557 struct i2o_controller
*iop
= i2o_dev
->controller
;
560 m
= I2O_POST_READ32(iop
);
561 if (m
== 0xFFFFFFFF) {
565 msg
= bus_to_virt(iop
->mem_offset
+ m
);
567 msg
[0] = SEVEN_WORD_MSG_SIZE
| 1<<12 | SGL_OFFSET_4
;
568 msg
[1] = LAN_PACKET_SEND
<<24 | HOST_TID
<<12 | i2o_dev
->id
;
569 msg
[2] = priv
->unit
<< 16 | lan_context
; // IntiatorContext
570 msg
[3] = 1 << 4; // TransmitControlWord
572 // create a simple SGL, see fig. 3-26
573 // D5 = 1101 0101 = LE eob 0 1 LA dir bc1 bc0
575 msg
[4] = 0xD5000000 | skb
->len
; // MAC hdr included
576 msg
[5] = (u32
)skb
; // TransactionContext
577 msg
[6] = virt_to_bus(skb
->data
);
579 i2o_post_message(iop
,m
);
580 dprintk(KERN_INFO
"%s: Packet (%d bytes) sent to network.\n",
581 dev
->name
, skb
->len
);
586 static struct net_device_stats
*i2o_lan_get_stats(struct net_device
*dev
)
588 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
589 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
590 struct i2o_controller
*iop
= i2o_dev
->controller
;
592 u64 supported_group
[4] = { 0, 0, 0, 0 };
594 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0100, -1,
595 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
596 dprintk("%s: Unable to query LAN_HISTORICAL_STATS.\n",dev
->name
);
598 dprintk("%s: LAN_HISTORICAL_STATS queried.\n",dev
->name
);
599 priv
->stats
.tx_packets
= val64
[0];
600 priv
->stats
.tx_bytes
= val64
[1];
601 priv
->stats
.rx_packets
= val64
[2];
602 priv
->stats
.rx_bytes
= val64
[3];
603 priv
->stats
.tx_errors
= val64
[4];
604 priv
->stats
.rx_errors
= val64
[5];
605 priv
->stats
.rx_dropped
= val64
[6];
608 i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0180, -1,
609 &supported_group
, sizeof(supported_group
), &priv
->reply_flag
);
611 if (supported_group
[2]) {
612 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0183, -1,
613 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
614 dprintk("%s: Unable to query LAN_OPTIONAL_RX_HISTORICAL_STATS.\n",dev
->name
);
616 dprintk("%s: LAN_OPTIONAL_RX_HISTORICAL_STATS queried.\n",dev
->name
);
617 priv
->stats
.multicast
= val64
[4];
618 priv
->stats
.rx_length_errors
= val64
[10];
619 priv
->stats
.rx_crc_errors
= val64
[0];
623 if (i2o_dev
->subclass
== I2O_LAN_ETHERNET
)
625 u64 supported_stats
= 0;
627 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0200, -1,
628 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
629 dprintk("%s: Unable to query LAN_802_3_HISTORICAL_STATS.\n",dev
->name
);
631 // dprintk("%s: LAN_802_3_HISTORICAL_STATS queried.\n",dev->name);
632 priv
->stats
.transmit_collision
= val64
[1] + val64
[2];
633 priv
->stats
.rx_frame_errors
= val64
[0];
634 priv
->stats
.tx_carrier_errors
= val64
[6];
637 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0280, -1,
638 &supported_stats
, 8, &priv
->reply_flag
) < 0)
639 dprintk("%s: Unable to query LAN_SUPPORTED_802_3_HISTORICAL_STATS\n", dev
->name
);
641 if (supported_stats
!= 0) {
642 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0281, -1,
643 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
644 dprintk("%s: Unable to query LAN_OPTIONAL_802_3_HISTORICAL_STATS.\n",dev
->name
);
646 dprintk("%s: LAN_OPTIONAL_802_3_HISTORICAL_STATS queried.\n",dev
->name
);
647 if (supported_stats
& 0x1)
648 priv
->stats
.rx_over_errors
= val64
[0];
649 if (supported_stats
& 0x4)
650 priv
->stats
.tx_heartbeat_errors
= val64
[2];
657 if (i2o_dev
->subclass
== I2O_LAN_TR
)
659 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0300, -1,
660 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
661 dprintk("%s: Unable to query LAN_802_5_HISTORICAL_STATS.\n",dev
->name
);
663 struct tr_statistics
*stats
=
664 (struct tr_statistics
*)&priv
->stats
;
665 // dprintk("%s: LAN_802_5_HISTORICAL_STATS queried.\n",dev->name);
667 stats
->line_errors
= val64
[0];
668 stats
->internal_errors
= val64
[7];
669 stats
->burst_errors
= val64
[4];
670 stats
->A_C_errors
= val64
[2];
671 stats
->abort_delimiters
= val64
[3];
672 stats
->lost_frames
= val64
[1];
673 /* stats->recv_congest_count = ?; FIXME ??*/
674 stats
->frame_copied_errors
= val64
[5];
675 stats
->frequency_errors
= val64
[6];
676 stats
->token_errors
= val64
[9];
678 /* Token Ring optional stats not yet defined */
683 if (i2o_dev
->subclass
== I2O_LAN_FDDI
)
685 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0400, -1,
686 val64
, sizeof(val64
), &priv
->reply_flag
) < 0)
687 dprintk("%s: Unable to query LAN_FDDI_HISTORICAL_STATS.\n",dev
->name
);
689 // dprintk("%s: LAN_FDDI_HISTORICAL_STATS queried.\n",dev->name);
690 priv
->stats
.smt_cf_state
= val64
[0];
691 memcpy(priv
->stats
.mac_upstream_nbr
, &val64
[1], FDDI_K_ALEN
);
692 memcpy(priv
->stats
.mac_downstream_nbr
, &val64
[2], FDDI_K_ALEN
);
693 priv
->stats
.mac_error_cts
= val64
[3];
694 priv
->stats
.mac_lost_cts
= val64
[4];
695 priv
->stats
.mac_rmt_state
= val64
[5];
696 memcpy(priv
->stats
.port_lct_fail_cts
, &val64
[6], 8);
697 memcpy(priv
->stats
.port_lem_reject_cts
, &val64
[7], 8);
698 memcpy(priv
->stats
.port_lem_cts
, &val64
[8], 8);
699 memcpy(priv
->stats
.port_pcm_state
, &val64
[9], 8);
701 /* FDDI optional stats not yet defined */
705 return (struct net_device_stats
*)&priv
->stats
;
709 * i2o_lan_set_multicast_list(): Enable a network device to receive packets
710 * not send to the protocol address.
712 static void i2o_lan_set_multicast_list(struct net_device
*dev
)
714 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
715 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
716 struct i2o_controller
*iop
= i2o_dev
->controller
;
720 dprintk(KERN_INFO
"%s: Entered i2o_lan_set_multicast_list().\n", dev
->name
);
723 printk("dev is NULL\n");
724 else if (dev
->priv
==NULL
)
725 printk("dev->priv is NULL\n");
726 else if (priv
->i2o_dev
==NULL
)
727 printk("i2o_dev is NULL\n");
728 else if (i2o_dev
->controller
==NULL
)
729 printk("iop is NULL\n");
731 printk("Everything seems to be OK in i2o_lan_set_multicast_list().\n");
732 printk("id = %d, unit = %d, lan_context = %d\n",
733 i2o_dev
->id
, priv
->unit
, lan_context
);
738 /* FIXME: Why does the next call kill the interrupt handler?
739 * The same piece of code works fine in function lan_open(), and in i2o_proc.c
741 * *because its trying to sleep in an irq - this must be async - Alan
744 if (i2o_query_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0001, -1,
745 &work32
, sizeof(work32
), &priv
->reply_flag
) < 0 )
747 printk(KERN_WARNING
"i2o_lan: Unable to query "
748 " LAN_MAC_ADDRESS table.\n");
751 printk(KERN_INFO
"capab mask = 0x%08X, filter mask = 0x%08X\n",
752 work32
[7], work32
[6]);
754 filter_mask
= work32
[6];
756 if (dev
->flags
& IFF_PROMISC
)
758 filter_mask
|= 0x00000002;
759 dprintk(KERN_INFO
"i2o_lan: Enabling promiscuous mode...\n");
762 else if ((dev
->flags
& IFF_ALLMULTI
) || dev
->mc_count
> work32
[5])
764 filter_mask
|= 0x00000000;
765 dprintk(KERN_INFO
"i2o_lan: Enabling all multicast mode...\n");
768 else if (dev
->mc_count
)
770 struct dev_mc_list
*mclist
;
772 u8
*work8
= (u8
*)work32
;
774 dprintk(KERN_INFO
"i2o_lan: Enabling multicast mode...\n");
775 filter_mask
= 0x00000004;
777 /* Fill the multicast addresses */
778 mclist
= dev
->mc_list
;
780 for (i
= 0; i
< dev
->mc_count
; i
++)
782 memcpy(work8
, mclist
->dmi_addr
, mclist
->dmi_addrlen
);
784 mclist
= mclist
->next
;
787 if (i2o_clear_table(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0002,
788 &priv
->reply_flag
) < 0 )
789 dprintk("%s: Unable to clear LAN_MULTICAST_MAC_ADDRESS table.\n",dev
->name
);
791 if (i2o_row_add_table(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0002, -1,
792 work32
, dev
->mc_count
*8, &priv
->reply_flag
) < 0)
793 dprintk("%s: Unable to set LAN_MULTICAST_MAC_ADDRESS table.\n",dev
->name
);
797 filter_mask
|= 0x00000300; // Broadcast, Multicast disabled
798 dprintk(KERN_INFO
"i2o_lan: Enabling unicast mode...\n");
801 if (i2o_set_scalar(iop
, i2o_dev
->id
, priv
->unit
<< 16 | lan_context
, 0x0001, 3,
802 &filter_mask
, 4, &priv
->reply_flag
) <0)
803 printk(KERN_WARNING
"i2o_lan: Unable to set MAC FilterMask.\n");
808 struct net_device
*i2o_lan_register_device(struct i2o_device
*i2o_dev
)
810 struct net_device
*dev
= NULL
;
811 struct i2o_lan_local
*priv
= NULL
;
813 unsigned short (*type_trans
)(struct sk_buff
*, struct net_device
*);
814 void (*unregister_dev
)(struct net_device
*dev
);
816 switch (i2o_dev
->subclass
)
818 case I2O_LAN_ETHERNET
:
819 dev
= init_etherdev(NULL
, sizeof(struct i2o_lan_local
));
822 type_trans
= eth_type_trans
;
823 unregister_dev
= unregister_netdev
;
829 printk(KERN_ERR
"i2o_lan: 100base VG not yet supported\n");
836 dev
= init_trdev(NULL
, sizeof(struct i2o_lan_local
));
839 type_trans
= tr_type_trans
;
840 unregister_dev
= unregister_trdev
;
847 int size
= sizeof(struct net_device
) + sizeof(struct i2o_lan_local
)
850 dev
= (struct net_device
*) kmalloc(size
, GFP_KERNEL
);
851 memset((char *)dev
, 0, size
);
852 dev
->priv
= (void *)(dev
+ 1);
853 dev
->name
= (char *)(dev
+ 1) + sizeof(struct i2o_lan_local
);
855 if (dev_alloc_name(dev
,"fddi%d") < 0)
857 printk(KERN_WARNING
"i2o_lan: Too many FDDI devices.\n");
861 type_trans
= fddi_type_trans
;
862 unregister_dev
= (void *)unregister_netdevice
;
865 register_netdev(dev
);
870 #ifdef CONFIG_FIBRE_CHANNEL
871 case I2O_LAN_FIBRE_CHANNEL
:
872 printk(KERN_INFO
"i2o_lan: Fibre Channel not yet supported\n");
876 case I2O_LAN_UNKNOWN
:
878 printk(KERN_ERR
"i2o_lan: LAN type 0x%08X not supported\n",
883 priv
= (struct i2o_lan_local
*)dev
->priv
;
884 priv
->i2o_dev
= i2o_dev
;
885 priv
->type_trans
= type_trans
;
886 priv
->bucket_count
= 0;
889 i2o_landevs
[unit
] = dev
;
892 if (i2o_query_scalar(i2o_dev
->controller
, i2o_dev
->id
,
893 priv
->unit
<< 16 | lan_context
,
894 0x0001, 0, &hw_addr
, 8, &priv
->reply_flag
) < 0)
896 printk(KERN_ERR
"%s: Unable to query hardware address.\n", dev
->name
);
903 dprintk("%s: hwaddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
904 dev
->name
,hw_addr
[0], hw_addr
[1], hw_addr
[2], hw_addr
[3],
905 hw_addr
[4], hw_addr
[5]);
908 memcpy(dev
->dev_addr
, hw_addr
, 6);
910 dev
->open
= i2o_lan_open
;
911 dev
->stop
= i2o_lan_close
;
912 dev
->hard_start_xmit
= i2o_lan_packet_send
;
913 dev
->get_stats
= i2o_lan_get_stats
;
914 dev
->set_multicast_list
= i2o_lan_set_multicast_list
;
920 #define i2o_lan_init init_module
923 __init
int i2o_lan_init(void)
925 struct net_device
*dev
;
928 bucketpost
= bucketpost
- bucketthresh
;
930 if (i2o_install_handler(&i2o_lan_handler
) < 0)
932 printk(KERN_ERR
"Unable to register I2O LAN OSM.\n");
936 for(i
=0; i
<= MAX_LAN_CARDS
; i
++)
937 i2o_landevs
[i
] = NULL
;
939 lan_context
= i2o_lan_handler
.context
;
941 for (i
=0; i
< MAX_I2O_CONTROLLERS
; i
++)
943 struct i2o_controller
*iop
= i2o_find_controller(i
);
944 struct i2o_device
*i2o_dev
;
949 for (i2o_dev
=iop
->devices
;i2o_dev
!= NULL
;i2o_dev
=i2o_dev
->next
)
951 if (i2o_dev
->class != I2O_CLASS_LAN
)
954 if (unit
== MAX_LAN_CARDS
)
956 i2o_unlock_controller(iop
);
957 printk(KERN_WARNING
"Too many I2O LAN devices.\n");
961 dev
= i2o_lan_register_device(i2o_dev
);
964 printk(KERN_ERR
"Unable to register I2O LAN device\n");
965 continue; // try next one
968 printk(KERN_INFO
"%s: I2O LAN device registered, tid = %d,"
969 " subclass = 0x%08X, unit = %d.\n",
970 dev
->name
, i2o_dev
->id
, i2o_dev
->subclass
,
971 ((struct i2o_lan_local
*)dev
->priv
)->unit
);
974 i2o_unlock_controller(iop
);
977 dprintk(KERN_INFO
"%d I2O LAN devices found and registered.\n", unit
+1);
984 void cleanup_module(void)
988 for (i
= 0; i
<= unit
; i
++)
990 struct net_device
*dev
= i2o_landevs
[i
];
991 struct i2o_lan_local
*priv
= (struct i2o_lan_local
*)dev
->priv
;
992 struct i2o_device
*i2o_dev
= priv
->i2o_dev
;
994 switch (i2o_dev
->subclass
)
996 case I2O_LAN_ETHERNET
:
997 unregister_netdev(dev
);
1002 unregister_netdevice(dev
);
1008 unregister_trdev(dev
);
1013 printk(KERN_WARNING
"i2o_lan: Spurious I2O LAN subclass 0x%08X.\n",
1017 dprintk(KERN_INFO
"%s: I2O LAN device unregistered.\n",
1021 i2o_remove_handler(&i2o_lan_handler
);
1026 MODULE_AUTHOR("Univ of Helsinki, CS Department");
1027 MODULE_DESCRIPTION("I2O Lan OSM");
1029 MODULE_PARM(bucketpost
, "i"); // Number of buckets to post
1030 MODULE_PARM(bucketthresh
, "i"); // Bucket post threshold
1031 MODULE_PARM(rx_copybreak
, "i");