i40e_client.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/list.h>
  27. #include <linux/errno.h>
  28. #include "i40e.h"
  29. #include "i40e_prototype.h"
  30. #include "i40e_client.h"
  31. static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
  32. static LIST_HEAD(i40e_devices);
  33. static DEFINE_MUTEX(i40e_device_mutex);
  34. static LIST_HEAD(i40e_clients);
  35. static DEFINE_MUTEX(i40e_client_mutex);
  36. static LIST_HEAD(i40e_client_instances);
  37. static DEFINE_MUTEX(i40e_client_instance_mutex);
  38. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  39. struct i40e_client *client,
  40. u32 vf_id, u8 *msg, u16 len);
  41. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  42. struct i40e_client *client,
  43. struct i40e_qvlist_info *qvlist_info);
  44. static void i40e_client_request_reset(struct i40e_info *ldev,
  45. struct i40e_client *client,
  46. u32 reset_level);
  47. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  48. struct i40e_client *client,
  49. bool is_vf, u32 vf_id,
  50. u32 flag, u32 valid_flag);
  51. static struct i40e_ops i40e_lan_ops = {
  52. .virtchnl_send = i40e_client_virtchnl_send,
  53. .setup_qvlist = i40e_client_setup_qvlist,
  54. .request_reset = i40e_client_request_reset,
  55. .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
  56. };
  57. /**
  58. * i40e_client_type_to_vsi_type - convert client type to vsi type
  59. * @client_type: the i40e_client type
  60. *
  61. * returns the related vsi type value
  62. **/
  63. static
  64. enum i40e_vsi_type i40e_client_type_to_vsi_type(enum i40e_client_type type)
  65. {
  66. switch (type) {
  67. case I40E_CLIENT_IWARP:
  68. return I40E_VSI_IWARP;
  69. case I40E_CLIENT_VMDQ2:
  70. return I40E_VSI_VMDQ2;
  71. default:
  72. pr_err("i40e: Client type unknown\n");
  73. return I40E_VSI_TYPE_UNKNOWN;
  74. }
  75. }
  76. /**
  77. * i40e_client_get_params - Get the params that can change at runtime
  78. * @vsi: the VSI with the message
  79. * @param: clinet param struct
  80. *
  81. **/
  82. static
  83. int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
  84. {
  85. struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
  86. int i = 0;
  87. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  88. u8 tc = dcb_cfg->etscfg.prioritytable[i];
  89. u16 qs_handle;
  90. /* If TC is not enabled for VSI use TC0 for UP */
  91. if (!(vsi->tc_config.enabled_tc & BIT(tc)))
  92. tc = 0;
  93. qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
  94. params->qos.prio_qos[i].tc = tc;
  95. params->qos.prio_qos[i].qs_handle = qs_handle;
  96. if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
  97. dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
  98. tc, vsi->id);
  99. return -EINVAL;
  100. }
  101. }
  102. params->mtu = vsi->netdev->mtu;
  103. return 0;
  104. }
  105. /**
  106. * i40e_notify_client_of_vf_msg - call the client vf message callback
  107. * @vsi: the VSI with the message
  108. * @vf_id: the absolute VF id that sent the message
  109. * @msg: message buffer
  110. * @len: length of the message
  111. *
  112. * If there is a client to this VSI, call the client
  113. **/
  114. void
  115. i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
  116. {
  117. struct i40e_client_instance *cdev;
  118. if (!vsi)
  119. return;
  120. mutex_lock(&i40e_client_instance_mutex);
  121. list_for_each_entry(cdev, &i40e_client_instances, list) {
  122. if (cdev->lan_info.pf == vsi->back) {
  123. if (!cdev->client ||
  124. !cdev->client->ops ||
  125. !cdev->client->ops->virtchnl_receive) {
  126. dev_dbg(&vsi->back->pdev->dev,
  127. "Cannot locate client instance virtual channel receive routine\n");
  128. continue;
  129. }
  130. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  131. &cdev->state)) {
  132. dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort virtchnl_receive\n");
  133. continue;
  134. }
  135. cdev->client->ops->virtchnl_receive(&cdev->lan_info,
  136. cdev->client,
  137. vf_id, msg, len);
  138. }
  139. }
  140. mutex_unlock(&i40e_client_instance_mutex);
  141. }
  142. /**
  143. * i40e_notify_client_of_l2_param_changes - call the client notify callback
  144. * @vsi: the VSI with l2 param changes
  145. *
  146. * If there is a client to this VSI, call the client
  147. **/
  148. void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
  149. {
  150. struct i40e_client_instance *cdev;
  151. struct i40e_params params;
  152. if (!vsi)
  153. return;
  154. memset(&params, 0, sizeof(params));
  155. i40e_client_get_params(vsi, &params);
  156. mutex_lock(&i40e_client_instance_mutex);
  157. list_for_each_entry(cdev, &i40e_client_instances, list) {
  158. if (cdev->lan_info.pf == vsi->back) {
  159. if (!cdev->client ||
  160. !cdev->client->ops ||
  161. !cdev->client->ops->l2_param_change) {
  162. dev_dbg(&vsi->back->pdev->dev,
  163. "Cannot locate client instance l2_param_change routine\n");
  164. continue;
  165. }
  166. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  167. &cdev->state)) {
  168. dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
  169. continue;
  170. }
  171. cdev->lan_info.params = params;
  172. cdev->client->ops->l2_param_change(&cdev->lan_info,
  173. cdev->client,
  174. &params);
  175. }
  176. }
  177. mutex_unlock(&i40e_client_instance_mutex);
  178. }
  179. /**
  180. * i40e_client_release_qvlist
  181. * @ldev: pointer to L2 context.
  182. *
  183. **/
  184. static void i40e_client_release_qvlist(struct i40e_info *ldev)
  185. {
  186. struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
  187. u32 i;
  188. if (!ldev->qvlist_info)
  189. return;
  190. for (i = 0; i < qvlist_info->num_vectors; i++) {
  191. struct i40e_pf *pf = ldev->pf;
  192. struct i40e_qv_info *qv_info;
  193. u32 reg_idx;
  194. qv_info = &qvlist_info->qv_info[i];
  195. if (!qv_info)
  196. continue;
  197. reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
  198. wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  199. }
  200. kfree(ldev->qvlist_info);
  201. ldev->qvlist_info = NULL;
  202. }
  203. /**
  204. * i40e_notify_client_of_netdev_close - call the client close callback
  205. * @vsi: the VSI with netdev closed
  206. * @reset: true when close called due to a reset pending
  207. *
  208. * If there is a client to this netdev, call the client with close
  209. **/
  210. void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
  211. {
  212. struct i40e_client_instance *cdev;
  213. if (!vsi)
  214. return;
  215. mutex_lock(&i40e_client_instance_mutex);
  216. list_for_each_entry(cdev, &i40e_client_instances, list) {
  217. if (cdev->lan_info.netdev == vsi->netdev) {
  218. if (!cdev->client ||
  219. !cdev->client->ops || !cdev->client->ops->close) {
  220. dev_dbg(&vsi->back->pdev->dev,
  221. "Cannot locate client instance close routine\n");
  222. continue;
  223. }
  224. cdev->client->ops->close(&cdev->lan_info, cdev->client,
  225. reset);
  226. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  227. i40e_client_release_qvlist(&cdev->lan_info);
  228. }
  229. }
  230. mutex_unlock(&i40e_client_instance_mutex);
  231. }
  232. /**
  233. * i40e_notify_client_of_vf_reset - call the client vf reset callback
  234. * @pf: PF device pointer
  235. * @vf_id: asolute id of VF being reset
  236. *
  237. * If there is a client attached to this PF, notify when a VF is reset
  238. **/
  239. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
  240. {
  241. struct i40e_client_instance *cdev;
  242. if (!pf)
  243. return;
  244. mutex_lock(&i40e_client_instance_mutex);
  245. list_for_each_entry(cdev, &i40e_client_instances, list) {
  246. if (cdev->lan_info.pf == pf) {
  247. if (!cdev->client ||
  248. !cdev->client->ops ||
  249. !cdev->client->ops->vf_reset) {
  250. dev_dbg(&pf->pdev->dev,
  251. "Cannot locate client instance VF reset routine\n");
  252. continue;
  253. }
  254. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  255. &cdev->state)) {
  256. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
  257. continue;
  258. }
  259. cdev->client->ops->vf_reset(&cdev->lan_info,
  260. cdev->client, vf_id);
  261. }
  262. }
  263. mutex_unlock(&i40e_client_instance_mutex);
  264. }
  265. /**
  266. * i40e_notify_client_of_vf_enable - call the client vf notification callback
  267. * @pf: PF device pointer
  268. * @num_vfs: the number of VFs currently enabled, 0 for disable
  269. *
  270. * If there is a client attached to this PF, call its VF notification routine
  271. **/
  272. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
  273. {
  274. struct i40e_client_instance *cdev;
  275. if (!pf)
  276. return;
  277. mutex_lock(&i40e_client_instance_mutex);
  278. list_for_each_entry(cdev, &i40e_client_instances, list) {
  279. if (cdev->lan_info.pf == pf) {
  280. if (!cdev->client ||
  281. !cdev->client->ops ||
  282. !cdev->client->ops->vf_enable) {
  283. dev_dbg(&pf->pdev->dev,
  284. "Cannot locate client instance VF enable routine\n");
  285. continue;
  286. }
  287. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  288. &cdev->state)) {
  289. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
  290. continue;
  291. }
  292. cdev->client->ops->vf_enable(&cdev->lan_info,
  293. cdev->client, num_vfs);
  294. }
  295. }
  296. mutex_unlock(&i40e_client_instance_mutex);
  297. }
  298. /**
  299. * i40e_vf_client_capable - ask the client if it likes the specified VF
  300. * @pf: PF device pointer
  301. * @vf_id: the VF in question
  302. *
  303. * If there is a client of the specified type attached to this PF, call
  304. * its vf_capable routine
  305. **/
  306. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
  307. enum i40e_client_type type)
  308. {
  309. struct i40e_client_instance *cdev;
  310. int capable = false;
  311. if (!pf)
  312. return false;
  313. mutex_lock(&i40e_client_instance_mutex);
  314. list_for_each_entry(cdev, &i40e_client_instances, list) {
  315. if (cdev->lan_info.pf == pf) {
  316. if (!cdev->client ||
  317. !cdev->client->ops ||
  318. !cdev->client->ops->vf_capable ||
  319. !(cdev->client->type == type)) {
  320. dev_dbg(&pf->pdev->dev,
  321. "Cannot locate client instance VF capability routine\n");
  322. continue;
  323. }
  324. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  325. &cdev->state)) {
  326. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-capable\n");
  327. continue;
  328. }
  329. capable = cdev->client->ops->vf_capable(&cdev->lan_info,
  330. cdev->client,
  331. vf_id);
  332. break;
  333. }
  334. }
  335. mutex_unlock(&i40e_client_instance_mutex);
  336. return capable;
  337. }
  338. /**
  339. * i40e_client_add_instance - add a client instance struct to the instance list
  340. * @pf: pointer to the board struct
  341. * @client: pointer to a client struct in the client list.
  342. * @existing: if there was already an existing instance
  343. *
  344. * Returns cdev ptr on success or if already exists, NULL on failure
  345. **/
  346. static
  347. struct i40e_client_instance *i40e_client_add_instance(struct i40e_pf *pf,
  348. struct i40e_client *client,
  349. bool *existing)
  350. {
  351. struct i40e_client_instance *cdev;
  352. struct netdev_hw_addr *mac = NULL;
  353. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  354. mutex_lock(&i40e_client_instance_mutex);
  355. list_for_each_entry(cdev, &i40e_client_instances, list) {
  356. if ((cdev->lan_info.pf == pf) && (cdev->client == client)) {
  357. *existing = true;
  358. goto out;
  359. }
  360. }
  361. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  362. if (!cdev)
  363. goto out;
  364. cdev->lan_info.pf = (void *)pf;
  365. cdev->lan_info.netdev = vsi->netdev;
  366. cdev->lan_info.pcidev = pf->pdev;
  367. cdev->lan_info.fid = pf->hw.pf_id;
  368. cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
  369. cdev->lan_info.hw_addr = pf->hw.hw_addr;
  370. cdev->lan_info.ops = &i40e_lan_ops;
  371. cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
  372. cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
  373. cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
  374. cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
  375. cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
  376. cdev->lan_info.fw_build = pf->hw.aq.fw_build;
  377. set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
  378. if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
  379. kfree(cdev);
  380. cdev = NULL;
  381. goto out;
  382. }
  383. cdev->lan_info.msix_count = pf->num_iwarp_msix;
  384. cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
  385. mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
  386. struct netdev_hw_addr, list);
  387. if (mac)
  388. ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
  389. else
  390. dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
  391. cdev->client = client;
  392. INIT_LIST_HEAD(&cdev->list);
  393. list_add(&cdev->list, &i40e_client_instances);
  394. out:
  395. mutex_unlock(&i40e_client_instance_mutex);
  396. return cdev;
  397. }
  398. /**
  399. * i40e_client_del_instance - removes a client instance from the list
  400. * @pf: pointer to the board struct
  401. *
  402. * Returns 0 on success or non-0 on error
  403. **/
  404. static
  405. int i40e_client_del_instance(struct i40e_pf *pf, struct i40e_client *client)
  406. {
  407. struct i40e_client_instance *cdev, *tmp;
  408. int ret = -ENODEV;
  409. mutex_lock(&i40e_client_instance_mutex);
  410. list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
  411. if ((cdev->lan_info.pf != pf) || (cdev->client != client))
  412. continue;
  413. dev_info(&pf->pdev->dev, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
  414. client->name, pf->hw.pf_id,
  415. pf->hw.bus.device, pf->hw.bus.func);
  416. list_del(&cdev->list);
  417. kfree(cdev);
  418. ret = 0;
  419. break;
  420. }
  421. mutex_unlock(&i40e_client_instance_mutex);
  422. return ret;
  423. }
  424. /**
  425. * i40e_client_subtask - client maintenance work
  426. * @pf: board private structure
  427. **/
  428. void i40e_client_subtask(struct i40e_pf *pf)
  429. {
  430. struct i40e_client_instance *cdev;
  431. struct i40e_client *client;
  432. bool existing = false;
  433. int ret = 0;
  434. if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
  435. return;
  436. pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  437. /* If we're down or resetting, just bail */
  438. if (test_bit(__I40E_DOWN, &pf->state) ||
  439. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  440. return;
  441. /* Check client state and instantiate client if client registered */
  442. mutex_lock(&i40e_client_mutex);
  443. list_for_each_entry(client, &i40e_clients, list) {
  444. /* first check client is registered */
  445. if (!test_bit(__I40E_CLIENT_REGISTERED, &client->state))
  446. continue;
  447. /* Do we also need the LAN VSI to be up, to create instance */
  448. if (!(client->flags & I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE)) {
  449. /* check if L2 VSI is up, if not we are not ready */
  450. if (test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  451. continue;
  452. } else {
  453. dev_warn(&pf->pdev->dev, "This client %s is being instantiated at probe\n",
  454. client->name);
  455. }
  456. /* Add the client instance to the instance list */
  457. cdev = i40e_client_add_instance(pf, client, &existing);
  458. if (!cdev)
  459. continue;
  460. if (!existing) {
  461. dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
  462. client->name, pf->hw.pf_id,
  463. pf->hw.bus.device, pf->hw.bus.func);
  464. }
  465. mutex_lock(&i40e_client_instance_mutex);
  466. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  467. &cdev->state)) {
  468. /* Send an Open request to the client */
  469. if (client->ops && client->ops->open)
  470. ret = client->ops->open(&cdev->lan_info,
  471. client);
  472. if (!ret) {
  473. set_bit(__I40E_CLIENT_INSTANCE_OPENED,
  474. &cdev->state);
  475. } else {
  476. /* remove client instance */
  477. i40e_client_del_instance(pf, client);
  478. }
  479. }
  480. mutex_unlock(&i40e_client_instance_mutex);
  481. }
  482. mutex_unlock(&i40e_client_mutex);
  483. }
  484. /**
  485. * i40e_lan_add_device - add a lan device struct to the list of lan devices
  486. * @pf: pointer to the board struct
  487. *
  488. * Returns 0 on success or none 0 on error
  489. **/
  490. int i40e_lan_add_device(struct i40e_pf *pf)
  491. {
  492. struct i40e_device *ldev;
  493. int ret = 0;
  494. mutex_lock(&i40e_device_mutex);
  495. list_for_each_entry(ldev, &i40e_devices, list) {
  496. if (ldev->pf == pf) {
  497. ret = -EEXIST;
  498. goto out;
  499. }
  500. }
  501. ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
  502. if (!ldev) {
  503. ret = -ENOMEM;
  504. goto out;
  505. }
  506. ldev->pf = pf;
  507. INIT_LIST_HEAD(&ldev->list);
  508. list_add(&ldev->list, &i40e_devices);
  509. dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
  510. pf->hw.pf_id, pf->hw.bus.device, pf->hw.bus.func);
  511. /* Since in some cases register may have happened before a device gets
  512. * added, we can schedule a subtask to go initiate the clients if
  513. * they can be launched at probe time.
  514. */
  515. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  516. i40e_service_event_schedule(pf);
  517. out:
  518. mutex_unlock(&i40e_device_mutex);
  519. return ret;
  520. }
  521. /**
  522. * i40e_lan_del_device - removes a lan device from the device list
  523. * @pf: pointer to the board struct
  524. *
  525. * Returns 0 on success or non-0 on error
  526. **/
  527. int i40e_lan_del_device(struct i40e_pf *pf)
  528. {
  529. struct i40e_device *ldev, *tmp;
  530. int ret = -ENODEV;
  531. mutex_lock(&i40e_device_mutex);
  532. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  533. if (ldev->pf == pf) {
  534. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
  535. pf->hw.pf_id, pf->hw.bus.device,
  536. pf->hw.bus.func);
  537. list_del(&ldev->list);
  538. kfree(ldev);
  539. ret = 0;
  540. break;
  541. }
  542. }
  543. mutex_unlock(&i40e_device_mutex);
  544. return ret;
  545. }
  546. /**
  547. * i40e_client_release - release client specific resources
  548. * @client: pointer to the registered client
  549. *
  550. * Return 0 on success or < 0 on error
  551. **/
  552. static int i40e_client_release(struct i40e_client *client)
  553. {
  554. struct i40e_client_instance *cdev, *tmp;
  555. struct i40e_pf *pf;
  556. int ret = 0;
  557. LIST_HEAD(cdevs_tmp);
  558. mutex_lock(&i40e_client_instance_mutex);
  559. list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
  560. if (strncmp(cdev->client->name, client->name,
  561. I40E_CLIENT_STR_LENGTH))
  562. continue;
  563. pf = (struct i40e_pf *)cdev->lan_info.pf;
  564. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  565. if (client->ops && client->ops->close)
  566. client->ops->close(&cdev->lan_info, client,
  567. false);
  568. i40e_client_release_qvlist(&cdev->lan_info);
  569. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  570. dev_warn(&pf->pdev->dev,
  571. "Client %s instance for PF id %d closed\n",
  572. client->name, pf->hw.pf_id);
  573. }
  574. /* delete the client instance from the list */
  575. list_move(&cdev->list, &cdevs_tmp);
  576. dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
  577. client->name);
  578. }
  579. mutex_unlock(&i40e_client_instance_mutex);
  580. /* free the client device and release its vsi */
  581. list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
  582. kfree(cdev);
  583. }
  584. return ret;
  585. }
  586. /**
  587. * i40e_client_prepare - prepare client specific resources
  588. * @client: pointer to the registered client
  589. *
  590. * Return 0 on success or < 0 on error
  591. **/
  592. static int i40e_client_prepare(struct i40e_client *client)
  593. {
  594. struct i40e_device *ldev;
  595. struct i40e_pf *pf;
  596. int ret = 0;
  597. mutex_lock(&i40e_device_mutex);
  598. list_for_each_entry(ldev, &i40e_devices, list) {
  599. pf = ldev->pf;
  600. /* Start the client subtask */
  601. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  602. i40e_service_event_schedule(pf);
  603. }
  604. mutex_unlock(&i40e_device_mutex);
  605. return ret;
  606. }
  607. /**
  608. * i40e_client_virtchnl_send - TBD
  609. * @ldev: pointer to L2 context
  610. * @client: Client pointer
  611. * @vf_id: absolute VF identifier
  612. * @msg: message buffer
  613. * @len: length of message buffer
  614. *
  615. * Return 0 on success or < 0 on error
  616. **/
  617. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  618. struct i40e_client *client,
  619. u32 vf_id, u8 *msg, u16 len)
  620. {
  621. struct i40e_pf *pf = ldev->pf;
  622. struct i40e_hw *hw = &pf->hw;
  623. i40e_status err;
  624. err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
  625. 0, msg, len, NULL);
  626. if (err)
  627. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  628. err, hw->aq.asq_last_status);
  629. return err;
  630. }
  631. /**
  632. * i40e_client_setup_qvlist
  633. * @ldev: pointer to L2 context.
  634. * @client: Client pointer.
  635. * @qv_info: queue and vector list
  636. *
  637. * Return 0 on success or < 0 on error
  638. **/
  639. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  640. struct i40e_client *client,
  641. struct i40e_qvlist_info *qvlist_info)
  642. {
  643. struct i40e_pf *pf = ldev->pf;
  644. struct i40e_hw *hw = &pf->hw;
  645. struct i40e_qv_info *qv_info;
  646. u32 v_idx, i, reg_idx, reg;
  647. u32 size;
  648. size = sizeof(struct i40e_qvlist_info) +
  649. (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
  650. ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
  651. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  652. for (i = 0; i < qvlist_info->num_vectors; i++) {
  653. qv_info = &qvlist_info->qv_info[i];
  654. if (!qv_info)
  655. continue;
  656. v_idx = qv_info->v_idx;
  657. /* Validate vector id belongs to this client */
  658. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  659. (v_idx < pf->iwarp_base_vector))
  660. goto err;
  661. ldev->qvlist_info->qv_info[i] = *qv_info;
  662. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  663. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  664. /* Special case - No CEQ mapped on this vector */
  665. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  666. } else {
  667. reg = (qv_info->ceq_idx &
  668. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  669. (I40E_QUEUE_TYPE_PE_CEQ <<
  670. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  671. wr32(hw, reg_idx, reg);
  672. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  673. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  674. (qv_info->itr_idx <<
  675. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  676. (I40E_QUEUE_END_OF_LIST <<
  677. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  678. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  679. }
  680. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  681. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  682. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  683. (qv_info->itr_idx <<
  684. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  685. wr32(hw, I40E_PFINT_AEQCTL, reg);
  686. }
  687. }
  688. /* Mitigate sync problems with iwarp VF driver */
  689. i40e_flush(hw);
  690. return 0;
  691. err:
  692. kfree(ldev->qvlist_info);
  693. ldev->qvlist_info = NULL;
  694. return -EINVAL;
  695. }
  696. /**
  697. * i40e_client_request_reset
  698. * @ldev: pointer to L2 context.
  699. * @client: Client pointer.
  700. * @level: reset level
  701. **/
  702. static void i40e_client_request_reset(struct i40e_info *ldev,
  703. struct i40e_client *client,
  704. u32 reset_level)
  705. {
  706. struct i40e_pf *pf = ldev->pf;
  707. switch (reset_level) {
  708. case I40E_CLIENT_RESET_LEVEL_PF:
  709. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  710. break;
  711. case I40E_CLIENT_RESET_LEVEL_CORE:
  712. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  713. break;
  714. default:
  715. dev_warn(&pf->pdev->dev,
  716. "Client %s instance for PF id %d request an unsupported reset: %d.\n",
  717. client->name, pf->hw.pf_id, reset_level);
  718. break;
  719. }
  720. i40e_service_event_schedule(pf);
  721. }
  722. /**
  723. * i40e_client_update_vsi_ctxt
  724. * @ldev: pointer to L2 context.
  725. * @client: Client pointer.
  726. * @is_vf: if this for the VF
  727. * @vf_id: if is_vf true this carries the vf_id
  728. * @flag: Any device level setting that needs to be done for PE
  729. * @valid_flag: Bits in this match up and enable changing of flag bits
  730. *
  731. * Return 0 on success or < 0 on error
  732. **/
  733. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  734. struct i40e_client *client,
  735. bool is_vf, u32 vf_id,
  736. u32 flag, u32 valid_flag)
  737. {
  738. struct i40e_pf *pf = ldev->pf;
  739. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  740. struct i40e_vsi_context ctxt;
  741. bool update = true;
  742. i40e_status err;
  743. /* TODO: for now do not allow setting VF's VSI setting */
  744. if (is_vf)
  745. return -EINVAL;
  746. ctxt.seid = pf->main_vsi_seid;
  747. ctxt.pf_num = pf->hw.pf_id;
  748. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  749. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  750. if (err) {
  751. dev_info(&pf->pdev->dev,
  752. "couldn't get PF vsi config, err %s aq_err %s\n",
  753. i40e_stat_str(&pf->hw, err),
  754. i40e_aq_str(&pf->hw,
  755. pf->hw.aq.asq_last_status));
  756. return -ENOENT;
  757. }
  758. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  759. (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  760. ctxt.info.valid_sections =
  761. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  762. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  763. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  764. !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  765. ctxt.info.valid_sections =
  766. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  767. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  768. } else {
  769. update = false;
  770. dev_warn(&pf->pdev->dev,
  771. "Client %s instance for PF id %d request an unsupported Config: %x.\n",
  772. client->name, pf->hw.pf_id, flag);
  773. }
  774. if (update) {
  775. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  776. if (err) {
  777. dev_info(&pf->pdev->dev,
  778. "update VSI ctxt for PE failed, err %s aq_err %s\n",
  779. i40e_stat_str(&pf->hw, err),
  780. i40e_aq_str(&pf->hw,
  781. pf->hw.aq.asq_last_status));
  782. }
  783. }
  784. return err;
  785. }
  786. /**
  787. * i40e_register_client - Register a i40e client driver with the L2 driver
  788. * @client: pointer to the i40e_client struct
  789. *
  790. * Returns 0 on success or non-0 on error
  791. **/
  792. int i40e_register_client(struct i40e_client *client)
  793. {
  794. int ret = 0;
  795. enum i40e_vsi_type vsi_type;
  796. if (!client) {
  797. ret = -EIO;
  798. goto out;
  799. }
  800. if (strlen(client->name) == 0) {
  801. pr_info("i40e: Failed to register client with no name\n");
  802. ret = -EIO;
  803. goto out;
  804. }
  805. mutex_lock(&i40e_client_mutex);
  806. if (i40e_client_is_registered(client)) {
  807. pr_info("i40e: Client %s has already been registered!\n",
  808. client->name);
  809. mutex_unlock(&i40e_client_mutex);
  810. ret = -EEXIST;
  811. goto out;
  812. }
  813. if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
  814. (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
  815. pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
  816. client->name);
  817. pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
  818. client->version.major, client->version.minor,
  819. client->version.build,
  820. i40e_client_interface_version_str);
  821. mutex_unlock(&i40e_client_mutex);
  822. ret = -EIO;
  823. goto out;
  824. }
  825. vsi_type = i40e_client_type_to_vsi_type(client->type);
  826. if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
  827. pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
  828. client->name, client->type);
  829. mutex_unlock(&i40e_client_mutex);
  830. ret = -EIO;
  831. goto out;
  832. }
  833. list_add(&client->list, &i40e_clients);
  834. set_bit(__I40E_CLIENT_REGISTERED, &client->state);
  835. mutex_unlock(&i40e_client_mutex);
  836. if (i40e_client_prepare(client)) {
  837. ret = -EIO;
  838. goto out;
  839. }
  840. pr_info("i40e: Registered client %s with return code %d\n",
  841. client->name, ret);
  842. out:
  843. return ret;
  844. }
  845. EXPORT_SYMBOL(i40e_register_client);
  846. /**
  847. * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
  848. * @client: pointer to the i40e_client struct
  849. *
  850. * Returns 0 on success or non-0 on error
  851. **/
  852. int i40e_unregister_client(struct i40e_client *client)
  853. {
  854. int ret = 0;
  855. /* When a unregister request comes through we would have to send
  856. * a close for each of the client instances that were opened.
  857. * client_release function is called to handle this.
  858. */
  859. mutex_lock(&i40e_client_mutex);
  860. if (!client || i40e_client_release(client)) {
  861. ret = -EIO;
  862. goto out;
  863. }
  864. /* TODO: check if device is in reset, or if that matters? */
  865. if (!i40e_client_is_registered(client)) {
  866. pr_info("i40e: Client %s has not been registered\n",
  867. client->name);
  868. ret = -ENODEV;
  869. goto out;
  870. }
  871. clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
  872. list_del(&client->list);
  873. pr_info("i40e: Unregistered client %s with return code %d\n",
  874. client->name, ret);
  875. out:
  876. mutex_unlock(&i40e_client_mutex);
  877. return ret;
  878. }
  879. EXPORT_SYMBOL(i40e_unregister_client);