i40e_client.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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_notify_client_of_netdev_open - call the client open callback
  181. * @vsi: the VSI with netdev opened
  182. *
  183. * If there is a client to this netdev, call the client with open
  184. **/
  185. void i40e_notify_client_of_netdev_open(struct i40e_vsi *vsi)
  186. {
  187. struct i40e_client_instance *cdev;
  188. int ret = 0;
  189. if (!vsi)
  190. return;
  191. mutex_lock(&i40e_client_instance_mutex);
  192. list_for_each_entry(cdev, &i40e_client_instances, list) {
  193. if (cdev->lan_info.netdev == vsi->netdev) {
  194. if (!cdev->client ||
  195. !cdev->client->ops || !cdev->client->ops->open) {
  196. dev_dbg(&vsi->back->pdev->dev,
  197. "Cannot locate client instance open routine\n");
  198. continue;
  199. }
  200. if (!(test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  201. &cdev->state))) {
  202. ret = cdev->client->ops->open(&cdev->lan_info,
  203. cdev->client);
  204. if (!ret)
  205. set_bit(__I40E_CLIENT_INSTANCE_OPENED,
  206. &cdev->state);
  207. }
  208. }
  209. }
  210. mutex_unlock(&i40e_client_instance_mutex);
  211. }
  212. /**
  213. * i40e_client_release_qvlist
  214. * @ldev: pointer to L2 context.
  215. *
  216. **/
  217. static void i40e_client_release_qvlist(struct i40e_info *ldev)
  218. {
  219. struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
  220. u32 i;
  221. if (!ldev->qvlist_info)
  222. return;
  223. for (i = 0; i < qvlist_info->num_vectors; i++) {
  224. struct i40e_pf *pf = ldev->pf;
  225. struct i40e_qv_info *qv_info;
  226. u32 reg_idx;
  227. qv_info = &qvlist_info->qv_info[i];
  228. if (!qv_info)
  229. continue;
  230. reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
  231. wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  232. }
  233. kfree(ldev->qvlist_info);
  234. ldev->qvlist_info = NULL;
  235. }
  236. /**
  237. * i40e_notify_client_of_netdev_close - call the client close callback
  238. * @vsi: the VSI with netdev closed
  239. * @reset: true when close called due to a reset pending
  240. *
  241. * If there is a client to this netdev, call the client with close
  242. **/
  243. void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
  244. {
  245. struct i40e_client_instance *cdev;
  246. if (!vsi)
  247. return;
  248. mutex_lock(&i40e_client_instance_mutex);
  249. list_for_each_entry(cdev, &i40e_client_instances, list) {
  250. if (cdev->lan_info.netdev == vsi->netdev) {
  251. if (!cdev->client ||
  252. !cdev->client->ops || !cdev->client->ops->close) {
  253. dev_dbg(&vsi->back->pdev->dev,
  254. "Cannot locate client instance close routine\n");
  255. continue;
  256. }
  257. cdev->client->ops->close(&cdev->lan_info, cdev->client,
  258. reset);
  259. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  260. i40e_client_release_qvlist(&cdev->lan_info);
  261. }
  262. }
  263. mutex_unlock(&i40e_client_instance_mutex);
  264. }
  265. /**
  266. * i40e_notify_client_of_vf_reset - call the client vf reset callback
  267. * @pf: PF device pointer
  268. * @vf_id: asolute id of VF being reset
  269. *
  270. * If there is a client attached to this PF, notify when a VF is reset
  271. **/
  272. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
  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_reset) {
  283. dev_dbg(&pf->pdev->dev,
  284. "Cannot locate client instance VF reset 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-reset\n");
  290. continue;
  291. }
  292. cdev->client->ops->vf_reset(&cdev->lan_info,
  293. cdev->client, vf_id);
  294. }
  295. }
  296. mutex_unlock(&i40e_client_instance_mutex);
  297. }
  298. /**
  299. * i40e_notify_client_of_vf_enable - call the client vf notification callback
  300. * @pf: PF device pointer
  301. * @num_vfs: the number of VFs currently enabled, 0 for disable
  302. *
  303. * If there is a client attached to this PF, call its VF notification routine
  304. **/
  305. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
  306. {
  307. struct i40e_client_instance *cdev;
  308. if (!pf)
  309. return;
  310. mutex_lock(&i40e_client_instance_mutex);
  311. list_for_each_entry(cdev, &i40e_client_instances, list) {
  312. if (cdev->lan_info.pf == pf) {
  313. if (!cdev->client ||
  314. !cdev->client->ops ||
  315. !cdev->client->ops->vf_enable) {
  316. dev_dbg(&pf->pdev->dev,
  317. "Cannot locate client instance VF enable routine\n");
  318. continue;
  319. }
  320. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  321. &cdev->state)) {
  322. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
  323. continue;
  324. }
  325. cdev->client->ops->vf_enable(&cdev->lan_info,
  326. cdev->client, num_vfs);
  327. }
  328. }
  329. mutex_unlock(&i40e_client_instance_mutex);
  330. }
  331. /**
  332. * i40e_vf_client_capable - ask the client if it likes the specified VF
  333. * @pf: PF device pointer
  334. * @vf_id: the VF in question
  335. *
  336. * If there is a client of the specified type attached to this PF, call
  337. * its vf_capable routine
  338. **/
  339. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
  340. enum i40e_client_type type)
  341. {
  342. struct i40e_client_instance *cdev;
  343. int capable = false;
  344. if (!pf)
  345. return false;
  346. mutex_lock(&i40e_client_instance_mutex);
  347. list_for_each_entry(cdev, &i40e_client_instances, list) {
  348. if (cdev->lan_info.pf == pf) {
  349. if (!cdev->client ||
  350. !cdev->client->ops ||
  351. !cdev->client->ops->vf_capable ||
  352. !(cdev->client->type == type)) {
  353. dev_dbg(&pf->pdev->dev,
  354. "Cannot locate client instance VF capability routine\n");
  355. continue;
  356. }
  357. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  358. &cdev->state)) {
  359. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-capable\n");
  360. continue;
  361. }
  362. capable = cdev->client->ops->vf_capable(&cdev->lan_info,
  363. cdev->client,
  364. vf_id);
  365. break;
  366. }
  367. }
  368. mutex_unlock(&i40e_client_instance_mutex);
  369. return capable;
  370. }
  371. /**
  372. * i40e_client_add_instance - add a client instance struct to the instance list
  373. * @pf: pointer to the board struct
  374. * @client: pointer to a client struct in the client list.
  375. * @existing: if there was already an existing instance
  376. *
  377. * Returns cdev ptr on success or if already exists, NULL on failure
  378. **/
  379. static
  380. struct i40e_client_instance *i40e_client_add_instance(struct i40e_pf *pf,
  381. struct i40e_client *client,
  382. bool *existing)
  383. {
  384. struct i40e_client_instance *cdev;
  385. struct netdev_hw_addr *mac = NULL;
  386. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  387. mutex_lock(&i40e_client_instance_mutex);
  388. list_for_each_entry(cdev, &i40e_client_instances, list) {
  389. if ((cdev->lan_info.pf == pf) && (cdev->client == client)) {
  390. *existing = true;
  391. goto out;
  392. }
  393. }
  394. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  395. if (!cdev)
  396. goto out;
  397. cdev->lan_info.pf = (void *)pf;
  398. cdev->lan_info.netdev = vsi->netdev;
  399. cdev->lan_info.pcidev = pf->pdev;
  400. cdev->lan_info.fid = pf->hw.pf_id;
  401. cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
  402. cdev->lan_info.hw_addr = pf->hw.hw_addr;
  403. cdev->lan_info.ops = &i40e_lan_ops;
  404. cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
  405. cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
  406. cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
  407. cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
  408. cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
  409. cdev->lan_info.fw_build = pf->hw.aq.fw_build;
  410. set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
  411. if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
  412. kfree(cdev);
  413. cdev = NULL;
  414. goto out;
  415. }
  416. cdev->lan_info.msix_count = pf->num_iwarp_msix;
  417. cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
  418. mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
  419. struct netdev_hw_addr, list);
  420. if (mac)
  421. ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
  422. else
  423. dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
  424. cdev->client = client;
  425. INIT_LIST_HEAD(&cdev->list);
  426. list_add(&cdev->list, &i40e_client_instances);
  427. out:
  428. mutex_unlock(&i40e_client_instance_mutex);
  429. return cdev;
  430. }
  431. /**
  432. * i40e_client_del_instance - removes a client instance from the list
  433. * @pf: pointer to the board struct
  434. *
  435. * Returns 0 on success or non-0 on error
  436. **/
  437. static
  438. int i40e_client_del_instance(struct i40e_pf *pf, struct i40e_client *client)
  439. {
  440. struct i40e_client_instance *cdev, *tmp;
  441. int ret = -ENODEV;
  442. mutex_lock(&i40e_client_instance_mutex);
  443. list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
  444. if ((cdev->lan_info.pf != pf) || (cdev->client != client))
  445. continue;
  446. dev_info(&pf->pdev->dev, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
  447. client->name, pf->hw.pf_id,
  448. pf->hw.bus.device, pf->hw.bus.func);
  449. list_del(&cdev->list);
  450. kfree(cdev);
  451. ret = 0;
  452. break;
  453. }
  454. mutex_unlock(&i40e_client_instance_mutex);
  455. return ret;
  456. }
  457. /**
  458. * i40e_client_subtask - client maintenance work
  459. * @pf: board private structure
  460. **/
  461. void i40e_client_subtask(struct i40e_pf *pf)
  462. {
  463. struct i40e_client_instance *cdev;
  464. struct i40e_client *client;
  465. bool existing = false;
  466. int ret = 0;
  467. if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
  468. return;
  469. pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  470. /* If we're down or resetting, just bail */
  471. if (test_bit(__I40E_DOWN, &pf->state) ||
  472. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  473. return;
  474. /* Check client state and instantiate client if client registered */
  475. mutex_lock(&i40e_client_mutex);
  476. list_for_each_entry(client, &i40e_clients, list) {
  477. /* first check client is registered */
  478. if (!test_bit(__I40E_CLIENT_REGISTERED, &client->state))
  479. continue;
  480. /* Do we also need the LAN VSI to be up, to create instance */
  481. if (!(client->flags & I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE)) {
  482. /* check if L2 VSI is up, if not we are not ready */
  483. if (test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  484. continue;
  485. } else {
  486. dev_warn(&pf->pdev->dev, "This client %s is being instantiated at probe\n",
  487. client->name);
  488. }
  489. /* Add the client instance to the instance list */
  490. cdev = i40e_client_add_instance(pf, client, &existing);
  491. if (!cdev)
  492. continue;
  493. if (!existing) {
  494. dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
  495. client->name, pf->hw.pf_id,
  496. pf->hw.bus.device, pf->hw.bus.func);
  497. }
  498. mutex_lock(&i40e_client_instance_mutex);
  499. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  500. &cdev->state)) {
  501. /* Send an Open request to the client */
  502. if (client->ops && client->ops->open)
  503. ret = client->ops->open(&cdev->lan_info,
  504. client);
  505. if (!ret) {
  506. set_bit(__I40E_CLIENT_INSTANCE_OPENED,
  507. &cdev->state);
  508. } else {
  509. /* remove client instance */
  510. i40e_client_del_instance(pf, client);
  511. }
  512. }
  513. mutex_unlock(&i40e_client_instance_mutex);
  514. }
  515. mutex_unlock(&i40e_client_mutex);
  516. }
  517. /**
  518. * i40e_lan_add_device - add a lan device struct to the list of lan devices
  519. * @pf: pointer to the board struct
  520. *
  521. * Returns 0 on success or none 0 on error
  522. **/
  523. int i40e_lan_add_device(struct i40e_pf *pf)
  524. {
  525. struct i40e_device *ldev;
  526. int ret = 0;
  527. mutex_lock(&i40e_device_mutex);
  528. list_for_each_entry(ldev, &i40e_devices, list) {
  529. if (ldev->pf == pf) {
  530. ret = -EEXIST;
  531. goto out;
  532. }
  533. }
  534. ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
  535. if (!ldev) {
  536. ret = -ENOMEM;
  537. goto out;
  538. }
  539. ldev->pf = pf;
  540. INIT_LIST_HEAD(&ldev->list);
  541. list_add(&ldev->list, &i40e_devices);
  542. dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
  543. pf->hw.pf_id, pf->hw.bus.device, pf->hw.bus.func);
  544. /* Since in some cases register may have happened before a device gets
  545. * added, we can schedule a subtask to go initiate the clients if
  546. * they can be launched at probe time.
  547. */
  548. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  549. i40e_service_event_schedule(pf);
  550. out:
  551. mutex_unlock(&i40e_device_mutex);
  552. return ret;
  553. }
  554. /**
  555. * i40e_lan_del_device - removes a lan device from the device list
  556. * @pf: pointer to the board struct
  557. *
  558. * Returns 0 on success or non-0 on error
  559. **/
  560. int i40e_lan_del_device(struct i40e_pf *pf)
  561. {
  562. struct i40e_device *ldev, *tmp;
  563. int ret = -ENODEV;
  564. mutex_lock(&i40e_device_mutex);
  565. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  566. if (ldev->pf == pf) {
  567. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
  568. pf->hw.pf_id, pf->hw.bus.device,
  569. pf->hw.bus.func);
  570. list_del(&ldev->list);
  571. kfree(ldev);
  572. ret = 0;
  573. break;
  574. }
  575. }
  576. mutex_unlock(&i40e_device_mutex);
  577. return ret;
  578. }
  579. /**
  580. * i40e_client_release - release client specific resources
  581. * @client: pointer to the registered client
  582. *
  583. * Return 0 on success or < 0 on error
  584. **/
  585. static int i40e_client_release(struct i40e_client *client)
  586. {
  587. struct i40e_client_instance *cdev, *tmp;
  588. struct i40e_pf *pf;
  589. int ret = 0;
  590. LIST_HEAD(cdevs_tmp);
  591. mutex_lock(&i40e_client_instance_mutex);
  592. list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
  593. if (strncmp(cdev->client->name, client->name,
  594. I40E_CLIENT_STR_LENGTH))
  595. continue;
  596. pf = (struct i40e_pf *)cdev->lan_info.pf;
  597. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  598. if (client->ops && client->ops->close)
  599. client->ops->close(&cdev->lan_info, client,
  600. false);
  601. i40e_client_release_qvlist(&cdev->lan_info);
  602. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  603. dev_warn(&pf->pdev->dev,
  604. "Client %s instance for PF id %d closed\n",
  605. client->name, pf->hw.pf_id);
  606. }
  607. /* delete the client instance from the list */
  608. list_move(&cdev->list, &cdevs_tmp);
  609. dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
  610. client->name);
  611. }
  612. mutex_unlock(&i40e_client_instance_mutex);
  613. /* free the client device and release its vsi */
  614. list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
  615. kfree(cdev);
  616. }
  617. return ret;
  618. }
  619. /**
  620. * i40e_client_prepare - prepare client specific resources
  621. * @client: pointer to the registered client
  622. *
  623. * Return 0 on success or < 0 on error
  624. **/
  625. static int i40e_client_prepare(struct i40e_client *client)
  626. {
  627. struct i40e_device *ldev;
  628. struct i40e_pf *pf;
  629. int ret = 0;
  630. mutex_lock(&i40e_device_mutex);
  631. list_for_each_entry(ldev, &i40e_devices, list) {
  632. pf = ldev->pf;
  633. /* Start the client subtask */
  634. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  635. i40e_service_event_schedule(pf);
  636. }
  637. mutex_unlock(&i40e_device_mutex);
  638. return ret;
  639. }
  640. /**
  641. * i40e_client_virtchnl_send - TBD
  642. * @ldev: pointer to L2 context
  643. * @client: Client pointer
  644. * @vf_id: absolute VF identifier
  645. * @msg: message buffer
  646. * @len: length of message buffer
  647. *
  648. * Return 0 on success or < 0 on error
  649. **/
  650. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  651. struct i40e_client *client,
  652. u32 vf_id, u8 *msg, u16 len)
  653. {
  654. struct i40e_pf *pf = ldev->pf;
  655. struct i40e_hw *hw = &pf->hw;
  656. i40e_status err;
  657. err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
  658. 0, msg, len, NULL);
  659. if (err)
  660. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  661. err, hw->aq.asq_last_status);
  662. return err;
  663. }
  664. /**
  665. * i40e_client_setup_qvlist
  666. * @ldev: pointer to L2 context.
  667. * @client: Client pointer.
  668. * @qv_info: queue and vector list
  669. *
  670. * Return 0 on success or < 0 on error
  671. **/
  672. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  673. struct i40e_client *client,
  674. struct i40e_qvlist_info *qvlist_info)
  675. {
  676. struct i40e_pf *pf = ldev->pf;
  677. struct i40e_hw *hw = &pf->hw;
  678. struct i40e_qv_info *qv_info;
  679. u32 v_idx, i, reg_idx, reg;
  680. u32 size;
  681. size = sizeof(struct i40e_qvlist_info) +
  682. (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
  683. ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
  684. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  685. for (i = 0; i < qvlist_info->num_vectors; i++) {
  686. qv_info = &qvlist_info->qv_info[i];
  687. if (!qv_info)
  688. continue;
  689. v_idx = qv_info->v_idx;
  690. /* Validate vector id belongs to this client */
  691. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  692. (v_idx < pf->iwarp_base_vector))
  693. goto err;
  694. ldev->qvlist_info->qv_info[i] = *qv_info;
  695. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  696. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  697. /* Special case - No CEQ mapped on this vector */
  698. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  699. } else {
  700. reg = (qv_info->ceq_idx &
  701. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  702. (I40E_QUEUE_TYPE_PE_CEQ <<
  703. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  704. wr32(hw, reg_idx, reg);
  705. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  706. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  707. (qv_info->itr_idx <<
  708. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  709. (I40E_QUEUE_END_OF_LIST <<
  710. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  711. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  712. }
  713. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  714. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  715. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  716. (qv_info->itr_idx <<
  717. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  718. wr32(hw, I40E_PFINT_AEQCTL, reg);
  719. }
  720. }
  721. /* Mitigate sync problems with iwarp VF driver */
  722. i40e_flush(hw);
  723. return 0;
  724. err:
  725. kfree(ldev->qvlist_info);
  726. ldev->qvlist_info = NULL;
  727. return -EINVAL;
  728. }
  729. /**
  730. * i40e_client_request_reset
  731. * @ldev: pointer to L2 context.
  732. * @client: Client pointer.
  733. * @level: reset level
  734. **/
  735. static void i40e_client_request_reset(struct i40e_info *ldev,
  736. struct i40e_client *client,
  737. u32 reset_level)
  738. {
  739. struct i40e_pf *pf = ldev->pf;
  740. switch (reset_level) {
  741. case I40E_CLIENT_RESET_LEVEL_PF:
  742. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  743. break;
  744. case I40E_CLIENT_RESET_LEVEL_CORE:
  745. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  746. break;
  747. default:
  748. dev_warn(&pf->pdev->dev,
  749. "Client %s instance for PF id %d request an unsupported reset: %d.\n",
  750. client->name, pf->hw.pf_id, reset_level);
  751. break;
  752. }
  753. i40e_service_event_schedule(pf);
  754. }
  755. /**
  756. * i40e_client_update_vsi_ctxt
  757. * @ldev: pointer to L2 context.
  758. * @client: Client pointer.
  759. * @is_vf: if this for the VF
  760. * @vf_id: if is_vf true this carries the vf_id
  761. * @flag: Any device level setting that needs to be done for PE
  762. * @valid_flag: Bits in this match up and enable changing of flag bits
  763. *
  764. * Return 0 on success or < 0 on error
  765. **/
  766. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  767. struct i40e_client *client,
  768. bool is_vf, u32 vf_id,
  769. u32 flag, u32 valid_flag)
  770. {
  771. struct i40e_pf *pf = ldev->pf;
  772. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  773. struct i40e_vsi_context ctxt;
  774. bool update = true;
  775. i40e_status err;
  776. /* TODO: for now do not allow setting VF's VSI setting */
  777. if (is_vf)
  778. return -EINVAL;
  779. ctxt.seid = pf->main_vsi_seid;
  780. ctxt.pf_num = pf->hw.pf_id;
  781. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  782. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  783. if (err) {
  784. dev_info(&pf->pdev->dev,
  785. "couldn't get PF vsi config, err %s aq_err %s\n",
  786. i40e_stat_str(&pf->hw, err),
  787. i40e_aq_str(&pf->hw,
  788. pf->hw.aq.asq_last_status));
  789. return -ENOENT;
  790. }
  791. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  792. (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  793. ctxt.info.valid_sections =
  794. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  795. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  796. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  797. !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  798. ctxt.info.valid_sections =
  799. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  800. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  801. } else {
  802. update = false;
  803. dev_warn(&pf->pdev->dev,
  804. "Client %s instance for PF id %d request an unsupported Config: %x.\n",
  805. client->name, pf->hw.pf_id, flag);
  806. }
  807. if (update) {
  808. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  809. if (err) {
  810. dev_info(&pf->pdev->dev,
  811. "update VSI ctxt for PE failed, err %s aq_err %s\n",
  812. i40e_stat_str(&pf->hw, err),
  813. i40e_aq_str(&pf->hw,
  814. pf->hw.aq.asq_last_status));
  815. }
  816. }
  817. return err;
  818. }
  819. /**
  820. * i40e_register_client - Register a i40e client driver with the L2 driver
  821. * @client: pointer to the i40e_client struct
  822. *
  823. * Returns 0 on success or non-0 on error
  824. **/
  825. int i40e_register_client(struct i40e_client *client)
  826. {
  827. int ret = 0;
  828. enum i40e_vsi_type vsi_type;
  829. if (!client) {
  830. ret = -EIO;
  831. goto out;
  832. }
  833. if (strlen(client->name) == 0) {
  834. pr_info("i40e: Failed to register client with no name\n");
  835. ret = -EIO;
  836. goto out;
  837. }
  838. mutex_lock(&i40e_client_mutex);
  839. if (i40e_client_is_registered(client)) {
  840. pr_info("i40e: Client %s has already been registered!\n",
  841. client->name);
  842. mutex_unlock(&i40e_client_mutex);
  843. ret = -EEXIST;
  844. goto out;
  845. }
  846. if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
  847. (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
  848. pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
  849. client->name);
  850. pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
  851. client->version.major, client->version.minor,
  852. client->version.build,
  853. i40e_client_interface_version_str);
  854. mutex_unlock(&i40e_client_mutex);
  855. ret = -EIO;
  856. goto out;
  857. }
  858. vsi_type = i40e_client_type_to_vsi_type(client->type);
  859. if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
  860. pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
  861. client->name, client->type);
  862. mutex_unlock(&i40e_client_mutex);
  863. ret = -EIO;
  864. goto out;
  865. }
  866. list_add(&client->list, &i40e_clients);
  867. set_bit(__I40E_CLIENT_REGISTERED, &client->state);
  868. mutex_unlock(&i40e_client_mutex);
  869. if (i40e_client_prepare(client)) {
  870. ret = -EIO;
  871. goto out;
  872. }
  873. pr_info("i40e: Registered client %s with return code %d\n",
  874. client->name, ret);
  875. out:
  876. return ret;
  877. }
  878. EXPORT_SYMBOL(i40e_register_client);
  879. /**
  880. * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
  881. * @client: pointer to the i40e_client struct
  882. *
  883. * Returns 0 on success or non-0 on error
  884. **/
  885. int i40e_unregister_client(struct i40e_client *client)
  886. {
  887. int ret = 0;
  888. /* When a unregister request comes through we would have to send
  889. * a close for each of the client instances that were opened.
  890. * client_release function is called to handle this.
  891. */
  892. mutex_lock(&i40e_client_mutex);
  893. if (!client || i40e_client_release(client)) {
  894. ret = -EIO;
  895. goto out;
  896. }
  897. /* TODO: check if device is in reset, or if that matters? */
  898. if (!i40e_client_is_registered(client)) {
  899. pr_info("i40e: Client %s has not been registered\n",
  900. client->name);
  901. ret = -ENODEV;
  902. goto out;
  903. }
  904. clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
  905. list_del(&client->list);
  906. pr_info("i40e: Unregistered client %s with return code %d\n",
  907. client->name, ret);
  908. out:
  909. mutex_unlock(&i40e_client_mutex);
  910. return ret;
  911. }
  912. EXPORT_SYMBOL(i40e_unregister_client);