fc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * NET3: Fibre Channel device handling subroutines
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Vineet Abraham <vma@iol.unh.edu>
  10. * v 1.0 03/22/99
  11. */
  12. #include <linux/config.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/system.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/string.h>
  19. #include <linux/mm.h>
  20. #include <linux/socket.h>
  21. #include <linux/in.h>
  22. #include <linux/inet.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/fcdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/errno.h>
  27. #include <linux/timer.h>
  28. #include <linux/net.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/init.h>
  31. #include <net/arp.h>
  32. /*
  33. * Put the headers on a Fibre Channel packet.
  34. */
  35. static int fc_header(struct sk_buff *skb, struct net_device *dev,
  36. unsigned short type,
  37. void *daddr, void *saddr, unsigned len)
  38. {
  39. struct fch_hdr *fch;
  40. int hdr_len;
  41. /*
  42. * Add the 802.2 SNAP header if IP as the IPv4 code calls
  43. * dev->hard_header directly.
  44. */
  45. if (type == ETH_P_IP || type == ETH_P_ARP)
  46. {
  47. struct fcllc *fcllc;
  48. hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
  49. fch = (struct fch_hdr *)skb_push(skb, hdr_len);
  50. fcllc = (struct fcllc *)(fch+1);
  51. fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
  52. fcllc->llc = UI_CMD;
  53. fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
  54. fcllc->ethertype = htons(type);
  55. }
  56. else
  57. {
  58. hdr_len = sizeof(struct fch_hdr);
  59. fch = (struct fch_hdr *)skb_push(skb, hdr_len);
  60. }
  61. if(saddr)
  62. memcpy(fch->saddr,saddr,dev->addr_len);
  63. else
  64. memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
  65. if(daddr)
  66. {
  67. memcpy(fch->daddr,daddr,dev->addr_len);
  68. return(hdr_len);
  69. }
  70. return -hdr_len;
  71. }
  72. /*
  73. * A neighbour discovery of some species (eg arp) has completed. We
  74. * can now send the packet.
  75. */
  76. static int fc_rebuild_header(struct sk_buff *skb)
  77. {
  78. struct fch_hdr *fch=(struct fch_hdr *)skb->data;
  79. struct fcllc *fcllc=(struct fcllc *)(skb->data+sizeof(struct fch_hdr));
  80. if(fcllc->ethertype != htons(ETH_P_IP)) {
  81. printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n", ntohs(fcllc->ethertype));
  82. return 0;
  83. }
  84. #ifdef CONFIG_INET
  85. return arp_find(fch->daddr, skb);
  86. #else
  87. return 0;
  88. #endif
  89. }
  90. static void fc_setup(struct net_device *dev)
  91. {
  92. dev->hard_header = fc_header;
  93. dev->rebuild_header = fc_rebuild_header;
  94. dev->type = ARPHRD_IEEE802;
  95. dev->hard_header_len = FC_HLEN;
  96. dev->mtu = 2024;
  97. dev->addr_len = FC_ALEN;
  98. dev->tx_queue_len = 100; /* Long queues on fc */
  99. dev->flags = IFF_BROADCAST;
  100. memset(dev->broadcast, 0xFF, FC_ALEN);
  101. }
  102. /**
  103. * alloc_fcdev - Register fibre channel device
  104. * @sizeof_priv: Size of additional driver-private structure to be allocated
  105. * for this fibre channel device
  106. *
  107. * Fill in the fields of the device structure with fibre channel-generic values.
  108. *
  109. * Constructs a new net device, complete with a private data area of
  110. * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
  111. * this private data area.
  112. */
  113. struct net_device *alloc_fcdev(int sizeof_priv)
  114. {
  115. return alloc_netdev(sizeof_priv, "fc%d", fc_setup);
  116. }
  117. EXPORT_SYMBOL(alloc_fcdev);