i40iw_if.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. static struct i40e_client i40iw_client;
  7. /**
  8. * i40iw_l2param_change - handle mss change
  9. * @cdev_info: parent lan device information structure with data/ops
  10. * @client: client for parameter change
  11. * @params: new parameters from L2
  12. */
  13. static void i40iw_l2param_change(struct i40e_info *cdev_info,
  14. struct i40e_client *client,
  15. struct i40e_params *params)
  16. {
  17. struct irdma_l2params l2params = {};
  18. struct irdma_device *iwdev;
  19. struct ib_device *ibdev;
  20. ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
  21. if (!ibdev)
  22. return;
  23. iwdev = to_iwdev(ibdev);
  24. if (iwdev->vsi.mtu != params->mtu) {
  25. l2params.mtu_changed = true;
  26. l2params.mtu = params->mtu;
  27. }
  28. irdma_change_l2params(&iwdev->vsi, &l2params);
  29. ib_device_put(ibdev);
  30. }
  31. /**
  32. * i40iw_close - client interface operation close for iwarp/uda device
  33. * @cdev_info: parent lan device information structure with data/ops
  34. * @client: client to close
  35. * @reset: flag to indicate close on reset
  36. *
  37. * Called by the lan driver during the processing of client unregister
  38. * Destroy and clean up the driver resources
  39. */
  40. static void i40iw_close(struct i40e_info *cdev_info, struct i40e_client *client,
  41. bool reset)
  42. {
  43. struct irdma_device *iwdev;
  44. struct ib_device *ibdev;
  45. ibdev = ib_device_get_by_netdev(cdev_info->netdev, RDMA_DRIVER_IRDMA);
  46. if (WARN_ON(!ibdev))
  47. return;
  48. iwdev = to_iwdev(ibdev);
  49. if (reset)
  50. iwdev->rf->reset = true;
  51. iwdev->iw_status = 0;
  52. irdma_port_ibevent(iwdev);
  53. ib_unregister_device_and_put(ibdev);
  54. pr_debug("INIT: Gen1 PF[%d] close complete\n", PCI_FUNC(cdev_info->pcidev->devfn));
  55. }
  56. static void i40iw_request_reset(struct irdma_pci_f *rf)
  57. {
  58. struct i40e_info *cdev_info = rf->cdev;
  59. cdev_info->ops->request_reset(cdev_info, &i40iw_client, 1);
  60. }
  61. static void i40iw_fill_device_info(struct irdma_device *iwdev, struct i40e_info *cdev_info)
  62. {
  63. struct irdma_pci_f *rf = iwdev->rf;
  64. rf->rdma_ver = IRDMA_GEN_1;
  65. rf->gen_ops.request_reset = i40iw_request_reset;
  66. rf->pcidev = cdev_info->pcidev;
  67. rf->pf_id = cdev_info->fid;
  68. rf->hw.hw_addr = cdev_info->hw_addr;
  69. rf->cdev = cdev_info;
  70. rf->msix_count = cdev_info->msix_count;
  71. rf->msix_entries = cdev_info->msix_entries;
  72. rf->limits_sel = 5;
  73. rf->protocol_used = IRDMA_IWARP_PROTOCOL_ONLY;
  74. rf->iwdev = iwdev;
  75. iwdev->init_state = INITIAL_STATE;
  76. iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED;
  77. iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE;
  78. iwdev->netdev = cdev_info->netdev;
  79. iwdev->vsi_num = 0;
  80. }
  81. /**
  82. * i40iw_open - client interface operation open for iwarp/uda device
  83. * @cdev_info: parent lan device information structure with data/ops
  84. * @client: iwarp client information, provided during registration
  85. *
  86. * Called by the lan driver during the processing of client register
  87. * Create device resources, set up queues, pble and hmc objects and
  88. * register the device with the ib verbs interface
  89. * Return 0 if successful, otherwise return error
  90. */
  91. static int i40iw_open(struct i40e_info *cdev_info, struct i40e_client *client)
  92. {
  93. struct irdma_l2params l2params = {};
  94. struct irdma_device *iwdev;
  95. struct irdma_pci_f *rf;
  96. int err = -EIO;
  97. int i;
  98. u16 qset;
  99. u16 last_qset = IRDMA_NO_QSET;
  100. iwdev = ib_alloc_device(irdma_device, ibdev);
  101. if (!iwdev)
  102. return -ENOMEM;
  103. iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL);
  104. if (!iwdev->rf) {
  105. ib_dealloc_device(&iwdev->ibdev);
  106. return -ENOMEM;
  107. }
  108. i40iw_fill_device_info(iwdev, cdev_info);
  109. rf = iwdev->rf;
  110. if (irdma_ctrl_init_hw(rf)) {
  111. err = -EIO;
  112. goto err_ctrl_init;
  113. }
  114. l2params.mtu = (cdev_info->params.mtu) ? cdev_info->params.mtu : IRDMA_DEFAULT_MTU;
  115. for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++) {
  116. qset = cdev_info->params.qos.prio_qos[i].qs_handle;
  117. l2params.up2tc[i] = cdev_info->params.qos.prio_qos[i].tc;
  118. l2params.qs_handle_list[i] = qset;
  119. if (last_qset == IRDMA_NO_QSET)
  120. last_qset = qset;
  121. else if ((qset != last_qset) && (qset != IRDMA_NO_QSET))
  122. iwdev->dcb_vlan_mode = true;
  123. }
  124. if (irdma_rt_init_hw(iwdev, &l2params)) {
  125. err = -EIO;
  126. goto err_rt_init;
  127. }
  128. err = irdma_ib_register_device(iwdev);
  129. if (err)
  130. goto err_ibreg;
  131. ibdev_dbg(&iwdev->ibdev, "INIT: Gen1 PF[%d] open success\n",
  132. PCI_FUNC(rf->pcidev->devfn));
  133. return 0;
  134. err_ibreg:
  135. irdma_rt_deinit_hw(iwdev);
  136. err_rt_init:
  137. irdma_ctrl_deinit_hw(rf);
  138. err_ctrl_init:
  139. kfree(iwdev->rf);
  140. ib_dealloc_device(&iwdev->ibdev);
  141. return err;
  142. }
  143. /* client interface functions */
  144. static const struct i40e_client_ops i40e_ops = {
  145. .open = i40iw_open,
  146. .close = i40iw_close,
  147. .l2_param_change = i40iw_l2param_change
  148. };
  149. static struct i40e_client i40iw_client = {
  150. .ops = &i40e_ops,
  151. .type = I40E_CLIENT_IWARP,
  152. };
  153. static int i40iw_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
  154. {
  155. struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
  156. struct i40e_auxiliary_device,
  157. aux_dev);
  158. struct i40e_info *cdev_info = i40e_adev->ldev;
  159. strncpy(i40iw_client.name, "irdma", I40E_CLIENT_STR_LENGTH);
  160. i40e_client_device_register(cdev_info, &i40iw_client);
  161. return 0;
  162. }
  163. static void i40iw_remove(struct auxiliary_device *aux_dev)
  164. {
  165. struct i40e_auxiliary_device *i40e_adev = container_of(aux_dev,
  166. struct i40e_auxiliary_device,
  167. aux_dev);
  168. struct i40e_info *cdev_info = i40e_adev->ldev;
  169. i40e_client_device_unregister(cdev_info);
  170. }
  171. static const struct auxiliary_device_id i40iw_auxiliary_id_table[] = {
  172. {.name = "i40e.iwarp", },
  173. {},
  174. };
  175. MODULE_DEVICE_TABLE(auxiliary, i40iw_auxiliary_id_table);
  176. struct auxiliary_driver i40iw_auxiliary_drv = {
  177. .name = "gen_1",
  178. .id_table = i40iw_auxiliary_id_table,
  179. .probe = i40iw_probe,
  180. .remove = i40iw_remove,
  181. };