|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2017 Hisilicon Limited. |
| 3 | + * |
| 4 | + * This software is available to you under a choice of one of two |
| 5 | + * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | + * General Public License (GPL) Version 2, available from the file |
| 7 | + * COPYING in the main directory of this source tree, or the |
| 8 | + * OpenIB.org BSD license below: |
| 9 | + * |
| 10 | + * Redistribution and use in source and binary forms, with or |
| 11 | + * without modification, are permitted provided that the following |
| 12 | + * conditions are met: |
| 13 | + * |
| 14 | + * - Redistributions of source code must retain the above |
| 15 | + * copyright notice, this list of conditions and the following |
| 16 | + * disclaimer. |
| 17 | + * |
| 18 | + * - Redistributions in binary form must reproduce the above |
| 19 | + * copyright notice, this list of conditions and the following |
| 20 | + * disclaimer in the documentation and/or other materials |
| 21 | + * provided with the distribution. |
| 22 | + * |
| 23 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | + * SOFTWARE. |
| 31 | + */ |
| 32 | + |
| 33 | +#include <linux/acpi.h> |
| 34 | +#include <linux/etherdevice.h> |
| 35 | +#include <linux/interrupt.h> |
| 36 | +#include <linux/kernel.h> |
| 37 | +#include <rdma/ib_umem.h> |
| 38 | + |
| 39 | +#include "hnae3.h" |
| 40 | +#include "hns_roce_common.h" |
| 41 | +#include "hns_roce_device.h" |
| 42 | +#include "hns_roce_cmd.h" |
| 43 | +#include "hns_roce_hem.h" |
| 44 | + |
| 45 | +static const struct hns_roce_hw hns_roce_hw_v2; |
| 46 | + |
| 47 | +static const struct pci_device_id hns_roce_hw_v2_pci_tbl[] = { |
| 48 | + {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0}, |
| 49 | + {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0}, |
| 50 | + {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0}, |
| 51 | + /* required last entry */ |
| 52 | + {0, } |
| 53 | +}; |
| 54 | + |
| 55 | +static int hns_roce_hw_v2_get_cfg(struct hns_roce_dev *hr_dev, |
| 56 | + struct hnae3_handle *handle) |
| 57 | +{ |
| 58 | + const struct pci_device_id *id; |
| 59 | + |
| 60 | + id = pci_match_id(hns_roce_hw_v2_pci_tbl, hr_dev->pci_dev); |
| 61 | + if (!id) { |
| 62 | + dev_err(hr_dev->dev, "device is not compatible!\n"); |
| 63 | + return -ENXIO; |
| 64 | + } |
| 65 | + |
| 66 | + hr_dev->hw = &hns_roce_hw_v2; |
| 67 | + |
| 68 | + /* Get info from NIC driver. */ |
| 69 | + hr_dev->reg_base = handle->rinfo.roce_io_base; |
| 70 | + hr_dev->caps.num_ports = 1; |
| 71 | + hr_dev->iboe.netdevs[0] = handle->rinfo.netdev; |
| 72 | + hr_dev->iboe.phy_port[0] = 0; |
| 73 | + |
| 74 | + /* cmd issue mode: 0 is poll, 1 is event */ |
| 75 | + hr_dev->cmd_mod = 0; |
| 76 | + hr_dev->loop_idc = 0; |
| 77 | + |
| 78 | + return 0; |
| 79 | +} |
| 80 | + |
| 81 | +static int hns_roce_hw_v2_init_instance(struct hnae3_handle *handle) |
| 82 | +{ |
| 83 | + struct hns_roce_dev *hr_dev; |
| 84 | + int ret; |
| 85 | + |
| 86 | + hr_dev = (struct hns_roce_dev *)ib_alloc_device(sizeof(*hr_dev)); |
| 87 | + if (!hr_dev) |
| 88 | + return -ENOMEM; |
| 89 | + |
| 90 | + hr_dev->pci_dev = handle->pdev; |
| 91 | + hr_dev->dev = &handle->pdev->dev; |
| 92 | + handle->priv = hr_dev; |
| 93 | + |
| 94 | + ret = hns_roce_hw_v2_get_cfg(hr_dev, handle); |
| 95 | + if (ret) { |
| 96 | + dev_err(hr_dev->dev, "Get Configuration failed!\n"); |
| 97 | + goto error_failed_get_cfg; |
| 98 | + } |
| 99 | + |
| 100 | + ret = hns_roce_init(hr_dev); |
| 101 | + if (ret) { |
| 102 | + dev_err(hr_dev->dev, "RoCE Engine init failed!\n"); |
| 103 | + goto error_failed_get_cfg; |
| 104 | + } |
| 105 | + |
| 106 | + return 0; |
| 107 | + |
| 108 | +error_failed_get_cfg: |
| 109 | + ib_dealloc_device(&hr_dev->ib_dev); |
| 110 | + |
| 111 | + return ret; |
| 112 | +} |
| 113 | + |
| 114 | +static void hns_roce_hw_v2_uninit_instance(struct hnae3_handle *handle, |
| 115 | + bool reset) |
| 116 | +{ |
| 117 | + struct hns_roce_dev *hr_dev = (struct hns_roce_dev *)handle->priv; |
| 118 | + |
| 119 | + hns_roce_exit(hr_dev); |
| 120 | + ib_dealloc_device(&hr_dev->ib_dev); |
| 121 | +} |
| 122 | + |
| 123 | +static const struct hnae3_client_ops hns_roce_hw_v2_ops = { |
| 124 | + .init_instance = hns_roce_hw_v2_init_instance, |
| 125 | + .uninit_instance = hns_roce_hw_v2_uninit_instance, |
| 126 | +}; |
| 127 | + |
| 128 | +static struct hnae3_client hns_roce_hw_v2_client = { |
| 129 | + .name = "hns_roce_hw_v2", |
| 130 | + .type = HNAE3_CLIENT_ROCE, |
| 131 | + .ops = &hns_roce_hw_v2_ops, |
| 132 | +}; |
| 133 | + |
| 134 | +static int __init hns_roce_hw_v2_init(void) |
| 135 | +{ |
| 136 | + return hnae3_register_client(&hns_roce_hw_v2_client); |
| 137 | +} |
| 138 | + |
| 139 | +static void __exit hns_roce_hw_v2_exit(void) |
| 140 | +{ |
| 141 | + hnae3_unregister_client(&hns_roce_hw_v2_client); |
| 142 | +} |
| 143 | + |
| 144 | +module_init(hns_roce_hw_v2_init); |
| 145 | +module_exit(hns_roce_hw_v2_exit); |
| 146 | + |
| 147 | +MODULE_LICENSE("Dual BSD/GPL"); |
| 148 | +MODULE_AUTHOR( "Wei Hu <[email protected]>"); |
| 149 | +MODULE_AUTHOR( "Lijun Ou <[email protected]>"); |
| 150 | +MODULE_AUTHOR( "Shaobo Xu <[email protected]>"); |
| 151 | +MODULE_DESCRIPTION("Hisilicon Hip08 Family RoCE Driver"); |
0 commit comments