treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_fcoe.c
blob33b2c0c455093e9cb8552c8adcfe43a4cb122168
1 /*
2 * This file is part of the Chelsio T4 Ethernet driver for Linux.
4 * Copyright (c) 2015 Chelsio Communications, Inc. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
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.
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.
35 #ifdef CONFIG_CHELSIO_T4_FCOE
37 #include <scsi/fc/fc_fs.h>
38 #include <scsi/libfcoe.h>
39 #include "cxgb4.h"
41 bool cxgb_fcoe_sof_eof_supported(struct adapter *adap, struct sk_buff *skb)
43 struct fcoe_hdr *fcoeh = (struct fcoe_hdr *)skb_network_header(skb);
44 u8 sof = fcoeh->fcoe_sof;
45 u8 eof = 0;
47 if ((sof != FC_SOF_I3) && (sof != FC_SOF_N3)) {
48 dev_err(adap->pdev_dev, "Unsupported SOF 0x%x\n", sof);
49 return false;
52 skb_copy_bits(skb, skb->len - 4, &eof, 1);
54 if ((eof != FC_EOF_N) && (eof != FC_EOF_T)) {
55 dev_err(adap->pdev_dev, "Unsupported EOF 0x%x\n", eof);
56 return false;
59 return true;
62 /**
63 * cxgb_fcoe_enable - enable FCoE offload features
64 * @netdev: net device
66 * Returns 0 on success or -EINVAL on failure.
68 int cxgb_fcoe_enable(struct net_device *netdev)
70 struct port_info *pi = netdev_priv(netdev);
71 struct adapter *adap = pi->adapter;
72 struct cxgb_fcoe *fcoe = &pi->fcoe;
74 if (is_t4(adap->params.chip))
75 return -EINVAL;
77 if (!(adap->flags & CXGB4_FULL_INIT_DONE))
78 return -EINVAL;
80 dev_info(adap->pdev_dev, "Enabling FCoE offload features\n");
82 netdev->features |= NETIF_F_FCOE_CRC;
83 netdev->vlan_features |= NETIF_F_FCOE_CRC;
84 netdev->features |= NETIF_F_FCOE_MTU;
85 netdev->vlan_features |= NETIF_F_FCOE_MTU;
87 netdev_features_change(netdev);
89 fcoe->flags |= CXGB_FCOE_ENABLED;
91 return 0;
94 /**
95 * cxgb_fcoe_disable - disable FCoE offload
96 * @netdev: net device
98 * Returns 0 on success or -EINVAL on failure.
100 int cxgb_fcoe_disable(struct net_device *netdev)
102 struct port_info *pi = netdev_priv(netdev);
103 struct adapter *adap = pi->adapter;
104 struct cxgb_fcoe *fcoe = &pi->fcoe;
106 if (!(fcoe->flags & CXGB_FCOE_ENABLED))
107 return -EINVAL;
109 dev_info(adap->pdev_dev, "Disabling FCoE offload features\n");
111 fcoe->flags &= ~CXGB_FCOE_ENABLED;
113 netdev->features &= ~NETIF_F_FCOE_CRC;
114 netdev->vlan_features &= ~NETIF_F_FCOE_CRC;
115 netdev->features &= ~NETIF_F_FCOE_MTU;
116 netdev->vlan_features &= ~NETIF_F_FCOE_MTU;
118 netdev_features_change(netdev);
120 return 0;
122 #endif /* CONFIG_CHELSIO_T4_FCOE */