1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2015 - 2021 Intel Corporation */
5 #include <linux/net/intel/i40e_client.h>
7 static struct i40e_client i40iw_client;
10 * i40iw_l2param_change - handle mss change
11 * @cdev_info: parent lan device information structure with data/ops
12 * @client: client for parameter change
13 * @params: new parameters from L2
15 static void i40iw_l2param_change(struct i40e_info *cdev_info,
16 struct i40e_client *client,
17 struct i40e_params *params)
19 struct irdma_l2params l2params = {};
20 struct irdma_device *iwdev;
21 struct ib_device *ibdev;
23 ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
27 iwdev = to_iwdev(ibdev);
29 if (iwdev->vsi.mtu != params->mtu) {
30 l2params.mtu_changed = true;
31 l2params.mtu = params->mtu;
33 irdma_change_l2params(&iwdev->vsi, &l2params);
38 * i40iw_close - client interface operation close for iwarp/uda device
39 * @cdev_info: parent lan device information structure with data/ops
40 * @client: client to close
41 * @reset: flag to indicate close on reset
43 * Called by the lan driver during the processing of client unregister
44 * Destroy and clean up the driver resources
46 static void i40iw_close(struct i40e_info *cdev_info, struct i40e_client *client,
49 struct irdma_device *iwdev;
50 struct ib_device *ibdev;
52 ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
56 iwdev = to_iwdev(ibdev);
58 iwdev->rf->reset = true;
61 irdma_port_ibevent(iwdev);
62 ib_unregister_device_and_put(ibdev);
63 pr_debug("INIT: Gen1 PF[%d] close complete\n", PCI_FUNC(cdev_info->pcidev->devfn));
66 static void i40iw_request_reset(struct irdma_pci_f *rf)
68 struct i40e_info *cdev_info = rf->cdev;
70 cdev_info->ops->request_reset(cdev_info, &i40iw_client, 1);
73 static void i40iw_fill_device_info(struct irdma_device *iwdev, struct i40e_info *cdev_info)
75 struct irdma_pci_f *rf = iwdev->rf;
77 rf->rdma_ver = IRDMA_GEN_1;
78 rf->gen_ops.request_reset = i40iw_request_reset;
79 rf->pcidev = cdev_info->pcidev;
80 rf->pf_id = cdev_info->fid;
81 rf->hw.hw_addr = cdev_info->hw_addr;
83 rf->msix_count = cdev_info->msix_count;
84 rf->msix_entries = cdev_info->msix_entries;
86 rf->protocol_used = IRDMA_IWARP_PROTOCOL_ONLY;
89 iwdev->init_state = INITIAL_STATE;
90 iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED;
91 iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE;
92 iwdev->netdev = cdev_info->netdev;
97 * i40iw_open - client interface operation open for iwarp/uda device
98 * @cdev_info: parent lan device information structure with data/ops
99 * @client: iwarp client information, provided during registration
101 * Called by the lan driver during the processing of client register
102 * Create device resources, set up queues, pble and hmc objects and
103 * register the device with the ib verbs interface
104 * Return 0 if successful, otherwise return error
106 static int i40iw_open(struct i40e_info *cdev_info, struct i40e_client *client)
108 struct irdma_l2params l2params = {};
109 struct irdma_device *iwdev;
110 struct irdma_pci_f *rf;
114 u16 last_qset = IRDMA_NO_QSET;
116 iwdev = ib_alloc_device(irdma_device, ibdev);
120 iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL);
122 ib_dealloc_device(&iwdev->ibdev);
126 i40iw_fill_device_info(iwdev, cdev_info);
129 if (irdma_ctrl_init_hw(rf)) {
134 l2params.mtu = (cdev_info->params.mtu) ? cdev_info->params.mtu : IRDMA_DEFAULT_MTU;
135 for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++) {
136 qset = cdev_info->params.qos.prio_qos[i].qs_handle;
137 l2params.up2tc[i] = cdev_info->params.qos.prio_qos[i].tc;
138 l2params.qs_handle_list[i] = qset;
139 if (last_qset == IRDMA_NO_QSET)
141 else if ((qset != last_qset) && (qset != IRDMA_NO_QSET))
142 iwdev->dcb_vlan_mode = true;
145 if (irdma_rt_init_hw(iwdev, &l2params)) {
150 err = irdma_ib_register_device(iwdev);
154 ibdev_dbg(&iwdev->ibdev, "INIT: Gen1 PF[%d] open success\n",
155 PCI_FUNC(rf->pcidev->devfn));
160 irdma_rt_deinit_hw(iwdev);
162 irdma_ctrl_deinit_hw(rf);
165 ib_dealloc_device(&iwdev->ibdev);
170 /* client interface functions */
171 static const struct i40e_client_ops i40e_ops = {
173 .close = i40iw_close,
174 .l2_param_change = i40iw_l2param_change
177 static struct i40e_client i40iw_client = {
179 .type = I40E_CLIENT_IWARP,
182 static int i40iw_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
184 struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
185 struct i40e_auxiliary_device,
187 struct i40e_info *cdev_info = i40e_adev->ldev;
189 strscpy_pad(i40iw_client.name, "irdma", I40E_CLIENT_STR_LENGTH);
190 i40e_client_device_register(cdev_info, &i40iw_client);
195 static void i40iw_remove(struct auxiliary_device *aux_dev)
197 struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
198 struct i40e_auxiliary_device,
200 struct i40e_info *cdev_info = i40e_adev->ldev;
202 i40e_client_device_unregister(cdev_info);
205 static const struct auxiliary_device_id i40iw_auxiliary_id_table[] = {
206 {.name = "i40e.iwarp", },
210 MODULE_DEVICE_TABLE(auxiliary, i40iw_auxiliary_id_table);
212 struct auxiliary_driver i40iw_auxiliary_drv = {
214 .id_table = i40iw_auxiliary_id_table,
215 .probe = i40iw_probe,
216 .remove = i40iw_remove,