cxgb4_fcoe.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2015 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifdef CONFIG_CHELSIO_T4_FCOE
  35. #include <scsi/fc/fc_fs.h>
  36. #include <scsi/libfcoe.h>
  37. #include "cxgb4.h"
  38. bool cxgb_fcoe_sof_eof_supported(struct adapter *adap, struct sk_buff *skb)
  39. {
  40. struct fcoe_hdr *fcoeh = (struct fcoe_hdr *)skb_network_header(skb);
  41. u8 sof = fcoeh->fcoe_sof;
  42. u8 eof = 0;
  43. if ((sof != FC_SOF_I3) && (sof != FC_SOF_N3)) {
  44. dev_err(adap->pdev_dev, "Unsupported SOF 0x%x\n", sof);
  45. return false;
  46. }
  47. skb_copy_bits(skb, skb->len - 4, &eof, 1);
  48. if ((eof != FC_EOF_N) && (eof != FC_EOF_T)) {
  49. dev_err(adap->pdev_dev, "Unsupported EOF 0x%x\n", eof);
  50. return false;
  51. }
  52. return true;
  53. }
  54. /**
  55. * cxgb_fcoe_enable - enable FCoE offload features
  56. * @netdev: net device
  57. *
  58. * Returns 0 on success or -EINVAL on failure.
  59. */
  60. int cxgb_fcoe_enable(struct net_device *netdev)
  61. {
  62. struct port_info *pi = netdev_priv(netdev);
  63. struct adapter *adap = pi->adapter;
  64. struct cxgb_fcoe *fcoe = &pi->fcoe;
  65. if (is_t4(adap->params.chip))
  66. return -EINVAL;
  67. if (!(adap->flags & FULL_INIT_DONE))
  68. return -EINVAL;
  69. dev_info(adap->pdev_dev, "Enabling FCoE offload features\n");
  70. netdev->features |= NETIF_F_FCOE_CRC;
  71. netdev->vlan_features |= NETIF_F_FCOE_CRC;
  72. netdev->features |= NETIF_F_FCOE_MTU;
  73. netdev->vlan_features |= NETIF_F_FCOE_MTU;
  74. netdev_features_change(netdev);
  75. fcoe->flags |= CXGB_FCOE_ENABLED;
  76. return 0;
  77. }
  78. /**
  79. * cxgb_fcoe_disable - disable FCoE offload
  80. * @netdev: net device
  81. *
  82. * Returns 0 on success or -EINVAL on failure.
  83. */
  84. int cxgb_fcoe_disable(struct net_device *netdev)
  85. {
  86. struct port_info *pi = netdev_priv(netdev);
  87. struct adapter *adap = pi->adapter;
  88. struct cxgb_fcoe *fcoe = &pi->fcoe;
  89. if (!(fcoe->flags & CXGB_FCOE_ENABLED))
  90. return -EINVAL;
  91. dev_info(adap->pdev_dev, "Disabling FCoE offload features\n");
  92. fcoe->flags &= ~CXGB_FCOE_ENABLED;
  93. netdev->features &= ~NETIF_F_FCOE_CRC;
  94. netdev->vlan_features &= ~NETIF_F_FCOE_CRC;
  95. netdev->features &= ~NETIF_F_FCOE_MTU;
  96. netdev->vlan_features &= ~NETIF_F_FCOE_MTU;
  97. netdev_features_change(netdev);
  98. return 0;
  99. }
  100. #endif /* CONFIG_CHELSIO_T4_FCOE */