i40evf_virtchnl.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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->txq.headwb_enabled = 1;
  212. vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
  213. (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
  214. vqpi->rxq.vsi_id = vqci->vsi_id;
  215. vqpi->rxq.queue_id = i;
  216. vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
  217. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
  218. vqpi->rxq.max_pkt_size = adapter->netdev->mtu
  219. + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
  220. vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
  221. vqpi++;
  222. }
  223. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  224. (u8 *)vqci, len);
  225. kfree(vqci);
  226. adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  227. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  228. }
  229. /**
  230. * i40evf_enable_queues
  231. * @adapter: adapter structure
  232. *
  233. * Request that the PF enable all of our queues.
  234. **/
  235. void i40evf_enable_queues(struct i40evf_adapter *adapter)
  236. {
  237. struct i40e_virtchnl_queue_select vqs;
  238. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  239. /* bail because we already have a command pending */
  240. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  241. __func__, adapter->current_op);
  242. return;
  243. }
  244. adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
  245. vqs.vsi_id = adapter->vsi_res->vsi_id;
  246. vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
  247. vqs.rx_queues = vqs.tx_queues;
  248. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  249. (u8 *)&vqs, sizeof(vqs));
  250. adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
  251. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  252. }
  253. /**
  254. * i40evf_disable_queues
  255. * @adapter: adapter structure
  256. *
  257. * Request that the PF disable all of our queues.
  258. **/
  259. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  260. {
  261. struct i40e_virtchnl_queue_select vqs;
  262. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  263. /* bail because we already have a command pending */
  264. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  265. __func__, adapter->current_op);
  266. return;
  267. }
  268. adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
  269. vqs.vsi_id = adapter->vsi_res->vsi_id;
  270. vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
  271. vqs.rx_queues = vqs.tx_queues;
  272. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  273. (u8 *)&vqs, sizeof(vqs));
  274. adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
  275. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  276. }
  277. /**
  278. * i40evf_map_queues
  279. * @adapter: adapter structure
  280. *
  281. * Request that the PF map queues to interrupt vectors. Misc causes, including
  282. * admin queue, are always mapped to vector 0.
  283. **/
  284. void i40evf_map_queues(struct i40evf_adapter *adapter)
  285. {
  286. struct i40e_virtchnl_irq_map_info *vimi;
  287. int v_idx, q_vectors, len;
  288. struct i40e_q_vector *q_vector;
  289. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  290. /* bail because we already have a command pending */
  291. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  292. __func__, adapter->current_op);
  293. return;
  294. }
  295. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
  296. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  297. len = sizeof(struct i40e_virtchnl_irq_map_info) +
  298. (adapter->num_msix_vectors *
  299. sizeof(struct i40e_virtchnl_vector_map));
  300. vimi = kzalloc(len, GFP_ATOMIC);
  301. if (!vimi)
  302. return;
  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. return;
  364. veal->vsi_id = adapter->vsi_res->vsi_id;
  365. veal->num_elements = count;
  366. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  367. if (f->add) {
  368. ether_addr_copy(veal->list[i].addr, f->macaddr);
  369. i++;
  370. f->add = false;
  371. }
  372. }
  373. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  374. (u8 *)veal, len);
  375. kfree(veal);
  376. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  377. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  378. }
  379. /**
  380. * i40evf_del_ether_addrs
  381. * @adapter: adapter structure
  382. * @addrs: the MAC address filters to remove (contiguous)
  383. * @count: number of filtes
  384. *
  385. * Request that the PF remove one or more addresses from our filters.
  386. **/
  387. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  388. {
  389. struct i40e_virtchnl_ether_addr_list *veal;
  390. struct i40evf_mac_filter *f, *ftmp;
  391. int len, i = 0, count = 0;
  392. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  393. /* bail because we already have a command pending */
  394. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  395. __func__, adapter->current_op);
  396. return;
  397. }
  398. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  399. if (f->remove)
  400. count++;
  401. }
  402. if (!count) {
  403. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  404. return;
  405. }
  406. adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
  407. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  408. (count * sizeof(struct i40e_virtchnl_ether_addr));
  409. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  410. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
  411. __func__);
  412. count = (I40EVF_MAX_AQ_BUF_SIZE -
  413. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  414. sizeof(struct i40e_virtchnl_ether_addr);
  415. len = I40EVF_MAX_AQ_BUF_SIZE;
  416. }
  417. veal = kzalloc(len, GFP_ATOMIC);
  418. if (!veal)
  419. return;
  420. veal->vsi_id = adapter->vsi_res->vsi_id;
  421. veal->num_elements = count;
  422. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  423. if (f->remove) {
  424. ether_addr_copy(veal->list[i].addr, f->macaddr);
  425. i++;
  426. list_del(&f->list);
  427. kfree(f);
  428. }
  429. }
  430. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  431. (u8 *)veal, len);
  432. kfree(veal);
  433. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  434. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  435. }
  436. /**
  437. * i40evf_add_vlans
  438. * @adapter: adapter structure
  439. * @vlans: the VLANs to add
  440. * @count: number of VLANs
  441. *
  442. * Request that the PF add one or more VLAN filters to our VSI.
  443. **/
  444. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  445. {
  446. struct i40e_virtchnl_vlan_filter_list *vvfl;
  447. int len, i = 0, count = 0;
  448. struct i40evf_vlan_filter *f;
  449. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  450. /* bail because we already have a command pending */
  451. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  452. __func__, adapter->current_op);
  453. return;
  454. }
  455. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  456. if (f->add)
  457. count++;
  458. }
  459. if (!count) {
  460. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  461. return;
  462. }
  463. adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
  464. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  465. (count * sizeof(u16));
  466. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  467. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
  468. __func__);
  469. count = (I40EVF_MAX_AQ_BUF_SIZE -
  470. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  471. sizeof(u16);
  472. len = I40EVF_MAX_AQ_BUF_SIZE;
  473. }
  474. vvfl = kzalloc(len, GFP_ATOMIC);
  475. if (!vvfl)
  476. return;
  477. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  478. vvfl->num_elements = count;
  479. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  480. if (f->add) {
  481. vvfl->vlan_id[i] = f->vlan;
  482. i++;
  483. f->add = false;
  484. }
  485. }
  486. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  487. kfree(vvfl);
  488. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  489. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  490. }
  491. /**
  492. * i40evf_del_vlans
  493. * @adapter: adapter structure
  494. * @vlans: the VLANs to remove
  495. * @count: number of VLANs
  496. *
  497. * Request that the PF remove one or more VLAN filters from our VSI.
  498. **/
  499. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  500. {
  501. struct i40e_virtchnl_vlan_filter_list *vvfl;
  502. struct i40evf_vlan_filter *f, *ftmp;
  503. int len, i = 0, count = 0;
  504. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  505. /* bail because we already have a command pending */
  506. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  507. __func__, adapter->current_op);
  508. return;
  509. }
  510. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  511. if (f->remove)
  512. count++;
  513. }
  514. if (!count) {
  515. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  516. return;
  517. }
  518. adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
  519. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  520. (count * sizeof(u16));
  521. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  522. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
  523. __func__);
  524. count = (I40EVF_MAX_AQ_BUF_SIZE -
  525. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  526. sizeof(u16);
  527. len = I40EVF_MAX_AQ_BUF_SIZE;
  528. }
  529. vvfl = kzalloc(len, GFP_ATOMIC);
  530. if (!vvfl)
  531. return;
  532. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  533. vvfl->num_elements = count;
  534. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  535. if (f->remove) {
  536. vvfl->vlan_id[i] = f->vlan;
  537. i++;
  538. list_del(&f->list);
  539. kfree(f);
  540. }
  541. }
  542. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  543. kfree(vvfl);
  544. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  545. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  546. }
  547. /**
  548. * i40evf_set_promiscuous
  549. * @adapter: adapter structure
  550. * @flags: bitmask to control unicast/multicast promiscuous.
  551. *
  552. * Request that the PF enable promiscuous mode for our VSI.
  553. **/
  554. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  555. {
  556. struct i40e_virtchnl_promisc_info vpi;
  557. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  558. /* bail because we already have a command pending */
  559. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  560. __func__, adapter->current_op);
  561. return;
  562. }
  563. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  564. vpi.vsi_id = adapter->vsi_res->vsi_id;
  565. vpi.flags = flags;
  566. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  567. (u8 *)&vpi, sizeof(vpi));
  568. }
  569. /**
  570. * i40evf_request_stats
  571. * @adapter: adapter structure
  572. *
  573. * Request VSI statistics from PF.
  574. **/
  575. void i40evf_request_stats(struct i40evf_adapter *adapter)
  576. {
  577. struct i40e_virtchnl_queue_select vqs;
  578. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  579. /* no error message, this isn't crucial */
  580. return;
  581. }
  582. adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
  583. vqs.vsi_id = adapter->vsi_res->vsi_id;
  584. /* queue maps are ignored for this message - only the vsi is used */
  585. if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
  586. (u8 *)&vqs, sizeof(vqs)))
  587. /* if the request failed, don't lock out others */
  588. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  589. }
  590. /**
  591. * i40evf_request_reset
  592. * @adapter: adapter structure
  593. *
  594. * Request that the PF reset this VF. No response is expected.
  595. **/
  596. void i40evf_request_reset(struct i40evf_adapter *adapter)
  597. {
  598. /* Don't check CURRENT_OP - this is always higher priority */
  599. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  600. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  601. }
  602. /**
  603. * i40evf_virtchnl_completion
  604. * @adapter: adapter structure
  605. * @v_opcode: opcode sent by PF
  606. * @v_retval: retval sent by PF
  607. * @msg: message sent by PF
  608. * @msglen: message length
  609. *
  610. * Asynchronous completion function for admin queue messages. Rather than busy
  611. * wait, we fire off our requests and assume that no errors will be returned.
  612. * This function handles the reply messages.
  613. **/
  614. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  615. enum i40e_virtchnl_ops v_opcode,
  616. i40e_status v_retval,
  617. u8 *msg, u16 msglen)
  618. {
  619. struct net_device *netdev = adapter->netdev;
  620. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  621. struct i40e_virtchnl_pf_event *vpe =
  622. (struct i40e_virtchnl_pf_event *)msg;
  623. switch (vpe->event) {
  624. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  625. adapter->link_up =
  626. vpe->event_data.link_event.link_status;
  627. if (adapter->link_up && !netif_carrier_ok(netdev)) {
  628. dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
  629. netif_carrier_on(netdev);
  630. netif_tx_wake_all_queues(netdev);
  631. } else if (!adapter->link_up) {
  632. dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
  633. netif_carrier_off(netdev);
  634. netif_tx_stop_all_queues(netdev);
  635. }
  636. break;
  637. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  638. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  639. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  640. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  641. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  642. schedule_work(&adapter->reset_task);
  643. }
  644. break;
  645. default:
  646. dev_err(&adapter->pdev->dev,
  647. "%s: Unknown event %d from pf\n",
  648. __func__, vpe->event);
  649. break;
  650. }
  651. return;
  652. }
  653. if (v_opcode != adapter->current_op) {
  654. dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d\n",
  655. __func__, adapter->current_op, v_opcode);
  656. /* We're probably completely screwed at this point, but clear
  657. * the current op and try to carry on....
  658. */
  659. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  660. return;
  661. }
  662. if (v_retval) {
  663. dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d\n",
  664. __func__, v_retval, v_opcode);
  665. }
  666. switch (v_opcode) {
  667. case I40E_VIRTCHNL_OP_GET_STATS: {
  668. struct i40e_eth_stats *stats =
  669. (struct i40e_eth_stats *)msg;
  670. adapter->net_stats.rx_packets = stats->rx_unicast +
  671. stats->rx_multicast +
  672. stats->rx_broadcast;
  673. adapter->net_stats.tx_packets = stats->tx_unicast +
  674. stats->tx_multicast +
  675. stats->tx_broadcast;
  676. adapter->net_stats.rx_bytes = stats->rx_bytes;
  677. adapter->net_stats.tx_bytes = stats->tx_bytes;
  678. adapter->net_stats.tx_errors = stats->tx_errors;
  679. adapter->net_stats.rx_dropped = stats->rx_discards;
  680. adapter->net_stats.tx_dropped = stats->tx_discards;
  681. adapter->current_stats = *stats;
  682. }
  683. break;
  684. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  685. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER);
  686. break;
  687. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  688. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER);
  689. break;
  690. case I40E_VIRTCHNL_OP_ADD_VLAN:
  691. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER);
  692. break;
  693. case I40E_VIRTCHNL_OP_DEL_VLAN:
  694. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER);
  695. break;
  696. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  697. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES);
  698. /* enable transmits */
  699. i40evf_irq_enable(adapter, true);
  700. netif_tx_start_all_queues(adapter->netdev);
  701. netif_carrier_on(adapter->netdev);
  702. break;
  703. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  704. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES);
  705. break;
  706. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  707. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
  708. break;
  709. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  710. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
  711. break;
  712. default:
  713. dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF\n",
  714. __func__, v_opcode);
  715. break;
  716. } /* switch v_opcode */
  717. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  718. }