fc.c 2.5 KB

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