i40evf_virtchnl.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2014 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. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Contact Information:
  19. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *
  22. ******************************************************************************/
  23. #include "i40evf.h"
  24. #include "i40e_prototype.h"
  25. /* busy wait delay in msec */
  26. #define I40EVF_BUSY_WAIT_DELAY 10
  27. #define I40EVF_BUSY_WAIT_COUNT 50
  28. /**
  29. * i40evf_send_pf_msg
  30. * @adapter: adapter structure
  31. * @op: virtual channel opcode
  32. * @msg: pointer to message buffer
  33. * @len: message length
  34. *
  35. * Send message to PF and print status if failure.
  36. **/
  37. static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
  38. enum i40e_virtchnl_ops op, u8 *msg, u16 len)
  39. {
  40. struct i40e_hw *hw = &adapter->hw;
  41. i40e_status err;
  42. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
  43. return 0; /* nothing to see here, move along */
  44. err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
  45. if (err)
  46. dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, error %d, aq status %d\n",
  47. op, err, hw->aq.asq_last_status);
  48. return err;
  49. }
  50. /**
  51. * i40evf_send_api_ver
  52. * @adapter: adapter structure
  53. *
  54. * Send API version admin queue message to the PF. The reply is not checked
  55. * in this function. Returns 0 if the message was successfully
  56. * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  57. **/
  58. int i40evf_send_api_ver(struct i40evf_adapter *adapter)
  59. {
  60. struct i40e_virtchnl_version_info vvi;
  61. vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
  62. vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
  63. return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
  64. sizeof(vvi));
  65. }
  66. /**
  67. * i40evf_verify_api_ver
  68. * @adapter: adapter structure
  69. *
  70. * Compare API versions with the PF. Must be called after admin queue is
  71. * initialized. Returns 0 if API versions match, -EIO if
  72. * they do not, or I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty.
  73. **/
  74. int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
  75. {
  76. struct i40e_virtchnl_version_info *pf_vvi;
  77. struct i40e_hw *hw = &adapter->hw;
  78. struct i40e_arq_event_info event;
  79. i40e_status err;
  80. event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
  81. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  82. if (!event.msg_buf) {
  83. err = -ENOMEM;
  84. goto out;
  85. }
  86. err = i40evf_clean_arq_element(hw, &event, NULL);
  87. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  88. goto out_alloc;
  89. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  90. if (err) {
  91. err = -EIO;
  92. goto out_alloc;
  93. }
  94. if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
  95. I40E_VIRTCHNL_OP_VERSION) {
  96. err = -EIO;
  97. goto out_alloc;
  98. }
  99. pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
  100. if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) ||
  101. (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR))
  102. err = -EIO;
  103. out_alloc:
  104. kfree(event.msg_buf);
  105. out:
  106. return err;
  107. }
  108. /**
  109. * i40evf_send_vf_config_msg
  110. * @adapter: adapter structure
  111. *
  112. * Send VF configuration request admin queue message to the PF. The reply
  113. * is not checked in this function. Returns 0 if the message was
  114. * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  115. **/
  116. int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
  117. {
  118. return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  119. NULL, 0);
  120. }
  121. /**
  122. * i40evf_get_vf_config
  123. * @hw: pointer to the hardware structure
  124. * @len: length of buffer
  125. *
  126. * Get VF configuration from PF and populate hw structure. Must be called after
  127. * admin queue is initialized. Busy waits until response is received from PF,
  128. * with maximum timeout. Response from PF is returned in the buffer for further
  129. * processing by the caller.
  130. **/
  131. int i40evf_get_vf_config(struct i40evf_adapter *adapter)
  132. {
  133. struct i40e_hw *hw = &adapter->hw;
  134. struct i40e_arq_event_info event;
  135. u16 len;
  136. i40e_status err;
  137. len = sizeof(struct i40e_virtchnl_vf_resource) +
  138. I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
  139. event.msg_size = len;
  140. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  141. if (!event.msg_buf) {
  142. err = -ENOMEM;
  143. goto out;
  144. }
  145. err = i40evf_clean_arq_element(hw, &event, NULL);
  146. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  147. goto out_alloc;
  148. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  149. if (err) {
  150. dev_err(&adapter->pdev->dev,
  151. "%s: Error returned from PF, %d, %d\n", __func__,
  152. le32_to_cpu(event.desc.cookie_high),
  153. le32_to_cpu(event.desc.cookie_low));
  154. err = -EIO;
  155. goto out_alloc;
  156. }
  157. if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
  158. I40E_VIRTCHNL_OP_GET_VF_RESOURCES) {
  159. dev_err(&adapter->pdev->dev,
  160. "%s: Invalid response from PF, %d, %d\n", __func__,
  161. le32_to_cpu(event.desc.cookie_high),
  162. le32_to_cpu(event.desc.cookie_low));
  163. err = -EIO;
  164. goto out_alloc;
  165. }
  166. memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len));
  167. i40e_vf_parse_hw_config(hw, adapter->vf_res);
  168. out_alloc:
  169. kfree(event.msg_buf);
  170. out:
  171. return err;
  172. }
  173. /**
  174. * i40evf_configure_queues
  175. * @adapter: adapter structure
  176. *
  177. * Request that the PF set up our (previously allocated) queues.
  178. **/
  179. void i40evf_configure_queues(struct i40evf_adapter *adapter)
  180. {
  181. struct i40e_virtchnl_vsi_queue_config_info *vqci;
  182. struct i40e_virtchnl_queue_pair_info *vqpi;
  183. int pairs = adapter->vsi_res->num_queue_pairs;
  184. int i, len;
  185. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  186. /* bail because we already have a command pending */
  187. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  188. __func__, adapter->current_op);
  189. return;
  190. }
  191. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
  192. len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
  193. (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
  194. vqci = kzalloc(len, GFP_ATOMIC);
  195. if (!vqci) {
  196. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  197. __func__);
  198. return;
  199. }
  200. vqci->vsi_id = adapter->vsi_res->vsi_id;
  201. vqci->num_queue_pairs = pairs;
  202. vqpi = vqci->qpair;
  203. /* Size check is not needed here - HW max is 16 queue pairs, and we
  204. * can fit info for 31 of them into the AQ buffer before it overflows.
  205. */
  206. for (i = 0; i < pairs; i++) {
  207. vqpi->txq.vsi_id = vqci->vsi_id;
  208. vqpi->txq.queue_id = i;
  209. vqpi->txq.ring_len = adapter->tx_rings[i]->count;
  210. vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
  211. vqpi->rxq.vsi_id = vqci->vsi_id;
  212. vqpi->rxq.queue_id = i;
  213. vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
  214. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
  215. vqpi->rxq.max_pkt_size = adapter->netdev->mtu
  216. + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
  217. vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
  218. vqpi++;
  219. }
  220. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  221. (u8 *)vqci, len);
  222. kfree(vqci);
  223. adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  224. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  225. }
  226. /**
  227. * i40evf_enable_queues
  228. * @adapter: adapter structure
  229. *
  230. * Request that the PF enable all of our queues.
  231. **/
  232. void i40evf_enable_queues(struct i40evf_adapter *adapter)
  233. {
  234. struct i40e_virtchnl_queue_select vqs;
  235. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  236. /* bail because we already have a command pending */
  237. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  238. __func__, adapter->current_op);
  239. return;
  240. }
  241. adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
  242. vqs.vsi_id = adapter->vsi_res->vsi_id;
  243. vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
  244. vqs.rx_queues = vqs.tx_queues;
  245. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  246. (u8 *)&vqs, sizeof(vqs));
  247. adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
  248. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  249. }
  250. /**
  251. * i40evf_disable_queues
  252. * @adapter: adapter structure
  253. *
  254. * Request that the PF disable all of our queues.
  255. **/
  256. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  257. {
  258. struct i40e_virtchnl_queue_select vqs;
  259. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  260. /* bail because we already have a command pending */
  261. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  262. __func__, adapter->current_op);
  263. return;
  264. }
  265. adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
  266. vqs.vsi_id = adapter->vsi_res->vsi_id;
  267. vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
  268. vqs.rx_queues = vqs.tx_queues;
  269. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  270. (u8 *)&vqs, sizeof(vqs));
  271. adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
  272. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  273. }
  274. /**
  275. * i40evf_map_queues
  276. * @adapter: adapter structure
  277. *
  278. * Request that the PF map queues to interrupt vectors. Misc causes, including
  279. * admin queue, are always mapped to vector 0.
  280. **/
  281. void i40evf_map_queues(struct i40evf_adapter *adapter)
  282. {
  283. struct i40e_virtchnl_irq_map_info *vimi;
  284. int v_idx, q_vectors, len;
  285. struct i40e_q_vector *q_vector;
  286. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  287. /* bail because we already have a command pending */
  288. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  289. __func__, adapter->current_op);
  290. return;
  291. }
  292. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
  293. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  294. len = sizeof(struct i40e_virtchnl_irq_map_info) +
  295. (adapter->num_msix_vectors *
  296. sizeof(struct i40e_virtchnl_vector_map));
  297. vimi = kzalloc(len, GFP_ATOMIC);
  298. if (!vimi) {
  299. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  300. __func__);
  301. return;
  302. }
  303. vimi->num_vectors = adapter->num_msix_vectors;
  304. /* Queue vectors first */
  305. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  306. q_vector = adapter->q_vector[v_idx];
  307. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  308. vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
  309. vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
  310. vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
  311. }
  312. /* Misc vector last - this is only for AdminQ messages */
  313. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  314. vimi->vecmap[v_idx].vector_id = 0;
  315. vimi->vecmap[v_idx].txq_map = 0;
  316. vimi->vecmap[v_idx].rxq_map = 0;
  317. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  318. (u8 *)vimi, len);
  319. kfree(vimi);
  320. adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS;
  321. adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
  322. }
  323. /**
  324. * i40evf_add_ether_addrs
  325. * @adapter: adapter structure
  326. * @addrs: the MAC address filters to add (contiguous)
  327. * @count: number of filters
  328. *
  329. * Request that the PF add one or more addresses to our filters.
  330. **/
  331. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
  332. {
  333. struct i40e_virtchnl_ether_addr_list *veal;
  334. int len, i = 0, count = 0;
  335. struct i40evf_mac_filter *f;
  336. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  337. /* bail because we already have a command pending */
  338. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  339. __func__, adapter->current_op);
  340. return;
  341. }
  342. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  343. if (f->add)
  344. count++;
  345. }
  346. if (!count) {
  347. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  348. return;
  349. }
  350. adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
  351. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  352. (count * sizeof(struct i40e_virtchnl_ether_addr));
  353. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  354. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
  355. __func__);
  356. count = (I40EVF_MAX_AQ_BUF_SIZE -
  357. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  358. sizeof(struct i40e_virtchnl_ether_addr);
  359. len = I40EVF_MAX_AQ_BUF_SIZE;
  360. }
  361. veal = kzalloc(len, GFP_ATOMIC);
  362. if (!veal) {
  363. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  364. __func__);
  365. return;
  366. }
  367. veal->vsi_id = adapter->vsi_res->vsi_id;
  368. veal->num_elements = count;
  369. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  370. if (f->add) {
  371. memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
  372. i++;
  373. f->add = false;
  374. }
  375. }
  376. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  377. (u8 *)veal, len);
  378. kfree(veal);
  379. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  380. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  381. }
  382. /**
  383. * i40evf_del_ether_addrs
  384. * @adapter: adapter structure
  385. * @addrs: the MAC address filters to remove (contiguous)
  386. * @count: number of filtes
  387. *
  388. * Request that the PF remove one or more addresses from our filters.
  389. **/
  390. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  391. {
  392. struct i40e_virtchnl_ether_addr_list *veal;
  393. struct i40evf_mac_filter *f, *ftmp;
  394. int len, i = 0, count = 0;
  395. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  396. /* bail because we already have a command pending */
  397. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  398. __func__, adapter->current_op);
  399. return;
  400. }
  401. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  402. if (f->remove)
  403. count++;
  404. }
  405. if (!count) {
  406. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  407. return;
  408. }
  409. adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
  410. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  411. (count * sizeof(struct i40e_virtchnl_ether_addr));
  412. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  413. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
  414. __func__);
  415. count = (I40EVF_MAX_AQ_BUF_SIZE -
  416. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  417. sizeof(struct i40e_virtchnl_ether_addr);
  418. len = I40EVF_MAX_AQ_BUF_SIZE;
  419. }
  420. veal = kzalloc(len, GFP_ATOMIC);
  421. if (!veal) {
  422. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  423. __func__);
  424. return;
  425. }
  426. veal->vsi_id = adapter->vsi_res->vsi_id;
  427. veal->num_elements = count;
  428. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  429. if (f->remove) {
  430. memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
  431. i++;
  432. list_del(&f->list);
  433. kfree(f);
  434. }
  435. }
  436. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  437. (u8 *)veal, len);
  438. kfree(veal);
  439. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  440. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  441. }
  442. /**
  443. * i40evf_add_vlans
  444. * @adapter: adapter structure
  445. * @vlans: the VLANs to add
  446. * @count: number of VLANs
  447. *
  448. * Request that the PF add one or more VLAN filters to our VSI.
  449. **/
  450. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  451. {
  452. struct i40e_virtchnl_vlan_filter_list *vvfl;
  453. int len, i = 0, count = 0;
  454. struct i40evf_vlan_filter *f;
  455. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  456. /* bail because we already have a command pending */
  457. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  458. __func__, adapter->current_op);
  459. return;
  460. }
  461. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  462. if (f->add)
  463. count++;
  464. }
  465. if (!count) {
  466. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  467. return;
  468. }
  469. adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
  470. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  471. (count * sizeof(u16));
  472. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  473. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
  474. __func__);
  475. count = (I40EVF_MAX_AQ_BUF_SIZE -
  476. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  477. sizeof(u16);
  478. len = I40EVF_MAX_AQ_BUF_SIZE;
  479. }
  480. vvfl = kzalloc(len, GFP_ATOMIC);
  481. if (!vvfl) {
  482. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  483. __func__);
  484. return;
  485. }
  486. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  487. vvfl->num_elements = count;
  488. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  489. if (f->add) {
  490. vvfl->vlan_id[i] = f->vlan;
  491. i++;
  492. f->add = false;
  493. }
  494. }
  495. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  496. kfree(vvfl);
  497. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  498. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  499. }
  500. /**
  501. * i40evf_del_vlans
  502. * @adapter: adapter structure
  503. * @vlans: the VLANs to remove
  504. * @count: number of VLANs
  505. *
  506. * Request that the PF remove one or more VLAN filters from our VSI.
  507. **/
  508. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  509. {
  510. struct i40e_virtchnl_vlan_filter_list *vvfl;
  511. struct i40evf_vlan_filter *f, *ftmp;
  512. int len, i = 0, count = 0;
  513. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  514. /* bail because we already have a command pending */
  515. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  516. __func__, adapter->current_op);
  517. return;
  518. }
  519. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  520. if (f->remove)
  521. count++;
  522. }
  523. if (!count) {
  524. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  525. return;
  526. }
  527. adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
  528. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  529. (count * sizeof(u16));
  530. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  531. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
  532. __func__);
  533. count = (I40EVF_MAX_AQ_BUF_SIZE -
  534. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  535. sizeof(u16);
  536. len = I40EVF_MAX_AQ_BUF_SIZE;
  537. }
  538. vvfl = kzalloc(len, GFP_ATOMIC);
  539. if (!vvfl) {
  540. dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
  541. __func__);
  542. return;
  543. }
  544. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  545. vvfl->num_elements = count;
  546. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  547. if (f->remove) {
  548. vvfl->vlan_id[i] = f->vlan;
  549. i++;
  550. list_del(&f->list);
  551. kfree(f);
  552. }
  553. }
  554. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  555. kfree(vvfl);
  556. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  557. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  558. }
  559. /**
  560. * i40evf_set_promiscuous
  561. * @adapter: adapter structure
  562. * @flags: bitmask to control unicast/multicast promiscuous.
  563. *
  564. * Request that the PF enable promiscuous mode for our VSI.
  565. **/
  566. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  567. {
  568. struct i40e_virtchnl_promisc_info vpi;
  569. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  570. /* bail because we already have a command pending */
  571. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  572. __func__, adapter->current_op);
  573. return;
  574. }
  575. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  576. vpi.vsi_id = adapter->vsi_res->vsi_id;
  577. vpi.flags = flags;
  578. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  579. (u8 *)&vpi, sizeof(vpi));
  580. }
  581. /**
  582. * i40evf_request_stats
  583. * @adapter: adapter structure
  584. *
  585. * Request VSI statistics from PF.
  586. **/
  587. void i40evf_request_stats(struct i40evf_adapter *adapter)
  588. {
  589. struct i40e_virtchnl_queue_select vqs;
  590. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  591. /* no error message, this isn't crucial */
  592. return;
  593. }
  594. adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
  595. vqs.vsi_id = adapter->vsi_res->vsi_id;
  596. /* queue maps are ignored for this message - only the vsi is used */
  597. if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
  598. (u8 *)&vqs, sizeof(vqs)))
  599. /* if the request failed, don't lock out others */
  600. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  601. }
  602. /**
  603. * i40evf_request_reset
  604. * @adapter: adapter structure
  605. *
  606. * Request that the PF reset this VF. No response is expected.
  607. **/
  608. void i40evf_request_reset(struct i40evf_adapter *adapter)
  609. {
  610. /* Don't check CURRENT_OP - this is always higher priority */
  611. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  612. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  613. }
  614. /**
  615. * i40evf_virtchnl_completion
  616. * @adapter: adapter structure
  617. * @v_opcode: opcode sent by PF
  618. * @v_retval: retval sent by PF
  619. * @msg: message sent by PF
  620. * @msglen: message length
  621. *
  622. * Asynchronous completion function for admin queue messages. Rather than busy
  623. * wait, we fire off our requests and assume that no errors will be returned.
  624. * This function handles the reply messages.
  625. **/
  626. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  627. enum i40e_virtchnl_ops v_opcode,
  628. i40e_status v_retval,
  629. u8 *msg, u16 msglen)
  630. {
  631. struct net_device *netdev = adapter->netdev;
  632. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  633. struct i40e_virtchnl_pf_event *vpe =
  634. (struct i40e_virtchnl_pf_event *)msg;
  635. switch (vpe->event) {
  636. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  637. adapter->link_up =
  638. vpe->event_data.link_event.link_status;
  639. if (adapter->link_up && !netif_carrier_ok(netdev)) {
  640. dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
  641. netif_carrier_on(netdev);
  642. netif_tx_wake_all_queues(netdev);
  643. } else if (!adapter->link_up) {
  644. dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
  645. netif_carrier_off(netdev);
  646. netif_tx_stop_all_queues(netdev);
  647. }
  648. break;
  649. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  650. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  651. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  652. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  653. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  654. schedule_work(&adapter->reset_task);
  655. }
  656. break;
  657. default:
  658. dev_err(&adapter->pdev->dev,
  659. "%s: Unknown event %d from pf\n",
  660. __func__, vpe->event);
  661. break;
  662. }
  663. return;
  664. }
  665. if (v_opcode != adapter->current_op) {
  666. dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d.\n",
  667. __func__, adapter->current_op, v_opcode);
  668. /* We're probably completely screwed at this point, but clear
  669. * the current op and try to carry on....
  670. */
  671. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  672. return;
  673. }
  674. if (v_retval) {
  675. dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d!\n",
  676. __func__, v_retval, v_opcode);
  677. }
  678. switch (v_opcode) {
  679. case I40E_VIRTCHNL_OP_GET_STATS: {
  680. struct i40e_eth_stats *stats =
  681. (struct i40e_eth_stats *)msg;
  682. adapter->net_stats.rx_packets = stats->rx_unicast +
  683. stats->rx_multicast +
  684. stats->rx_broadcast;
  685. adapter->net_stats.tx_packets = stats->tx_unicast +
  686. stats->tx_multicast +
  687. stats->tx_broadcast;
  688. adapter->net_stats.rx_bytes = stats->rx_bytes;
  689. adapter->net_stats.tx_bytes = stats->tx_bytes;
  690. adapter->net_stats.rx_errors = stats->rx_errors;
  691. adapter->net_stats.tx_errors = stats->tx_errors;
  692. adapter->net_stats.rx_dropped = stats->rx_missed;
  693. adapter->net_stats.tx_dropped = stats->tx_discards;
  694. adapter->current_stats = *stats;
  695. }
  696. break;
  697. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  698. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER);
  699. break;
  700. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  701. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER);
  702. break;
  703. case I40E_VIRTCHNL_OP_ADD_VLAN:
  704. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER);
  705. break;
  706. case I40E_VIRTCHNL_OP_DEL_VLAN:
  707. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER);
  708. break;
  709. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  710. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES);
  711. /* enable transmits */
  712. i40evf_irq_enable(adapter, true);
  713. netif_tx_start_all_queues(adapter->netdev);
  714. netif_carrier_on(adapter->netdev);
  715. break;
  716. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  717. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES);
  718. break;
  719. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  720. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
  721. break;
  722. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  723. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
  724. break;
  725. default:
  726. dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF.\n",
  727. __func__, v_opcode);
  728. break;
  729. } /* switch v_opcode */
  730. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  731. }