Merge ../linus
[linux-drm-fsl-dcu.git] / arch / ia64 / sn / kernel / xpnet.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1999,2001-2005 Silicon Graphics, Inc. All rights reserved.
7  */
8
9
10 /*
11  * Cross Partition Network Interface (XPNET) support
12  *
13  *      XPNET provides a virtual network layered on top of the Cross
14  *      Partition communication layer.
15  *
16  *      XPNET provides direct point-to-point and broadcast-like support
17  *      for an ethernet-like device.  The ethernet broadcast medium is
18  *      replaced with a point-to-point message structure which passes
19  *      pointers to a DMA-capable block that a remote partition should
20  *      retrieve and pass to the upper level networking layer.
21  *
22  */
23
24
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/pci.h>
28 #include <linux/init.h>
29 #include <linux/ioport.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/delay.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
35 #include <linux/smp.h>
36 #include <linux/string.h>
37 #include <asm/sn/bte.h>
38 #include <asm/sn/io.h>
39 #include <asm/sn/sn_sal.h>
40 #include <asm/types.h>
41 #include <asm/atomic.h>
42 #include <asm/sn/xp.h>
43
44
45 /*
46  * The message payload transferred by XPC.
47  *
48  * buf_pa is the physical address where the DMA should pull from.
49  *
50  * NOTE: for performance reasons, buf_pa should _ALWAYS_ begin on a
51  * cacheline boundary.  To accomplish this, we record the number of
52  * bytes from the beginning of the first cacheline to the first useful
53  * byte of the skb (leadin_ignore) and the number of bytes from the
54  * last useful byte of the skb to the end of the last cacheline
55  * (tailout_ignore).
56  *
57  * size is the number of bytes to transfer which includes the skb->len
58  * (useful bytes of the senders skb) plus the leadin and tailout
59  */
60 struct xpnet_message {
61         u16 version;            /* Version for this message */
62         u16 embedded_bytes;     /* #of bytes embedded in XPC message */
63         u32 magic;              /* Special number indicating this is xpnet */
64         u64 buf_pa;             /* phys address of buffer to retrieve */
65         u32 size;               /* #of bytes in buffer */
66         u8 leadin_ignore;       /* #of bytes to ignore at the beginning */
67         u8 tailout_ignore;      /* #of bytes to ignore at the end */
68         unsigned char data;     /* body of small packets */
69 };
70
71 /*
72  * Determine the size of our message, the cacheline aligned size,
73  * and then the number of message will request from XPC.
74  *
75  * XPC expects each message to exist in an individual cacheline.
76  */
77 #define XPNET_MSG_SIZE          (L1_CACHE_BYTES - XPC_MSG_PAYLOAD_OFFSET)
78 #define XPNET_MSG_DATA_MAX      \
79                 (XPNET_MSG_SIZE - (u64)(&((struct xpnet_message *)0)->data))
80 #define XPNET_MSG_ALIGNED_SIZE  (L1_CACHE_ALIGN(XPNET_MSG_SIZE))
81 #define XPNET_MSG_NENTRIES      (PAGE_SIZE / XPNET_MSG_ALIGNED_SIZE)
82
83
84 #define XPNET_MAX_KTHREADS      (XPNET_MSG_NENTRIES + 1)
85 #define XPNET_MAX_IDLE_KTHREADS (XPNET_MSG_NENTRIES + 1)
86
87 /*
88  * Version number of XPNET implementation. XPNET can always talk to versions
89  * with same major #, and never talk to versions with a different version.
90  */
91 #define _XPNET_VERSION(_major, _minor)  (((_major) << 4) | (_minor))
92 #define XPNET_VERSION_MAJOR(_v)         ((_v) >> 4)
93 #define XPNET_VERSION_MINOR(_v)         ((_v) & 0xf)
94
95 #define XPNET_VERSION _XPNET_VERSION(1,0)               /* version 1.0 */
96 #define XPNET_VERSION_EMBED _XPNET_VERSION(1,1)         /* version 1.1 */
97 #define XPNET_MAGIC     0x88786984 /* "XNET" */
98
99 #define XPNET_VALID_MSG(_m)                                                  \
100    ((XPNET_VERSION_MAJOR(_m->version) == XPNET_VERSION_MAJOR(XPNET_VERSION)) \
101     && (msg->magic == XPNET_MAGIC))
102
103 #define XPNET_DEVICE_NAME               "xp0"
104
105
106 /*
107  * When messages are queued with xpc_send_notify, a kmalloc'd buffer
108  * of the following type is passed as a notification cookie.  When the
109  * notification function is called, we use the cookie to decide
110  * whether all outstanding message sends have completed.  The skb can
111  * then be released.
112  */
113 struct xpnet_pending_msg {
114         struct list_head free_list;
115         struct sk_buff *skb;
116         atomic_t use_count;
117 };
118
119 /* driver specific structure pointed to by the device structure */
120 struct xpnet_dev_private {
121         struct net_device_stats stats;
122 };
123
124 struct net_device *xpnet_device;
125
126 /*
127  * When we are notified of other partitions activating, we add them to
128  * our bitmask of partitions to which we broadcast.
129  */
130 static u64 xpnet_broadcast_partitions;
131 /* protect above */
132 static DEFINE_SPINLOCK(xpnet_broadcast_lock);
133
134 /*
135  * Since the Block Transfer Engine (BTE) is being used for the transfer
136  * and it relies upon cache-line size transfers, we need to reserve at
137  * least one cache-line for head and tail alignment.  The BTE is
138  * limited to 8MB transfers.
139  *
140  * Testing has shown that changing MTU to greater than 64KB has no effect
141  * on TCP as the two sides negotiate a Max Segment Size that is limited
142  * to 64K.  Other protocols May use packets greater than this, but for
143  * now, the default is 64KB.
144  */
145 #define XPNET_MAX_MTU (0x800000UL - L1_CACHE_BYTES)
146 /* 32KB has been determined to be the ideal */
147 #define XPNET_DEF_MTU (0x8000UL)
148
149
150 /*
151  * The partition id is encapsulated in the MAC address.  The following
152  * define locates the octet the partid is in.
153  */
154 #define XPNET_PARTID_OCTET      1
155 #define XPNET_LICENSE_OCTET     2
156
157
158 /*
159  * Define the XPNET debug device structure that is to be used with dev_dbg(),
160  * dev_err(), dev_warn(), and dev_info().
161  */
162 struct device_driver xpnet_dbg_name = {
163         .name = "xpnet"
164 };
165
166 struct device xpnet_dbg_subname = {
167         .bus_id = {0},                  /* set to "" */
168         .driver = &xpnet_dbg_name
169 };
170
171 struct device *xpnet = &xpnet_dbg_subname;
172
173 /*
174  * Packet was recevied by XPC and forwarded to us.
175  */
176 static void
177 xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
178 {
179         struct sk_buff *skb;
180         bte_result_t bret;
181         struct xpnet_dev_private *priv =
182                 (struct xpnet_dev_private *) xpnet_device->priv;
183
184
185         if (!XPNET_VALID_MSG(msg)) {
186                 /*
187                  * Packet with a different XPC version.  Ignore.
188                  */
189                 xpc_received(partid, channel, (void *) msg);
190
191                 priv->stats.rx_errors++;
192
193                 return;
194         }
195         dev_dbg(xpnet, "received 0x%lx, %d, %d, %d\n", msg->buf_pa, msg->size,
196                 msg->leadin_ignore, msg->tailout_ignore);
197
198
199         /* reserve an extra cache line */
200         skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES);
201         if (!skb) {
202                 dev_err(xpnet, "failed on dev_alloc_skb(%d)\n",
203                         msg->size + L1_CACHE_BYTES);
204
205                 xpc_received(partid, channel, (void *) msg);
206
207                 priv->stats.rx_errors++;
208
209                 return;
210         }
211
212         /*
213          * The allocated skb has some reserved space.
214          * In order to use bte_copy, we need to get the
215          * skb->data pointer moved forward.
216          */
217         skb_reserve(skb, (L1_CACHE_BYTES - ((u64)skb->data &
218                                             (L1_CACHE_BYTES - 1)) +
219                           msg->leadin_ignore));
220
221         /*
222          * Update the tail pointer to indicate data actually
223          * transferred.
224          */
225         skb_put(skb, (msg->size - msg->leadin_ignore - msg->tailout_ignore));
226
227         /*
228          * Move the data over from the other side.
229          */
230         if ((XPNET_VERSION_MINOR(msg->version) == 1) &&
231                                                 (msg->embedded_bytes != 0)) {
232                 dev_dbg(xpnet, "copying embedded message. memcpy(0x%p, 0x%p, "
233                         "%lu)\n", skb->data, &msg->data,
234                         (size_t) msg->embedded_bytes);
235
236                 memcpy(skb->data, &msg->data, (size_t) msg->embedded_bytes);
237         } else {
238                 dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t"
239                         "bte_copy(0x%p, 0x%p, %hu)\n", (void *)msg->buf_pa,
240                         (void *)__pa((u64)skb->data & ~(L1_CACHE_BYTES - 1)),
241                         msg->size);
242
243                 bret = bte_copy(msg->buf_pa,
244                                 __pa((u64)skb->data & ~(L1_CACHE_BYTES - 1)),
245                                 msg->size, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
246
247                 if (bret != BTE_SUCCESS) {
248                         // >>> Need better way of cleaning skb.  Currently skb
249                         // >>> appears in_use and we can't just call
250                         // >>> dev_kfree_skb.
251                         dev_err(xpnet, "bte_copy(0x%p, 0x%p, 0x%hx) returned "
252                                 "error=0x%x\n", (void *)msg->buf_pa,
253                                 (void *)__pa((u64)skb->data &
254                                                         ~(L1_CACHE_BYTES - 1)),
255                                 msg->size, bret);
256
257                         xpc_received(partid, channel, (void *) msg);
258
259                         priv->stats.rx_errors++;
260
261                         return;
262                 }
263         }
264
265         dev_dbg(xpnet, "<skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
266                 "skb->end=0x%p skb->len=%d\n", (void *) skb->head,
267                 (void *) skb->data, (void *) skb->tail, (void *) skb->end,
268                 skb->len);
269
270         skb->dev = xpnet_device;
271         skb->protocol = eth_type_trans(skb, xpnet_device);
272         skb->ip_summed = CHECKSUM_UNNECESSARY;
273
274         dev_dbg(xpnet, "passing skb to network layer; \n\tskb->head=0x%p "
275                 "skb->data=0x%p skb->tail=0x%p skb->end=0x%p skb->len=%d\n",
276                 (void *) skb->head, (void *) skb->data, (void *) skb->tail,
277                 (void *) skb->end, skb->len);
278
279
280         xpnet_device->last_rx = jiffies;
281         priv->stats.rx_packets++;
282         priv->stats.rx_bytes += skb->len + ETH_HLEN;
283
284         netif_rx_ni(skb);
285         xpc_received(partid, channel, (void *) msg);
286 }
287
288
289 /*
290  * This is the handler which XPC calls during any sort of change in
291  * state or message reception on a connection.
292  */
293 static void
294 xpnet_connection_activity(enum xpc_retval reason, partid_t partid, int channel,
295                           void *data, void *key)
296 {
297         long bp;
298
299
300         DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
301         DBUG_ON(channel != XPC_NET_CHANNEL);
302
303         switch(reason) {
304         case xpcMsgReceived:    /* message received */
305                 DBUG_ON(data == NULL);
306
307                 xpnet_receive(partid, channel, (struct xpnet_message *) data);
308                 break;
309
310         case xpcConnected:      /* connection completed to a partition */
311                 spin_lock_bh(&xpnet_broadcast_lock);
312                 xpnet_broadcast_partitions |= 1UL << (partid -1 );
313                 bp = xpnet_broadcast_partitions;
314                 spin_unlock_bh(&xpnet_broadcast_lock);
315
316                 netif_carrier_on(xpnet_device);
317
318                 dev_dbg(xpnet, "%s connection created to partition %d; "
319                         "xpnet_broadcast_partitions=0x%lx\n",
320                         xpnet_device->name, partid, bp);
321                 break;
322
323         default:
324                 spin_lock_bh(&xpnet_broadcast_lock);
325                 xpnet_broadcast_partitions &= ~(1UL << (partid -1 ));
326                 bp = xpnet_broadcast_partitions;
327                 spin_unlock_bh(&xpnet_broadcast_lock);
328
329                 if (bp == 0) {
330                         netif_carrier_off(xpnet_device);
331                 }
332
333                 dev_dbg(xpnet, "%s disconnected from partition %d; "
334                         "xpnet_broadcast_partitions=0x%lx\n",
335                         xpnet_device->name, partid, bp);
336                 break;
337
338         }
339 }
340
341
342 static int
343 xpnet_dev_open(struct net_device *dev)
344 {
345         enum xpc_retval ret;
346
347
348         dev_dbg(xpnet, "calling xpc_connect(%d, 0x%p, NULL, %ld, %ld, %d, "
349                 "%d)\n", XPC_NET_CHANNEL, xpnet_connection_activity,
350                 XPNET_MSG_SIZE, XPNET_MSG_NENTRIES, XPNET_MAX_KTHREADS,
351                 XPNET_MAX_IDLE_KTHREADS);
352
353         ret = xpc_connect(XPC_NET_CHANNEL, xpnet_connection_activity, NULL,
354                           XPNET_MSG_SIZE, XPNET_MSG_NENTRIES,
355                           XPNET_MAX_KTHREADS, XPNET_MAX_IDLE_KTHREADS);
356         if (ret != xpcSuccess) {
357                 dev_err(xpnet, "ifconfig up of %s failed on XPC connect, "
358                         "ret=%d\n", dev->name, ret);
359
360                 return -ENOMEM;
361         }
362
363         dev_dbg(xpnet, "ifconfig up of %s; XPC connected\n", dev->name);
364
365         return 0;
366 }
367
368
369 static int
370 xpnet_dev_stop(struct net_device *dev)
371 {
372         xpc_disconnect(XPC_NET_CHANNEL);
373
374         dev_dbg(xpnet, "ifconfig down of %s; XPC disconnected\n", dev->name);
375
376         return 0;
377 }
378
379
380 static int
381 xpnet_dev_change_mtu(struct net_device *dev, int new_mtu)
382 {
383         /* 68 comes from min TCP+IP+MAC header */
384         if ((new_mtu < 68) || (new_mtu > XPNET_MAX_MTU)) {
385                 dev_err(xpnet, "ifconfig %s mtu %d failed; value must be "
386                         "between 68 and %ld\n", dev->name, new_mtu,
387                         XPNET_MAX_MTU);
388                 return -EINVAL;
389         }
390
391         dev->mtu = new_mtu;
392         dev_dbg(xpnet, "ifconfig %s mtu set to %d\n", dev->name, new_mtu);
393         return 0;
394 }
395
396
397 /*
398  * Required for the net_device structure.
399  */
400 static int
401 xpnet_dev_set_config(struct net_device *dev, struct ifmap *new_map)
402 {
403         return 0;
404 }
405
406
407 /*
408  * Return statistics to the caller.
409  */
410 static struct net_device_stats *
411 xpnet_dev_get_stats(struct net_device *dev)
412 {
413         struct xpnet_dev_private *priv;
414
415
416         priv = (struct xpnet_dev_private *) dev->priv;
417
418         return &priv->stats;
419 }
420
421
422 /*
423  * Notification that the other end has received the message and
424  * DMA'd the skb information.  At this point, they are done with
425  * our side.  When all recipients are done processing, we
426  * release the skb and then release our pending message structure.
427  */
428 static void
429 xpnet_send_completed(enum xpc_retval reason, partid_t partid, int channel,
430                         void *__qm)
431 {
432         struct xpnet_pending_msg *queued_msg =
433                 (struct xpnet_pending_msg *) __qm;
434
435
436         DBUG_ON(queued_msg == NULL);
437
438         dev_dbg(xpnet, "message to %d notified with reason %d\n",
439                 partid, reason);
440
441         if (atomic_dec_return(&queued_msg->use_count) == 0) {
442                 dev_dbg(xpnet, "all acks for skb->head=-x%p\n",
443                         (void *) queued_msg->skb->head);
444
445                 dev_kfree_skb_any(queued_msg->skb);
446                 kfree(queued_msg);
447         }
448 }
449
450
451 /*
452  * Network layer has formatted a packet (skb) and is ready to place it
453  * "on the wire".  Prepare and send an xpnet_message to all partitions
454  * which have connected with us and are targets of this packet.
455  *
456  * MAC-NOTE:  For the XPNET driver, the MAC address contains the
457  * destination partition_id.  If the destination partition id word
458  * is 0xff, this packet is to broadcast to all partitions.
459  */
460 static int
461 xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
462 {
463         struct xpnet_pending_msg *queued_msg;
464         enum xpc_retval ret;
465         struct xpnet_message *msg;
466         u64 start_addr, end_addr;
467         long dp;
468         u8 second_mac_octet;
469         partid_t dest_partid;
470         struct xpnet_dev_private *priv;
471         u16 embedded_bytes;
472
473
474         priv = (struct xpnet_dev_private *) dev->priv;
475
476
477         dev_dbg(xpnet, ">skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
478                 "skb->end=0x%p skb->len=%d\n", (void *) skb->head,
479                 (void *) skb->data, (void *) skb->tail, (void *) skb->end,
480                 skb->len);
481
482
483         /*
484          * The xpnet_pending_msg tracks how many outstanding
485          * xpc_send_notifies are relying on this skb.  When none
486          * remain, release the skb.
487          */
488         queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
489         if (queued_msg == NULL) {
490                 dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping "
491                         "packet\n", sizeof(struct xpnet_pending_msg));
492
493                 priv->stats.tx_errors++;
494
495                 return -ENOMEM;
496         }
497
498
499         /* get the beginning of the first cacheline and end of last */
500         start_addr = ((u64) skb->data & ~(L1_CACHE_BYTES - 1));
501         end_addr = L1_CACHE_ALIGN((u64) skb->tail);
502
503         /* calculate how many bytes to embed in the XPC message */
504         embedded_bytes = 0;
505         if (unlikely(skb->len <= XPNET_MSG_DATA_MAX)) {
506                 /* skb->data does fit so embed */
507                 embedded_bytes = skb->len;
508         }
509
510
511         /*
512          * Since the send occurs asynchronously, we set the count to one
513          * and begin sending.  Any sends that happen to complete before
514          * we are done sending will not free the skb.  We will be left
515          * with that task during exit.  This also handles the case of
516          * a packet destined for a partition which is no longer up.
517          */
518         atomic_set(&queued_msg->use_count, 1);
519         queued_msg->skb = skb;
520
521
522         second_mac_octet = skb->data[XPNET_PARTID_OCTET];
523         if (second_mac_octet == 0xff) {
524                 /* we are being asked to broadcast to all partitions */
525                 dp = xpnet_broadcast_partitions;
526         } else if (second_mac_octet != 0) {
527                 dp = xpnet_broadcast_partitions &
528                                         (1UL << (second_mac_octet - 1));
529         } else {
530                 /* 0 is an invalid partid.  Ignore */
531                 dp = 0;
532         }
533         dev_dbg(xpnet, "destination Partitions mask (dp) = 0x%lx\n", dp);
534
535         /*
536          * If we wanted to allow promiscous mode to work like an
537          * unswitched network, this would be a good point to OR in a
538          * mask of partitions which should be receiving all packets.
539          */
540
541         /*
542          * Main send loop.
543          */
544         for (dest_partid = 1; dp && dest_partid < XP_MAX_PARTITIONS;
545              dest_partid++) {
546
547
548                 if (!(dp & (1UL << (dest_partid - 1)))) {
549                         /* not destined for this partition */
550                         continue;
551                 }
552
553                 /* remove this partition from the destinations mask */
554                 dp &= ~(1UL << (dest_partid - 1));
555
556
557                 /* found a partition to send to */
558
559                 ret = xpc_allocate(dest_partid, XPC_NET_CHANNEL,
560                                    XPC_NOWAIT, (void **)&msg);
561                 if (unlikely(ret != xpcSuccess)) {
562                         continue;
563                 }
564
565                 msg->embedded_bytes = embedded_bytes;
566                 if (unlikely(embedded_bytes != 0)) {
567                         msg->version = XPNET_VERSION_EMBED;
568                         dev_dbg(xpnet, "calling memcpy(0x%p, 0x%p, 0x%lx)\n",
569                                 &msg->data, skb->data, (size_t) embedded_bytes);
570                         memcpy(&msg->data, skb->data, (size_t) embedded_bytes);
571                 } else {
572                         msg->version = XPNET_VERSION;
573                 }
574                 msg->magic = XPNET_MAGIC;
575                 msg->size = end_addr - start_addr;
576                 msg->leadin_ignore = (u64) skb->data - start_addr;
577                 msg->tailout_ignore = end_addr - (u64) skb->tail;
578                 msg->buf_pa = __pa(start_addr);
579
580                 dev_dbg(xpnet, "sending XPC message to %d:%d\nmsg->buf_pa="
581                         "0x%lx, msg->size=%u, msg->leadin_ignore=%u, "
582                         "msg->tailout_ignore=%u\n", dest_partid,
583                         XPC_NET_CHANNEL, msg->buf_pa, msg->size,
584                         msg->leadin_ignore, msg->tailout_ignore);
585
586
587                 atomic_inc(&queued_msg->use_count);
588
589                 ret = xpc_send_notify(dest_partid, XPC_NET_CHANNEL, msg,
590                                       xpnet_send_completed, queued_msg);
591                 if (unlikely(ret != xpcSuccess)) {
592                         atomic_dec(&queued_msg->use_count);
593                         continue;
594                 }
595
596         }
597
598         if (atomic_dec_return(&queued_msg->use_count) == 0) {
599                 dev_dbg(xpnet, "no partitions to receive packet destined for "
600                         "%d\n", dest_partid);
601
602
603                 dev_kfree_skb(skb);
604                 kfree(queued_msg);
605         }
606
607         priv->stats.tx_packets++;
608         priv->stats.tx_bytes += skb->len;
609
610         return 0;
611 }
612
613
614 /*
615  * Deal with transmit timeouts coming from the network layer.
616  */
617 static void
618 xpnet_dev_tx_timeout (struct net_device *dev)
619 {
620         struct xpnet_dev_private *priv;
621
622
623         priv = (struct xpnet_dev_private *) dev->priv;
624
625         priv->stats.tx_errors++;
626         return;
627 }
628
629
630 static int __init
631 xpnet_init(void)
632 {
633         int i;
634         u32 license_num;
635         int result = -ENOMEM;
636
637
638         if (!ia64_platform_is("sn2")) {
639                 return -ENODEV;
640         }
641
642         dev_info(xpnet, "registering network device %s\n", XPNET_DEVICE_NAME);
643
644         /*
645          * use ether_setup() to init the majority of our device
646          * structure and then override the necessary pieces.
647          */
648         xpnet_device = alloc_netdev(sizeof(struct xpnet_dev_private),
649                                     XPNET_DEVICE_NAME, ether_setup);
650         if (xpnet_device == NULL) {
651                 return -ENOMEM;
652         }
653
654         netif_carrier_off(xpnet_device);
655
656         xpnet_device->mtu = XPNET_DEF_MTU;
657         xpnet_device->change_mtu = xpnet_dev_change_mtu;
658         xpnet_device->open = xpnet_dev_open;
659         xpnet_device->get_stats = xpnet_dev_get_stats;
660         xpnet_device->stop = xpnet_dev_stop;
661         xpnet_device->hard_start_xmit = xpnet_dev_hard_start_xmit;
662         xpnet_device->tx_timeout = xpnet_dev_tx_timeout;
663         xpnet_device->set_config = xpnet_dev_set_config;
664
665         /*
666          * Multicast assumes the LSB of the first octet is set for multicast
667          * MAC addresses.  We chose the first octet of the MAC to be unlikely
668          * to collide with any vendor's officially issued MAC.
669          */
670         xpnet_device->dev_addr[0] = 0xfe;
671         xpnet_device->dev_addr[XPNET_PARTID_OCTET] = sn_partition_id;
672         license_num = sn_partition_serial_number_val();
673         for (i = 3; i >= 0; i--) {
674                 xpnet_device->dev_addr[XPNET_LICENSE_OCTET + i] =
675                                                         license_num & 0xff;
676                 license_num = license_num >> 8;
677         }
678
679         /*
680          * ether_setup() sets this to a multicast device.  We are
681          * really not supporting multicast at this time.
682          */
683         xpnet_device->flags &= ~IFF_MULTICAST;
684
685         /*
686          * No need to checksum as it is a DMA transfer.  The BTE will
687          * report an error if the data is not retrievable and the
688          * packet will be dropped.
689          */
690         xpnet_device->features = NETIF_F_NO_CSUM;
691
692         result = register_netdev(xpnet_device);
693         if (result != 0) {
694                 free_netdev(xpnet_device);
695         }
696
697         return result;
698 }
699 module_init(xpnet_init);
700
701
702 static void __exit
703 xpnet_exit(void)
704 {
705         dev_info(xpnet, "unregistering network device %s\n",
706                 xpnet_device[0].name);
707
708         unregister_netdev(xpnet_device);
709
710         free_netdev(xpnet_device);
711 }
712 module_exit(xpnet_exit);
713
714
715 MODULE_AUTHOR("Silicon Graphics, Inc.");
716 MODULE_DESCRIPTION("Cross Partition Network adapter (XPNET)");
717 MODULE_LICENSE("GPL");
718