xpnet.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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-2008 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. /*
  9. * Cross Partition Network Interface (XPNET) support
  10. *
  11. * XPNET provides a virtual network layered on top of the Cross
  12. * Partition communication layer.
  13. *
  14. * XPNET provides direct point-to-point and broadcast-like support
  15. * for an ethernet-like device. The ethernet broadcast medium is
  16. * replaced with a point-to-point message structure which passes
  17. * pointers to a DMA-capable block that a remote partition should
  18. * retrieve and pass to the upper level networking layer.
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/ioport.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/delay.h>
  28. #include <linux/ethtool.h>
  29. #include <linux/mii.h>
  30. #include <linux/smp.h>
  31. #include <linux/string.h>
  32. #include <asm/atomic.h>
  33. #include "xp.h"
  34. /*
  35. * The message payload transferred by XPC.
  36. *
  37. * buf_pa is the physical address where the DMA should pull from.
  38. *
  39. * NOTE: for performance reasons, buf_pa should _ALWAYS_ begin on a
  40. * cacheline boundary. To accomplish this, we record the number of
  41. * bytes from the beginning of the first cacheline to the first useful
  42. * byte of the skb (leadin_ignore) and the number of bytes from the
  43. * last useful byte of the skb to the end of the last cacheline
  44. * (tailout_ignore).
  45. *
  46. * size is the number of bytes to transfer which includes the skb->len
  47. * (useful bytes of the senders skb) plus the leadin and tailout
  48. */
  49. struct xpnet_message {
  50. u16 version; /* Version for this message */
  51. u16 embedded_bytes; /* #of bytes embedded in XPC message */
  52. u32 magic; /* Special number indicating this is xpnet */
  53. u64 buf_pa; /* phys address of buffer to retrieve */
  54. u32 size; /* #of bytes in buffer */
  55. u8 leadin_ignore; /* #of bytes to ignore at the beginning */
  56. u8 tailout_ignore; /* #of bytes to ignore at the end */
  57. unsigned char data; /* body of small packets */
  58. };
  59. /*
  60. * Determine the size of our message, the cacheline aligned size,
  61. * and then the number of message will request from XPC.
  62. *
  63. * XPC expects each message to exist in an individual cacheline.
  64. */
  65. #define XPNET_MSG_SIZE (L1_CACHE_BYTES - XPC_MSG_PAYLOAD_OFFSET)
  66. #define XPNET_MSG_DATA_MAX \
  67. (XPNET_MSG_SIZE - (u64)(&((struct xpnet_message *)0)->data))
  68. #define XPNET_MSG_ALIGNED_SIZE (L1_CACHE_ALIGN(XPNET_MSG_SIZE))
  69. #define XPNET_MSG_NENTRIES (PAGE_SIZE / XPNET_MSG_ALIGNED_SIZE)
  70. #define XPNET_MAX_KTHREADS (XPNET_MSG_NENTRIES + 1)
  71. #define XPNET_MAX_IDLE_KTHREADS (XPNET_MSG_NENTRIES + 1)
  72. /*
  73. * Version number of XPNET implementation. XPNET can always talk to versions
  74. * with same major #, and never talk to versions with a different version.
  75. */
  76. #define _XPNET_VERSION(_major, _minor) (((_major) << 4) | (_minor))
  77. #define XPNET_VERSION_MAJOR(_v) ((_v) >> 4)
  78. #define XPNET_VERSION_MINOR(_v) ((_v) & 0xf)
  79. #define XPNET_VERSION _XPNET_VERSION(1, 0) /* version 1.0 */
  80. #define XPNET_VERSION_EMBED _XPNET_VERSION(1, 1) /* version 1.1 */
  81. #define XPNET_MAGIC 0x88786984 /* "XNET" */
  82. #define XPNET_VALID_MSG(_m) \
  83. ((XPNET_VERSION_MAJOR(_m->version) == XPNET_VERSION_MAJOR(XPNET_VERSION)) \
  84. && (msg->magic == XPNET_MAGIC))
  85. #define XPNET_DEVICE_NAME "xp0"
  86. /*
  87. * When messages are queued with xpc_send_notify, a kmalloc'd buffer
  88. * of the following type is passed as a notification cookie. When the
  89. * notification function is called, we use the cookie to decide
  90. * whether all outstanding message sends have completed. The skb can
  91. * then be released.
  92. */
  93. struct xpnet_pending_msg {
  94. struct sk_buff *skb;
  95. atomic_t use_count;
  96. };
  97. /* driver specific structure pointed to by the device structure */
  98. struct xpnet_dev_private {
  99. struct net_device_stats stats;
  100. };
  101. struct net_device *xpnet_device;
  102. /*
  103. * When we are notified of other partitions activating, we add them to
  104. * our bitmask of partitions to which we broadcast.
  105. */
  106. static unsigned long *xpnet_broadcast_partitions;
  107. /* protect above */
  108. static DEFINE_SPINLOCK(xpnet_broadcast_lock);
  109. /*
  110. * Since the Block Transfer Engine (BTE) is being used for the transfer
  111. * and it relies upon cache-line size transfers, we need to reserve at
  112. * least one cache-line for head and tail alignment. The BTE is
  113. * limited to 8MB transfers.
  114. *
  115. * Testing has shown that changing MTU to greater than 64KB has no effect
  116. * on TCP as the two sides negotiate a Max Segment Size that is limited
  117. * to 64K. Other protocols May use packets greater than this, but for
  118. * now, the default is 64KB.
  119. */
  120. #define XPNET_MAX_MTU (0x800000UL - L1_CACHE_BYTES)
  121. /* 32KB has been determined to be the ideal */
  122. #define XPNET_DEF_MTU (0x8000UL)
  123. /*
  124. * The partid is encapsulated in the MAC address beginning in the following
  125. * octet and it consists of two octets.
  126. */
  127. #define XPNET_PARTID_OCTET 2
  128. /* Define the XPNET debug device structures to be used with dev_dbg() et al */
  129. struct device_driver xpnet_dbg_name = {
  130. .name = "xpnet"
  131. };
  132. struct device xpnet_dbg_subname = {
  133. .bus_id = {0}, /* set to "" */
  134. .driver = &xpnet_dbg_name
  135. };
  136. struct device *xpnet = &xpnet_dbg_subname;
  137. /*
  138. * Packet was recevied by XPC and forwarded to us.
  139. */
  140. static void
  141. xpnet_receive(short partid, int channel, struct xpnet_message *msg)
  142. {
  143. struct sk_buff *skb;
  144. enum xp_retval ret;
  145. struct xpnet_dev_private *priv =
  146. (struct xpnet_dev_private *)xpnet_device->priv;
  147. if (!XPNET_VALID_MSG(msg)) {
  148. /*
  149. * Packet with a different XPC version. Ignore.
  150. */
  151. xpc_received(partid, channel, (void *)msg);
  152. priv->stats.rx_errors++;
  153. return;
  154. }
  155. dev_dbg(xpnet, "received 0x%lx, %d, %d, %d\n", msg->buf_pa, msg->size,
  156. msg->leadin_ignore, msg->tailout_ignore);
  157. /* reserve an extra cache line */
  158. skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES);
  159. if (!skb) {
  160. dev_err(xpnet, "failed on dev_alloc_skb(%d)\n",
  161. msg->size + L1_CACHE_BYTES);
  162. xpc_received(partid, channel, (void *)msg);
  163. priv->stats.rx_errors++;
  164. return;
  165. }
  166. /*
  167. * The allocated skb has some reserved space.
  168. * In order to use xp_remote_memcpy(), we need to get the
  169. * skb->data pointer moved forward.
  170. */
  171. skb_reserve(skb, (L1_CACHE_BYTES - ((u64)skb->data &
  172. (L1_CACHE_BYTES - 1)) +
  173. msg->leadin_ignore));
  174. /*
  175. * Update the tail pointer to indicate data actually
  176. * transferred.
  177. */
  178. skb_put(skb, (msg->size - msg->leadin_ignore - msg->tailout_ignore));
  179. /*
  180. * Move the data over from the other side.
  181. */
  182. if ((XPNET_VERSION_MINOR(msg->version) == 1) &&
  183. (msg->embedded_bytes != 0)) {
  184. dev_dbg(xpnet, "copying embedded message. memcpy(0x%p, 0x%p, "
  185. "%lu)\n", skb->data, &msg->data,
  186. (size_t)msg->embedded_bytes);
  187. skb_copy_to_linear_data(skb, &msg->data,
  188. (size_t)msg->embedded_bytes);
  189. } else {
  190. dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t"
  191. "xp_remote_memcpy(0x%p, 0x%p, %hu)\n", (void *)
  192. ((u64)skb->data & ~(L1_CACHE_BYTES - 1)),
  193. (void *)msg->buf_pa, msg->size);
  194. ret = xp_remote_memcpy((void *)((u64)skb->data &
  195. ~(L1_CACHE_BYTES - 1)),
  196. (void *)msg->buf_pa, msg->size);
  197. if (ret != xpSuccess) {
  198. /*
  199. * >>> Need better way of cleaning skb. Currently skb
  200. * >>> appears in_use and we can't just call
  201. * >>> dev_kfree_skb.
  202. */
  203. dev_err(xpnet, "xp_remote_memcpy(0x%p, 0x%p, 0x%hx) "
  204. "returned error=0x%x\n", (void *)
  205. ((u64)skb->data & ~(L1_CACHE_BYTES - 1)),
  206. (void *)msg->buf_pa, msg->size, ret);
  207. xpc_received(partid, channel, (void *)msg);
  208. priv->stats.rx_errors++;
  209. return;
  210. }
  211. }
  212. dev_dbg(xpnet, "<skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
  213. "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
  214. (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
  215. skb->len);
  216. skb->protocol = eth_type_trans(skb, xpnet_device);
  217. skb->ip_summed = CHECKSUM_UNNECESSARY;
  218. dev_dbg(xpnet, "passing skb to network layer\n"
  219. KERN_DEBUG "\tskb->head=0x%p skb->data=0x%p skb->tail=0x%p "
  220. "skb->end=0x%p skb->len=%d\n",
  221. (void *)skb->head, (void *)skb->data, skb_tail_pointer(skb),
  222. skb_end_pointer(skb), skb->len);
  223. xpnet_device->last_rx = jiffies;
  224. priv->stats.rx_packets++;
  225. priv->stats.rx_bytes += skb->len + ETH_HLEN;
  226. netif_rx_ni(skb);
  227. xpc_received(partid, channel, (void *)msg);
  228. }
  229. /*
  230. * This is the handler which XPC calls during any sort of change in
  231. * state or message reception on a connection.
  232. */
  233. static void
  234. xpnet_connection_activity(enum xp_retval reason, short partid, int channel,
  235. void *data, void *key)
  236. {
  237. DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
  238. DBUG_ON(channel != XPC_NET_CHANNEL);
  239. switch (reason) {
  240. case xpMsgReceived: /* message received */
  241. DBUG_ON(data == NULL);
  242. xpnet_receive(partid, channel, (struct xpnet_message *)data);
  243. break;
  244. case xpConnected: /* connection completed to a partition */
  245. spin_lock_bh(&xpnet_broadcast_lock);
  246. __set_bit(partid, xpnet_broadcast_partitions);
  247. spin_unlock_bh(&xpnet_broadcast_lock);
  248. netif_carrier_on(xpnet_device);
  249. dev_dbg(xpnet, "%s connected to partition %d\n",
  250. xpnet_device->name, partid);
  251. break;
  252. default:
  253. spin_lock_bh(&xpnet_broadcast_lock);
  254. __clear_bit(partid, xpnet_broadcast_partitions);
  255. spin_unlock_bh(&xpnet_broadcast_lock);
  256. if (bitmap_empty((unsigned long *)xpnet_broadcast_partitions,
  257. xp_max_npartitions)) {
  258. netif_carrier_off(xpnet_device);
  259. }
  260. dev_dbg(xpnet, "%s disconnected from partition %d\n",
  261. xpnet_device->name, partid);
  262. break;
  263. }
  264. }
  265. static int
  266. xpnet_dev_open(struct net_device *dev)
  267. {
  268. enum xp_retval ret;
  269. dev_dbg(xpnet, "calling xpc_connect(%d, 0x%p, NULL, %ld, %ld, %ld, "
  270. "%ld)\n", XPC_NET_CHANNEL, xpnet_connection_activity,
  271. XPNET_MSG_SIZE, XPNET_MSG_NENTRIES, XPNET_MAX_KTHREADS,
  272. XPNET_MAX_IDLE_KTHREADS);
  273. ret = xpc_connect(XPC_NET_CHANNEL, xpnet_connection_activity, NULL,
  274. XPNET_MSG_SIZE, XPNET_MSG_NENTRIES,
  275. XPNET_MAX_KTHREADS, XPNET_MAX_IDLE_KTHREADS);
  276. if (ret != xpSuccess) {
  277. dev_err(xpnet, "ifconfig up of %s failed on XPC connect, "
  278. "ret=%d\n", dev->name, ret);
  279. return -ENOMEM;
  280. }
  281. dev_dbg(xpnet, "ifconfig up of %s; XPC connected\n", dev->name);
  282. return 0;
  283. }
  284. static int
  285. xpnet_dev_stop(struct net_device *dev)
  286. {
  287. xpc_disconnect(XPC_NET_CHANNEL);
  288. dev_dbg(xpnet, "ifconfig down of %s; XPC disconnected\n", dev->name);
  289. return 0;
  290. }
  291. static int
  292. xpnet_dev_change_mtu(struct net_device *dev, int new_mtu)
  293. {
  294. /* 68 comes from min TCP+IP+MAC header */
  295. if ((new_mtu < 68) || (new_mtu > XPNET_MAX_MTU)) {
  296. dev_err(xpnet, "ifconfig %s mtu %d failed; value must be "
  297. "between 68 and %ld\n", dev->name, new_mtu,
  298. XPNET_MAX_MTU);
  299. return -EINVAL;
  300. }
  301. dev->mtu = new_mtu;
  302. dev_dbg(xpnet, "ifconfig %s mtu set to %d\n", dev->name, new_mtu);
  303. return 0;
  304. }
  305. /*
  306. * Required for the net_device structure.
  307. */
  308. static int
  309. xpnet_dev_set_config(struct net_device *dev, struct ifmap *new_map)
  310. {
  311. return 0;
  312. }
  313. /*
  314. * Return statistics to the caller.
  315. */
  316. static struct net_device_stats *
  317. xpnet_dev_get_stats(struct net_device *dev)
  318. {
  319. struct xpnet_dev_private *priv;
  320. priv = (struct xpnet_dev_private *)dev->priv;
  321. return &priv->stats;
  322. }
  323. /*
  324. * Notification that the other end has received the message and
  325. * DMA'd the skb information. At this point, they are done with
  326. * our side. When all recipients are done processing, we
  327. * release the skb and then release our pending message structure.
  328. */
  329. static void
  330. xpnet_send_completed(enum xp_retval reason, short partid, int channel,
  331. void *__qm)
  332. {
  333. struct xpnet_pending_msg *queued_msg = (struct xpnet_pending_msg *)__qm;
  334. DBUG_ON(queued_msg == NULL);
  335. dev_dbg(xpnet, "message to %d notified with reason %d\n",
  336. partid, reason);
  337. if (atomic_dec_return(&queued_msg->use_count) == 0) {
  338. dev_dbg(xpnet, "all acks for skb->head=-x%p\n",
  339. (void *)queued_msg->skb->head);
  340. dev_kfree_skb_any(queued_msg->skb);
  341. kfree(queued_msg);
  342. }
  343. }
  344. static void
  345. xpnet_send(struct sk_buff *skb, struct xpnet_pending_msg *queued_msg,
  346. u64 start_addr, u64 end_addr, u16 embedded_bytes, int dest_partid)
  347. {
  348. u8 msg_buffer[XPNET_MSG_SIZE];
  349. struct xpnet_message *msg = (struct xpnet_message *)&msg_buffer;
  350. enum xp_retval ret;
  351. msg->embedded_bytes = embedded_bytes;
  352. if (unlikely(embedded_bytes != 0)) {
  353. msg->version = XPNET_VERSION_EMBED;
  354. dev_dbg(xpnet, "calling memcpy(0x%p, 0x%p, 0x%lx)\n",
  355. &msg->data, skb->data, (size_t)embedded_bytes);
  356. skb_copy_from_linear_data(skb, &msg->data,
  357. (size_t)embedded_bytes);
  358. } else {
  359. msg->version = XPNET_VERSION;
  360. }
  361. msg->magic = XPNET_MAGIC;
  362. msg->size = end_addr - start_addr;
  363. msg->leadin_ignore = (u64)skb->data - start_addr;
  364. msg->tailout_ignore = end_addr - (u64)skb_tail_pointer(skb);
  365. msg->buf_pa = __pa(start_addr);
  366. dev_dbg(xpnet, "sending XPC message to %d:%d\n"
  367. KERN_DEBUG "msg->buf_pa=0x%lx, msg->size=%u, "
  368. "msg->leadin_ignore=%u, msg->tailout_ignore=%u\n",
  369. dest_partid, XPC_NET_CHANNEL, msg->buf_pa, msg->size,
  370. msg->leadin_ignore, msg->tailout_ignore);
  371. atomic_inc(&queued_msg->use_count);
  372. ret = xpc_send_notify(dest_partid, XPC_NET_CHANNEL, XPC_NOWAIT, msg,
  373. XPNET_MSG_SIZE, xpnet_send_completed, queued_msg);
  374. if (unlikely(ret != xpSuccess))
  375. atomic_dec(&queued_msg->use_count);
  376. }
  377. /*
  378. * Network layer has formatted a packet (skb) and is ready to place it
  379. * "on the wire". Prepare and send an xpnet_message to all partitions
  380. * which have connected with us and are targets of this packet.
  381. *
  382. * MAC-NOTE: For the XPNET driver, the MAC address contains the
  383. * destination partid. If the destination partid octets are 0xffff,
  384. * this packet is to be broadcast to all connected partitions.
  385. */
  386. static int
  387. xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  388. {
  389. struct xpnet_pending_msg *queued_msg;
  390. u64 start_addr, end_addr;
  391. short dest_partid;
  392. struct xpnet_dev_private *priv = (struct xpnet_dev_private *)dev->priv;
  393. u16 embedded_bytes = 0;
  394. dev_dbg(xpnet, ">skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
  395. "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
  396. (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
  397. skb->len);
  398. if (skb->data[0] == 0x33) {
  399. dev_kfree_skb(skb);
  400. return 0; /* nothing needed to be done */
  401. }
  402. /*
  403. * The xpnet_pending_msg tracks how many outstanding
  404. * xpc_send_notifies are relying on this skb. When none
  405. * remain, release the skb.
  406. */
  407. queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
  408. if (queued_msg == NULL) {
  409. dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping "
  410. "packet\n", sizeof(struct xpnet_pending_msg));
  411. priv->stats.tx_errors++;
  412. return -ENOMEM;
  413. }
  414. /* get the beginning of the first cacheline and end of last */
  415. start_addr = ((u64)skb->data & ~(L1_CACHE_BYTES - 1));
  416. end_addr = L1_CACHE_ALIGN((u64)skb_tail_pointer(skb));
  417. /* calculate how many bytes to embed in the XPC message */
  418. if (unlikely(skb->len <= XPNET_MSG_DATA_MAX)) {
  419. /* skb->data does fit so embed */
  420. embedded_bytes = skb->len;
  421. }
  422. /*
  423. * Since the send occurs asynchronously, we set the count to one
  424. * and begin sending. Any sends that happen to complete before
  425. * we are done sending will not free the skb. We will be left
  426. * with that task during exit. This also handles the case of
  427. * a packet destined for a partition which is no longer up.
  428. */
  429. atomic_set(&queued_msg->use_count, 1);
  430. queued_msg->skb = skb;
  431. if (skb->data[0] == 0xff) {
  432. /* we are being asked to broadcast to all partitions */
  433. for_each_bit(dest_partid, xpnet_broadcast_partitions,
  434. xp_max_npartitions) {
  435. xpnet_send(skb, queued_msg, start_addr, end_addr,
  436. embedded_bytes, dest_partid);
  437. }
  438. } else {
  439. dest_partid = (short)skb->data[XPNET_PARTID_OCTET + 1];
  440. dest_partid |= (short)skb->data[XPNET_PARTID_OCTET + 0] << 8;
  441. if (dest_partid >= 0 &&
  442. dest_partid < xp_max_npartitions &&
  443. test_bit(dest_partid, xpnet_broadcast_partitions) != 0) {
  444. xpnet_send(skb, queued_msg, start_addr, end_addr,
  445. embedded_bytes, dest_partid);
  446. }
  447. }
  448. if (atomic_dec_return(&queued_msg->use_count) == 0) {
  449. dev_kfree_skb(skb);
  450. kfree(queued_msg);
  451. }
  452. priv->stats.tx_packets++;
  453. priv->stats.tx_bytes += skb->len;
  454. return 0;
  455. }
  456. /*
  457. * Deal with transmit timeouts coming from the network layer.
  458. */
  459. static void
  460. xpnet_dev_tx_timeout(struct net_device *dev)
  461. {
  462. struct xpnet_dev_private *priv;
  463. priv = (struct xpnet_dev_private *)dev->priv;
  464. priv->stats.tx_errors++;
  465. return;
  466. }
  467. static int __init
  468. xpnet_init(void)
  469. {
  470. int result;
  471. if (!is_shub() && !is_uv())
  472. return -ENODEV;
  473. dev_info(xpnet, "registering network device %s\n", XPNET_DEVICE_NAME);
  474. xpnet_broadcast_partitions = kzalloc(BITS_TO_LONGS(xp_max_npartitions) *
  475. sizeof(long), GFP_KERNEL);
  476. if (xpnet_broadcast_partitions == NULL)
  477. return -ENOMEM;
  478. /*
  479. * use ether_setup() to init the majority of our device
  480. * structure and then override the necessary pieces.
  481. */
  482. xpnet_device = alloc_netdev(sizeof(struct xpnet_dev_private),
  483. XPNET_DEVICE_NAME, ether_setup);
  484. if (xpnet_device == NULL) {
  485. kfree(xpnet_broadcast_partitions);
  486. return -ENOMEM;
  487. }
  488. netif_carrier_off(xpnet_device);
  489. xpnet_device->mtu = XPNET_DEF_MTU;
  490. xpnet_device->change_mtu = xpnet_dev_change_mtu;
  491. xpnet_device->open = xpnet_dev_open;
  492. xpnet_device->get_stats = xpnet_dev_get_stats;
  493. xpnet_device->stop = xpnet_dev_stop;
  494. xpnet_device->hard_start_xmit = xpnet_dev_hard_start_xmit;
  495. xpnet_device->tx_timeout = xpnet_dev_tx_timeout;
  496. xpnet_device->set_config = xpnet_dev_set_config;
  497. /*
  498. * Multicast assumes the LSB of the first octet is set for multicast
  499. * MAC addresses. We chose the first octet of the MAC to be unlikely
  500. * to collide with any vendor's officially issued MAC.
  501. */
  502. xpnet_device->dev_addr[0] = 0x02; /* locally administered, no OUI */
  503. xpnet_device->dev_addr[XPNET_PARTID_OCTET + 1] = sn_partition_id;
  504. xpnet_device->dev_addr[XPNET_PARTID_OCTET + 0] = (sn_partition_id >> 8);
  505. /*
  506. * ether_setup() sets this to a multicast device. We are
  507. * really not supporting multicast at this time.
  508. */
  509. xpnet_device->flags &= ~IFF_MULTICAST;
  510. /*
  511. * No need to checksum as it is a DMA transfer. The BTE will
  512. * report an error if the data is not retrievable and the
  513. * packet will be dropped.
  514. */
  515. xpnet_device->features = NETIF_F_NO_CSUM;
  516. result = register_netdev(xpnet_device);
  517. if (result != 0) {
  518. free_netdev(xpnet_device);
  519. kfree(xpnet_broadcast_partitions);
  520. }
  521. return result;
  522. }
  523. module_init(xpnet_init);
  524. static void __exit
  525. xpnet_exit(void)
  526. {
  527. dev_info(xpnet, "unregistering network device %s\n",
  528. xpnet_device[0].name);
  529. unregister_netdev(xpnet_device);
  530. free_netdev(xpnet_device);
  531. kfree(xpnet_broadcast_partitions);
  532. }
  533. module_exit(xpnet_exit);
  534. MODULE_AUTHOR("Silicon Graphics, Inc.");
  535. MODULE_DESCRIPTION("Cross Partition Network adapter (XPNET)");
  536. MODULE_LICENSE("GPL");