i40evf_virtchnl.c 23 KB

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