fc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <asm/uaccess.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/mm.h>
  17. #include <linux/socket.h>
  18. #include <linux/in.h>
  19. #include <linux/inet.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/fcdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/errno.h>
  24. #include <linux/timer.h>
  25. #include <linux/net.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/init.h>
  28. #include <linux/export.h>
  29. #include <net/arp.h>
  30. /*
  31. * Put the headers on a Fibre Channel packet.
  32. */
  33. static int fc_header(struct sk_buff *skb, struct net_device *dev,
  34. unsigned short type,
  35. const void *daddr, const void *saddr, unsigned int len)
  36. {
  37. struct fch_hdr *fch;
  38. int hdr_len;
  39. /*
  40. * Add the 802.2 SNAP header if IP as the IPv4 code calls
  41. * dev->hard_header directly.
  42. */
  43. if (type == ETH_P_IP || type == ETH_P_ARP)
  44. {
  45. struct fcllc *fcllc;
  46. hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
  47. fch = (struct fch_hdr *)skb_push(skb, hdr_len);
  48. fcllc = (struct fcllc *)(fch+1);
  49. fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
  50. fcllc->llc = UI_CMD;
  51. fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
  52. fcllc->ethertype = htons(type);
  53. }
  54. else
  55. {
  56. hdr_len = sizeof(struct fch_hdr);
  57. fch = (struct fch_hdr *)skb_push(skb, hdr_len);
  58. }
  59. if(saddr)
  60. memcpy(fch->saddr,saddr,dev->addr_len);
  61. else
  62. memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
  63. if(daddr)
  64. {
  65. memcpy(fch->daddr,daddr,dev->addr_len);
  66. return hdr_len;
  67. }
  68. return -hdr_len;
  69. }
  70. static const struct header_ops fc_header_ops = {
  71. .create = fc_header,
  72. };
  73. static void fc_setup(struct net_device *dev)
  74. {
  75. dev->header_ops = &fc_header_ops;
  76. dev->type = ARPHRD_IEEE802;
  77. dev->hard_header_len = FC_HLEN;
  78. dev->mtu = 2024;
  79. dev->addr_len = FC_ALEN;
  80. dev->tx_queue_len = 100; /* Long queues on fc */
  81. dev->flags = IFF_BROADCAST;
  82. memset(dev->broadcast, 0xFF, FC_ALEN);
  83. }
  84. /**
  85. * alloc_fcdev - Register fibre channel device
  86. * @sizeof_priv: Size of additional driver-private structure to be allocated
  87. * for this fibre channel device
  88. *
  89. * Fill in the fields of the device structure with fibre channel-generic values.
  90. *
  91. * Constructs a new net device, complete with a private data area of
  92. * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
  93. * this private data area.
  94. */
  95. struct net_device *alloc_fcdev(int sizeof_priv)
  96. {
  97. return alloc_netdev(sizeof_priv, "fc%d", NET_NAME_UNKNOWN, fc_setup);
  98. }
  99. EXPORT_SYMBOL(alloc_fcdev);