18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is part of the Chelsio T4 Ethernet driver for Linux. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2015 Chelsio Communications, Inc. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 78c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 138c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 148c2ecf20Sopenharmony_ci * conditions are met: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 178c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 188c2ecf20Sopenharmony_ci * disclaimer. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 218c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 228c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 238c2ecf20Sopenharmony_ci * provided with the distribution. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 328c2ecf20Sopenharmony_ci * SOFTWARE. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifdef CONFIG_CHELSIO_T4_FCOE 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include <scsi/fc/fc_fs.h> 388c2ecf20Sopenharmony_ci#include <scsi/libfcoe.h> 398c2ecf20Sopenharmony_ci#include "cxgb4.h" 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cibool cxgb_fcoe_sof_eof_supported(struct adapter *adap, struct sk_buff *skb) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci struct fcoe_hdr *fcoeh = (struct fcoe_hdr *)skb_network_header(skb); 448c2ecf20Sopenharmony_ci u8 sof = fcoeh->fcoe_sof; 458c2ecf20Sopenharmony_ci u8 eof = 0; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci if ((sof != FC_SOF_I3) && (sof != FC_SOF_N3)) { 488c2ecf20Sopenharmony_ci dev_err(adap->pdev_dev, "Unsupported SOF 0x%x\n", sof); 498c2ecf20Sopenharmony_ci return false; 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci skb_copy_bits(skb, skb->len - 4, &eof, 1); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci if ((eof != FC_EOF_N) && (eof != FC_EOF_T)) { 558c2ecf20Sopenharmony_ci dev_err(adap->pdev_dev, "Unsupported EOF 0x%x\n", eof); 568c2ecf20Sopenharmony_ci return false; 578c2ecf20Sopenharmony_ci } 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci return true; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * cxgb_fcoe_enable - enable FCoE offload features 648c2ecf20Sopenharmony_ci * @netdev: net device 658c2ecf20Sopenharmony_ci * 668c2ecf20Sopenharmony_ci * Returns 0 on success or -EINVAL on failure. 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ciint cxgb_fcoe_enable(struct net_device *netdev) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci struct port_info *pi = netdev_priv(netdev); 718c2ecf20Sopenharmony_ci struct adapter *adap = pi->adapter; 728c2ecf20Sopenharmony_ci struct cxgb_fcoe *fcoe = &pi->fcoe; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci if (is_t4(adap->params.chip)) 758c2ecf20Sopenharmony_ci return -EINVAL; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci if (!(adap->flags & CXGB4_FULL_INIT_DONE)) 788c2ecf20Sopenharmony_ci return -EINVAL; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci dev_info(adap->pdev_dev, "Enabling FCoE offload features\n"); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci netdev->features |= NETIF_F_FCOE_CRC; 838c2ecf20Sopenharmony_ci netdev->vlan_features |= NETIF_F_FCOE_CRC; 848c2ecf20Sopenharmony_ci netdev->features |= NETIF_F_FCOE_MTU; 858c2ecf20Sopenharmony_ci netdev->vlan_features |= NETIF_F_FCOE_MTU; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci netdev_features_change(netdev); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci fcoe->flags |= CXGB_FCOE_ENABLED; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci return 0; 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * cxgb_fcoe_disable - disable FCoE offload 968c2ecf20Sopenharmony_ci * @netdev: net device 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * Returns 0 on success or -EINVAL on failure. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ciint cxgb_fcoe_disable(struct net_device *netdev) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci struct port_info *pi = netdev_priv(netdev); 1038c2ecf20Sopenharmony_ci struct adapter *adap = pi->adapter; 1048c2ecf20Sopenharmony_ci struct cxgb_fcoe *fcoe = &pi->fcoe; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci if (!(fcoe->flags & CXGB_FCOE_ENABLED)) 1078c2ecf20Sopenharmony_ci return -EINVAL; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci dev_info(adap->pdev_dev, "Disabling FCoE offload features\n"); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci fcoe->flags &= ~CXGB_FCOE_ENABLED; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci netdev->features &= ~NETIF_F_FCOE_CRC; 1148c2ecf20Sopenharmony_ci netdev->vlan_features &= ~NETIF_F_FCOE_CRC; 1158c2ecf20Sopenharmony_ci netdev->features &= ~NETIF_F_FCOE_MTU; 1168c2ecf20Sopenharmony_ci netdev->vlan_features &= ~NETIF_F_FCOE_MTU; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci netdev_features_change(netdev); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci return 0; 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci#endif /* CONFIG_CHELSIO_T4_FCOE */ 123