184a200b3SVarun Prakash /*
284a200b3SVarun Prakash * This file is part of the Chelsio T4 Ethernet driver for Linux.
384a200b3SVarun Prakash *
484a200b3SVarun Prakash * Copyright (c) 2015 Chelsio Communications, Inc. All rights reserved.
584a200b3SVarun Prakash *
684a200b3SVarun Prakash * This software is available to you under a choice of one of two
784a200b3SVarun Prakash * licenses. You may choose to be licensed under the terms of the GNU
884a200b3SVarun Prakash * General Public License (GPL) Version 2, available from the file
984a200b3SVarun Prakash * COPYING in the main directory of this source tree, or the
1084a200b3SVarun Prakash * OpenIB.org BSD license below:
1184a200b3SVarun Prakash *
1284a200b3SVarun Prakash * Redistribution and use in source and binary forms, with or
1384a200b3SVarun Prakash * without modification, are permitted provided that the following
1484a200b3SVarun Prakash * conditions are met:
1584a200b3SVarun Prakash *
1684a200b3SVarun Prakash * - Redistributions of source code must retain the above
1784a200b3SVarun Prakash * copyright notice, this list of conditions and the following
1884a200b3SVarun Prakash * disclaimer.
1984a200b3SVarun Prakash *
2084a200b3SVarun Prakash * - Redistributions in binary form must reproduce the above
2184a200b3SVarun Prakash * copyright notice, this list of conditions and the following
2284a200b3SVarun Prakash * disclaimer in the documentation and/or other materials
2384a200b3SVarun Prakash * provided with the distribution.
2484a200b3SVarun Prakash *
2584a200b3SVarun Prakash * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2684a200b3SVarun Prakash * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2784a200b3SVarun Prakash * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2884a200b3SVarun Prakash * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2984a200b3SVarun Prakash * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3084a200b3SVarun Prakash * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3184a200b3SVarun Prakash * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3284a200b3SVarun Prakash * SOFTWARE.
3384a200b3SVarun Prakash */
3484a200b3SVarun Prakash
3584a200b3SVarun Prakash #ifdef CONFIG_CHELSIO_T4_FCOE
3684a200b3SVarun Prakash
3784a200b3SVarun Prakash #include <scsi/fc/fc_fs.h>
3884a200b3SVarun Prakash #include <scsi/libfcoe.h>
3984a200b3SVarun Prakash #include "cxgb4.h"
4084a200b3SVarun Prakash
cxgb_fcoe_sof_eof_supported(struct adapter * adap,struct sk_buff * skb)4184a200b3SVarun Prakash bool cxgb_fcoe_sof_eof_supported(struct adapter *adap, struct sk_buff *skb)
4284a200b3SVarun Prakash {
4384a200b3SVarun Prakash struct fcoe_hdr *fcoeh = (struct fcoe_hdr *)skb_network_header(skb);
4484a200b3SVarun Prakash u8 sof = fcoeh->fcoe_sof;
4584a200b3SVarun Prakash u8 eof = 0;
4684a200b3SVarun Prakash
4784a200b3SVarun Prakash if ((sof != FC_SOF_I3) && (sof != FC_SOF_N3)) {
4884a200b3SVarun Prakash dev_err(adap->pdev_dev, "Unsupported SOF 0x%x\n", sof);
491fb7cd4eSWu Fengguang return false;
5084a200b3SVarun Prakash }
5184a200b3SVarun Prakash
5284a200b3SVarun Prakash skb_copy_bits(skb, skb->len - 4, &eof, 1);
5384a200b3SVarun Prakash
5484a200b3SVarun Prakash if ((eof != FC_EOF_N) && (eof != FC_EOF_T)) {
5584a200b3SVarun Prakash dev_err(adap->pdev_dev, "Unsupported EOF 0x%x\n", eof);
561fb7cd4eSWu Fengguang return false;
5784a200b3SVarun Prakash }
5884a200b3SVarun Prakash
591fb7cd4eSWu Fengguang return true;
6084a200b3SVarun Prakash }
6184a200b3SVarun Prakash
6284a200b3SVarun Prakash /**
6384a200b3SVarun Prakash * cxgb_fcoe_enable - enable FCoE offload features
6484a200b3SVarun Prakash * @netdev: net device
6584a200b3SVarun Prakash *
6684a200b3SVarun Prakash * Returns 0 on success or -EINVAL on failure.
6784a200b3SVarun Prakash */
cxgb_fcoe_enable(struct net_device * netdev)6884a200b3SVarun Prakash int cxgb_fcoe_enable(struct net_device *netdev)
6984a200b3SVarun Prakash {
7084a200b3SVarun Prakash struct port_info *pi = netdev_priv(netdev);
7184a200b3SVarun Prakash struct adapter *adap = pi->adapter;
7284a200b3SVarun Prakash struct cxgb_fcoe *fcoe = &pi->fcoe;
7384a200b3SVarun Prakash
7484a200b3SVarun Prakash if (is_t4(adap->params.chip))
7584a200b3SVarun Prakash return -EINVAL;
7684a200b3SVarun Prakash
77*80f61f19SArjun Vynipadath if (!(adap->flags & CXGB4_FULL_INIT_DONE))
7884a200b3SVarun Prakash return -EINVAL;
7984a200b3SVarun Prakash
8084a200b3SVarun Prakash dev_info(adap->pdev_dev, "Enabling FCoE offload features\n");
8184a200b3SVarun Prakash
8284a200b3SVarun Prakash netdev->features |= NETIF_F_FCOE_CRC;
8384a200b3SVarun Prakash netdev->vlan_features |= NETIF_F_FCOE_CRC;
8484a200b3SVarun Prakash netdev->features |= NETIF_F_FCOE_MTU;
8584a200b3SVarun Prakash netdev->vlan_features |= NETIF_F_FCOE_MTU;
8684a200b3SVarun Prakash
8784a200b3SVarun Prakash netdev_features_change(netdev);
8884a200b3SVarun Prakash
8984a200b3SVarun Prakash fcoe->flags |= CXGB_FCOE_ENABLED;
9084a200b3SVarun Prakash
9184a200b3SVarun Prakash return 0;
9284a200b3SVarun Prakash }
9384a200b3SVarun Prakash
9484a200b3SVarun Prakash /**
9584a200b3SVarun Prakash * cxgb_fcoe_disable - disable FCoE offload
9684a200b3SVarun Prakash * @netdev: net device
9784a200b3SVarun Prakash *
9884a200b3SVarun Prakash * Returns 0 on success or -EINVAL on failure.
9984a200b3SVarun Prakash */
cxgb_fcoe_disable(struct net_device * netdev)10084a200b3SVarun Prakash int cxgb_fcoe_disable(struct net_device *netdev)
10184a200b3SVarun Prakash {
10284a200b3SVarun Prakash struct port_info *pi = netdev_priv(netdev);
10384a200b3SVarun Prakash struct adapter *adap = pi->adapter;
10484a200b3SVarun Prakash struct cxgb_fcoe *fcoe = &pi->fcoe;
10584a200b3SVarun Prakash
10684a200b3SVarun Prakash if (!(fcoe->flags & CXGB_FCOE_ENABLED))
10784a200b3SVarun Prakash return -EINVAL;
10884a200b3SVarun Prakash
10984a200b3SVarun Prakash dev_info(adap->pdev_dev, "Disabling FCoE offload features\n");
11084a200b3SVarun Prakash
11184a200b3SVarun Prakash fcoe->flags &= ~CXGB_FCOE_ENABLED;
11284a200b3SVarun Prakash
11384a200b3SVarun Prakash netdev->features &= ~NETIF_F_FCOE_CRC;
11484a200b3SVarun Prakash netdev->vlan_features &= ~NETIF_F_FCOE_CRC;
11584a200b3SVarun Prakash netdev->features &= ~NETIF_F_FCOE_MTU;
11684a200b3SVarun Prakash netdev->vlan_features &= ~NETIF_F_FCOE_MTU;
11784a200b3SVarun Prakash
11884a200b3SVarun Prakash netdev_features_change(netdev);
11984a200b3SVarun Prakash
12084a200b3SVarun Prakash return 0;
12184a200b3SVarun Prakash }
12284a200b3SVarun Prakash #endif /* CONFIG_CHELSIO_T4_FCOE */
123