Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
0002 /* Copyright (c) 2015 - 2021 Intel Corporation */
0003 #include "main.h"
0004 #include "i40iw_hw.h"
0005 #include <linux/net/intel/i40e_client.h>
0006 
0007 static struct i40e_client i40iw_client;
0008 
0009 /**
0010  * i40iw_l2param_change - handle mss change
0011  * @cdev_info: parent lan device information structure with data/ops
0012  * @client: client for parameter change
0013  * @params: new parameters from L2
0014  */
0015 static void i40iw_l2param_change(struct i40e_info *cdev_info,
0016                  struct i40e_client *client,
0017                  struct i40e_params *params)
0018 {
0019     struct irdma_l2params l2params = {};
0020     struct irdma_device *iwdev;
0021     struct ib_device *ibdev;
0022 
0023     ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
0024     if (!ibdev)
0025         return;
0026 
0027     iwdev = to_iwdev(ibdev);
0028 
0029     if (iwdev->vsi.mtu != params->mtu) {
0030         l2params.mtu_changed = true;
0031         l2params.mtu = params->mtu;
0032     }
0033     irdma_change_l2params(&iwdev->vsi, &l2params);
0034     ib_device_put(ibdev);
0035 }
0036 
0037 /**
0038  * i40iw_close - client interface operation close for iwarp/uda device
0039  * @cdev_info: parent lan device information structure with data/ops
0040  * @client: client to close
0041  * @reset: flag to indicate close on reset
0042  *
0043  * Called by the lan driver during the processing of client unregister
0044  * Destroy and clean up the driver resources
0045  */
0046 static void i40iw_close(struct i40e_info *cdev_info, struct i40e_client *client,
0047             bool reset)
0048 {
0049     struct irdma_device *iwdev;
0050     struct ib_device *ibdev;
0051 
0052     ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
0053     if (WARN_ON(!ibdev))
0054         return;
0055 
0056     iwdev = to_iwdev(ibdev);
0057     if (reset)
0058         iwdev->rf->reset = true;
0059 
0060     iwdev->iw_status = 0;
0061     irdma_port_ibevent(iwdev);
0062     ib_unregister_device_and_put(ibdev);
0063     pr_debug("INIT: Gen1 PF[%d] close complete\n", PCI_FUNC(cdev_info->pcidev->devfn));
0064 }
0065 
0066 static void i40iw_request_reset(struct irdma_pci_f *rf)
0067 {
0068     struct i40e_info *cdev_info = rf->cdev;
0069 
0070     cdev_info->ops->request_reset(cdev_info, &i40iw_client, 1);
0071 }
0072 
0073 static void i40iw_fill_device_info(struct irdma_device *iwdev, struct i40e_info *cdev_info)
0074 {
0075     struct irdma_pci_f *rf = iwdev->rf;
0076 
0077     rf->rdma_ver = IRDMA_GEN_1;
0078     rf->gen_ops.request_reset = i40iw_request_reset;
0079     rf->pcidev = cdev_info->pcidev;
0080     rf->pf_id = cdev_info->fid;
0081     rf->hw.hw_addr = cdev_info->hw_addr;
0082     rf->cdev = cdev_info;
0083     rf->msix_count = cdev_info->msix_count;
0084     rf->msix_entries = cdev_info->msix_entries;
0085     rf->limits_sel = 5;
0086     rf->protocol_used = IRDMA_IWARP_PROTOCOL_ONLY;
0087     rf->iwdev = iwdev;
0088 
0089     iwdev->init_state = INITIAL_STATE;
0090     iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED;
0091     iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE;
0092     iwdev->netdev = cdev_info->netdev;
0093     iwdev->vsi_num = 0;
0094 }
0095 
0096 /**
0097  * i40iw_open - client interface operation open for iwarp/uda device
0098  * @cdev_info: parent lan device information structure with data/ops
0099  * @client: iwarp client information, provided during registration
0100  *
0101  * Called by the lan driver during the processing of client register
0102  * Create device resources, set up queues, pble and hmc objects and
0103  * register the device with the ib verbs interface
0104  * Return 0 if successful, otherwise return error
0105  */
0106 static int i40iw_open(struct i40e_info *cdev_info, struct i40e_client *client)
0107 {
0108     struct irdma_l2params l2params = {};
0109     struct irdma_device *iwdev;
0110     struct irdma_pci_f *rf;
0111     int err = -EIO;
0112     int i;
0113     u16 qset;
0114     u16 last_qset = IRDMA_NO_QSET;
0115 
0116     iwdev = ib_alloc_device(irdma_device, ibdev);
0117     if (!iwdev)
0118         return -ENOMEM;
0119 
0120     iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL);
0121     if (!iwdev->rf) {
0122         ib_dealloc_device(&iwdev->ibdev);
0123         return -ENOMEM;
0124     }
0125 
0126     i40iw_fill_device_info(iwdev, cdev_info);
0127     rf = iwdev->rf;
0128 
0129     if (irdma_ctrl_init_hw(rf)) {
0130         err = -EIO;
0131         goto err_ctrl_init;
0132     }
0133 
0134     l2params.mtu = (cdev_info->params.mtu) ? cdev_info->params.mtu : IRDMA_DEFAULT_MTU;
0135     for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++) {
0136         qset = cdev_info->params.qos.prio_qos[i].qs_handle;
0137         l2params.up2tc[i] = cdev_info->params.qos.prio_qos[i].tc;
0138         l2params.qs_handle_list[i] = qset;
0139         if (last_qset == IRDMA_NO_QSET)
0140             last_qset = qset;
0141         else if ((qset != last_qset) && (qset != IRDMA_NO_QSET))
0142             iwdev->dcb_vlan_mode = true;
0143     }
0144 
0145     if (irdma_rt_init_hw(iwdev, &l2params)) {
0146         err = -EIO;
0147         goto err_rt_init;
0148     }
0149 
0150     err = irdma_ib_register_device(iwdev);
0151     if (err)
0152         goto err_ibreg;
0153 
0154     ibdev_dbg(&iwdev->ibdev, "INIT: Gen1 PF[%d] open success\n",
0155           PCI_FUNC(rf->pcidev->devfn));
0156 
0157     return 0;
0158 
0159 err_ibreg:
0160     irdma_rt_deinit_hw(iwdev);
0161 err_rt_init:
0162     irdma_ctrl_deinit_hw(rf);
0163 err_ctrl_init:
0164     kfree(iwdev->rf);
0165     ib_dealloc_device(&iwdev->ibdev);
0166 
0167     return err;
0168 }
0169 
0170 /* client interface functions */
0171 static const struct i40e_client_ops i40e_ops = {
0172     .open = i40iw_open,
0173     .close = i40iw_close,
0174     .l2_param_change = i40iw_l2param_change
0175 };
0176 
0177 static struct i40e_client i40iw_client = {
0178     .ops = &i40e_ops,
0179     .type = I40E_CLIENT_IWARP,
0180 };
0181 
0182 static int i40iw_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
0183 {
0184     struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
0185                                    struct i40e_auxiliary_device,
0186                                    aux_dev);
0187     struct i40e_info *cdev_info = i40e_adev->ldev;
0188 
0189     strncpy(i40iw_client.name, "irdma", I40E_CLIENT_STR_LENGTH);
0190     i40e_client_device_register(cdev_info, &i40iw_client);
0191 
0192     return 0;
0193 }
0194 
0195 static void i40iw_remove(struct auxiliary_device *aux_dev)
0196 {
0197     struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
0198                                    struct i40e_auxiliary_device,
0199                                    aux_dev);
0200     struct i40e_info *cdev_info = i40e_adev->ldev;
0201 
0202     i40e_client_device_unregister(cdev_info);
0203 }
0204 
0205 static const struct auxiliary_device_id i40iw_auxiliary_id_table[] = {
0206     {.name = "i40e.iwarp", },
0207     {},
0208 };
0209 
0210 MODULE_DEVICE_TABLE(auxiliary, i40iw_auxiliary_id_table);
0211 
0212 struct auxiliary_driver i40iw_auxiliary_drv = {
0213     .name = "gen_1",
0214     .id_table = i40iw_auxiliary_id_table,
0215     .probe = i40iw_probe,
0216     .remove = i40iw_remove,
0217 };