File Index
Files and directories
Sign in
FILE

i40iw_if.c

File preview with syntax highlighting.

linux-6.19.14/drivers/infiniband/hw/irdma/i40iw_if.c C
  1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  2/* Copyright (c) 2015 - 2021 Intel Corporation */
  3#include "main.h"
  4#include "i40iw_hw.h"
  5#include <linux/net/intel/i40e_client.h>
  6
  7static struct i40e_client i40iw_client;
  8
  9/**
 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
 14 */
 15static void i40iw_l2param_change(struct i40e_info *cdev_info,
 16				 struct i40e_client *client,
 17				 struct i40e_params *params)
 18{
 19	struct irdma_l2params l2params = {};
 20	struct irdma_device *iwdev;
 21	struct ib_device *ibdev;
 22
 23	ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
 24	if (!ibdev)
 25		return;
 26
 27	iwdev = to_iwdev(ibdev);
 28
 29	if (iwdev->vsi.mtu != params->mtu) {
 30		l2params.mtu_changed = true;
 31		l2params.mtu = params->mtu;
 32	}
 33	irdma_change_l2params(&iwdev->vsi, &l2params);
 34	ib_device_put(ibdev);
 35}
 36
 37/**
 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
 42 *
 43 * Called by the lan driver during the processing of client unregister
 44 * Destroy and clean up the driver resources
 45 */
 46static void i40iw_close(struct i40e_info *cdev_info, struct i40e_client *client,
 47			bool reset)
 48{
 49	struct irdma_device *iwdev;
 50	struct ib_device *ibdev;
 51
 52	ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
 53	if (WARN_ON(!ibdev))
 54		return;
 55
 56	iwdev = to_iwdev(ibdev);
 57	if (reset)
 58		iwdev->rf->reset = true;
 59
 60	iwdev->iw_status = 0;
 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));
 64}
 65
 66static void i40iw_request_reset(struct irdma_pci_f *rf)
 67{
 68	struct i40e_info *cdev_info = rf->cdev;
 69
 70	cdev_info->ops->request_reset(cdev_info, &i40iw_client, 1);
 71}
 72
 73static void i40iw_fill_device_info(struct irdma_device *iwdev, struct i40e_info *cdev_info)
 74{
 75	struct irdma_pci_f *rf = iwdev->rf;
 76
 77	rf->rdma_ver = IRDMA_GEN_1;
 78	rf->sc_dev.hw = &rf->hw;
 79	rf->sc_dev.hw_attrs.uk_attrs.hw_rev = IRDMA_GEN_1;
 80	rf->sc_dev.privileged = true;
 81	rf->gen_ops.request_reset = i40iw_request_reset;
 82	rf->pcidev = cdev_info->pcidev;
 83	rf->pf_id = cdev_info->fid;
 84	rf->hw.hw_addr = cdev_info->hw_addr;
 85	rf->cdev = cdev_info;
 86	rf->msix_count = cdev_info->msix_count;
 87	rf->msix_entries = cdev_info->msix_entries;
 88	rf->limits_sel = 5;
 89	rf->protocol_used = IRDMA_IWARP_PROTOCOL_ONLY;
 90	rf->iwdev = iwdev;
 91
 92	iwdev->init_state = INITIAL_STATE;
 93	iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED;
 94	iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE;
 95	iwdev->netdev = cdev_info->netdev;
 96	iwdev->vsi_num = 0;
 97}
 98
 99/**
100 * i40iw_open - client interface operation open for iwarp/uda device
101 * @cdev_info: parent lan device information structure with data/ops
102 * @client: iwarp client information, provided during registration
103 *
104 * Called by the lan driver during the processing of client register
105 * Create device resources, set up queues, pble and hmc objects and
106 * register the device with the ib verbs interface
107 * Return 0 if successful, otherwise return error
108 */
109static int i40iw_open(struct i40e_info *cdev_info, struct i40e_client *client)
110{
111	struct irdma_l2params l2params = {};
112	struct irdma_device *iwdev;
113	struct irdma_pci_f *rf;
114	int err = -EIO;
115	int i;
116	u16 qset;
117	u16 last_qset = IRDMA_NO_QSET;
118
119	iwdev = ib_alloc_device(irdma_device, ibdev);
120	if (!iwdev)
121		return -ENOMEM;
122
123	iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL);
124	if (!iwdev->rf) {
125		ib_dealloc_device(&iwdev->ibdev);
126		return -ENOMEM;
127	}
128
129	i40iw_fill_device_info(iwdev, cdev_info);
130	rf = iwdev->rf;
131
132	if (irdma_ctrl_init_hw(rf)) {
133		err = -EIO;
134		goto err_ctrl_init;
135	}
136
137	l2params.mtu = (cdev_info->params.mtu) ? cdev_info->params.mtu : IRDMA_DEFAULT_MTU;
138	for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++) {
139		qset = cdev_info->params.qos.prio_qos[i].qs_handle;
140		l2params.up2tc[i] = cdev_info->params.qos.prio_qos[i].tc;
141		l2params.qs_handle_list[i] = qset;
142		if (last_qset == IRDMA_NO_QSET)
143			last_qset = qset;
144		else if ((qset != last_qset) && (qset != IRDMA_NO_QSET))
145			iwdev->dcb_vlan_mode = true;
146	}
147
148	if (irdma_rt_init_hw(iwdev, &l2params)) {
149		err = -EIO;
150		goto err_rt_init;
151	}
152
153	err = irdma_ib_register_device(iwdev);
154	if (err)
155		goto err_ibreg;
156
157	ibdev_dbg(&iwdev->ibdev, "INIT: Gen1 PF[%d] open success\n",
158		  PCI_FUNC(rf->pcidev->devfn));
159
160	return 0;
161
162err_ibreg:
163	irdma_rt_deinit_hw(iwdev);
164err_rt_init:
165	irdma_ctrl_deinit_hw(rf);
166err_ctrl_init:
167	kfree(iwdev->rf);
168	ib_dealloc_device(&iwdev->ibdev);
169
170	return err;
171}
172
173/* client interface functions */
174static const struct i40e_client_ops i40e_ops = {
175	.open = i40iw_open,
176	.close = i40iw_close,
177	.l2_param_change = i40iw_l2param_change
178};
179
180static struct i40e_client i40iw_client = {
181	.ops = &i40e_ops,
182	.type = I40E_CLIENT_IWARP,
183};
184
185static int i40iw_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
186{
187	struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
188							       struct i40e_auxiliary_device,
189							       aux_dev);
190	struct i40e_info *cdev_info = i40e_adev->ldev;
191
192	strscpy_pad(i40iw_client.name, "irdma", I40E_CLIENT_STR_LENGTH);
193	i40e_client_device_register(cdev_info, &i40iw_client);
194
195	return 0;
196}
197
198static void i40iw_remove(struct auxiliary_device *aux_dev)
199{
200	struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
201							       struct i40e_auxiliary_device,
202							       aux_dev);
203	struct i40e_info *cdev_info = i40e_adev->ldev;
204
205	i40e_client_device_unregister(cdev_info);
206}
207
208static const struct auxiliary_device_id i40iw_auxiliary_id_table[] = {
209	{.name = "i40e.iwarp", },
210	{},
211};
212
213MODULE_DEVICE_TABLE(auxiliary, i40iw_auxiliary_id_table);
214
215struct auxiliary_driver i40iw_auxiliary_drv = {
216	.name = "gen_1",
217	.id_table = i40iw_auxiliary_id_table,
218	.probe = i40iw_probe,
219	.remove = i40iw_remove,
220};
~/ Read-only file preview.