i40evf_virtchnl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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 they do not,
  75. * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
  76. * from the firmware are propagated.
  77. **/
  78. int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
  79. {
  80. struct i40e_virtchnl_version_info *pf_vvi;
  81. struct i40e_hw *hw = &adapter->hw;
  82. struct i40e_arq_event_info event;
  83. enum i40e_virtchnl_ops op;
  84. i40e_status err;
  85. event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
  86. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  87. if (!event.msg_buf) {
  88. err = -ENOMEM;
  89. goto out;
  90. }
  91. while (1) {
  92. err = i40evf_clean_arq_element(hw, &event, NULL);
  93. /* When the AQ is empty, i40evf_clean_arq_element will return
  94. * nonzero and this loop will terminate.
  95. */
  96. if (err)
  97. goto out_alloc;
  98. op =
  99. (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  100. if (op == I40E_VIRTCHNL_OP_VERSION)
  101. break;
  102. }
  103. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  104. if (err)
  105. goto out_alloc;
  106. if (op != I40E_VIRTCHNL_OP_VERSION) {
  107. dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
  108. op);
  109. err = -EIO;
  110. goto out_alloc;
  111. }
  112. pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
  113. if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) ||
  114. (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR))
  115. err = -EIO;
  116. out_alloc:
  117. kfree(event.msg_buf);
  118. out:
  119. return err;
  120. }
  121. /**
  122. * i40evf_send_vf_config_msg
  123. * @adapter: adapter structure
  124. *
  125. * Send VF configuration request admin queue message to the PF. The reply
  126. * is not checked in this function. Returns 0 if the message was
  127. * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  128. **/
  129. int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
  130. {
  131. return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  132. NULL, 0);
  133. }
  134. /**
  135. * i40evf_get_vf_config
  136. * @hw: pointer to the hardware structure
  137. * @len: length of buffer
  138. *
  139. * Get VF configuration from PF and populate hw structure. Must be called after
  140. * admin queue is initialized. Busy waits until response is received from PF,
  141. * with maximum timeout. Response from PF is returned in the buffer for further
  142. * processing by the caller.
  143. **/
  144. int i40evf_get_vf_config(struct i40evf_adapter *adapter)
  145. {
  146. struct i40e_hw *hw = &adapter->hw;
  147. struct i40e_arq_event_info event;
  148. enum i40e_virtchnl_ops op;
  149. i40e_status err;
  150. u16 len;
  151. len = sizeof(struct i40e_virtchnl_vf_resource) +
  152. I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
  153. event.buf_len = len;
  154. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  155. if (!event.msg_buf) {
  156. err = -ENOMEM;
  157. goto out;
  158. }
  159. while (1) {
  160. /* When the AQ is empty, i40evf_clean_arq_element will return
  161. * nonzero and this loop will terminate.
  162. */
  163. err = i40evf_clean_arq_element(hw, &event, NULL);
  164. if (err)
  165. goto out_alloc;
  166. op =
  167. (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  168. if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
  169. break;
  170. }
  171. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  172. memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
  173. i40e_vf_parse_hw_config(hw, adapter->vf_res);
  174. out_alloc:
  175. kfree(event.msg_buf);
  176. out:
  177. return err;
  178. }
  179. /**
  180. * i40evf_configure_queues
  181. * @adapter: adapter structure
  182. *
  183. * Request that the PF set up our (previously allocated) queues.
  184. **/
  185. void i40evf_configure_queues(struct i40evf_adapter *adapter)
  186. {
  187. struct i40e_virtchnl_vsi_queue_config_info *vqci;
  188. struct i40e_virtchnl_queue_pair_info *vqpi;
  189. int pairs = adapter->num_active_queues;
  190. int i, len;
  191. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  192. /* bail because we already have a command pending */
  193. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  194. __func__, adapter->current_op);
  195. return;
  196. }
  197. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
  198. len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
  199. (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
  200. vqci = kzalloc(len, GFP_ATOMIC);
  201. if (!vqci)
  202. return;
  203. vqci->vsi_id = adapter->vsi_res->vsi_id;
  204. vqci->num_queue_pairs = pairs;
  205. vqpi = vqci->qpair;
  206. /* Size check is not needed here - HW max is 16 queue pairs, and we
  207. * can fit info for 31 of them into the AQ buffer before it overflows.
  208. */
  209. for (i = 0; i < pairs; i++) {
  210. vqpi->txq.vsi_id = vqci->vsi_id;
  211. vqpi->txq.queue_id = i;
  212. vqpi->txq.ring_len = adapter->tx_rings[i]->count;
  213. vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
  214. vqpi->txq.headwb_enabled = 1;
  215. vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
  216. (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
  217. vqpi->rxq.vsi_id = vqci->vsi_id;
  218. vqpi->rxq.queue_id = i;
  219. vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
  220. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
  221. vqpi->rxq.max_pkt_size = adapter->netdev->mtu
  222. + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
  223. vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
  224. vqpi++;
  225. }
  226. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  227. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  228. (u8 *)vqci, len);
  229. kfree(vqci);
  230. }
  231. /**
  232. * i40evf_enable_queues
  233. * @adapter: adapter structure
  234. *
  235. * Request that the PF enable all of our queues.
  236. **/
  237. void i40evf_enable_queues(struct i40evf_adapter *adapter)
  238. {
  239. struct i40e_virtchnl_queue_select vqs;
  240. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  241. /* bail because we already have a command pending */
  242. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  243. __func__, adapter->current_op);
  244. return;
  245. }
  246. adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
  247. vqs.vsi_id = adapter->vsi_res->vsi_id;
  248. vqs.tx_queues = (1 << adapter->num_active_queues) - 1;
  249. vqs.rx_queues = vqs.tx_queues;
  250. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  251. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  252. (u8 *)&vqs, sizeof(vqs));
  253. }
  254. /**
  255. * i40evf_disable_queues
  256. * @adapter: adapter structure
  257. *
  258. * Request that the PF disable all of our queues.
  259. **/
  260. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  261. {
  262. struct i40e_virtchnl_queue_select vqs;
  263. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  264. /* bail because we already have a command pending */
  265. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  266. __func__, adapter->current_op);
  267. return;
  268. }
  269. adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
  270. vqs.vsi_id = adapter->vsi_res->vsi_id;
  271. vqs.tx_queues = (1 << adapter->num_active_queues) - 1;
  272. vqs.rx_queues = vqs.tx_queues;
  273. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  274. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  275. (u8 *)&vqs, sizeof(vqs));
  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. adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
  318. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  319. (u8 *)vimi, len);
  320. kfree(vimi);
  321. }
  322. /**
  323. * i40evf_add_ether_addrs
  324. * @adapter: adapter structure
  325. * @addrs: the MAC address filters to add (contiguous)
  326. * @count: number of filters
  327. *
  328. * Request that the PF add one or more addresses to our filters.
  329. **/
  330. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
  331. {
  332. struct i40e_virtchnl_ether_addr_list *veal;
  333. int len, i = 0, count = 0;
  334. struct i40evf_mac_filter *f;
  335. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  336. /* bail because we already have a command pending */
  337. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  338. __func__, adapter->current_op);
  339. return;
  340. }
  341. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  342. if (f->add)
  343. count++;
  344. }
  345. if (!count) {
  346. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  347. return;
  348. }
  349. adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
  350. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  351. (count * sizeof(struct i40e_virtchnl_ether_addr));
  352. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  353. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
  354. __func__);
  355. count = (I40EVF_MAX_AQ_BUF_SIZE -
  356. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  357. sizeof(struct i40e_virtchnl_ether_addr);
  358. len = I40EVF_MAX_AQ_BUF_SIZE;
  359. }
  360. veal = kzalloc(len, GFP_ATOMIC);
  361. if (!veal)
  362. return;
  363. veal->vsi_id = adapter->vsi_res->vsi_id;
  364. veal->num_elements = count;
  365. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  366. if (f->add) {
  367. ether_addr_copy(veal->list[i].addr, f->macaddr);
  368. i++;
  369. f->add = false;
  370. }
  371. }
  372. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  373. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  374. (u8 *)veal, len);
  375. kfree(veal);
  376. }
  377. /**
  378. * i40evf_del_ether_addrs
  379. * @adapter: adapter structure
  380. * @addrs: the MAC address filters to remove (contiguous)
  381. * @count: number of filtes
  382. *
  383. * Request that the PF remove one or more addresses from our filters.
  384. **/
  385. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  386. {
  387. struct i40e_virtchnl_ether_addr_list *veal;
  388. struct i40evf_mac_filter *f, *ftmp;
  389. int len, i = 0, count = 0;
  390. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  391. /* bail because we already have a command pending */
  392. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  393. __func__, adapter->current_op);
  394. return;
  395. }
  396. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  397. if (f->remove)
  398. count++;
  399. }
  400. if (!count) {
  401. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  402. return;
  403. }
  404. adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
  405. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  406. (count * sizeof(struct i40e_virtchnl_ether_addr));
  407. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  408. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
  409. __func__);
  410. count = (I40EVF_MAX_AQ_BUF_SIZE -
  411. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  412. sizeof(struct i40e_virtchnl_ether_addr);
  413. len = I40EVF_MAX_AQ_BUF_SIZE;
  414. }
  415. veal = kzalloc(len, GFP_ATOMIC);
  416. if (!veal)
  417. return;
  418. veal->vsi_id = adapter->vsi_res->vsi_id;
  419. veal->num_elements = count;
  420. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  421. if (f->remove) {
  422. ether_addr_copy(veal->list[i].addr, f->macaddr);
  423. i++;
  424. list_del(&f->list);
  425. kfree(f);
  426. }
  427. }
  428. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  429. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  430. (u8 *)veal, len);
  431. kfree(veal);
  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. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  484. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  485. kfree(vvfl);
  486. }
  487. /**
  488. * i40evf_del_vlans
  489. * @adapter: adapter structure
  490. * @vlans: the VLANs to remove
  491. * @count: number of VLANs
  492. *
  493. * Request that the PF remove one or more VLAN filters from our VSI.
  494. **/
  495. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  496. {
  497. struct i40e_virtchnl_vlan_filter_list *vvfl;
  498. struct i40evf_vlan_filter *f, *ftmp;
  499. int len, i = 0, count = 0;
  500. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  501. /* bail because we already have a command pending */
  502. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  503. __func__, adapter->current_op);
  504. return;
  505. }
  506. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  507. if (f->remove)
  508. count++;
  509. }
  510. if (!count) {
  511. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  512. return;
  513. }
  514. adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
  515. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  516. (count * sizeof(u16));
  517. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  518. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
  519. __func__);
  520. count = (I40EVF_MAX_AQ_BUF_SIZE -
  521. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  522. sizeof(u16);
  523. len = I40EVF_MAX_AQ_BUF_SIZE;
  524. }
  525. vvfl = kzalloc(len, GFP_ATOMIC);
  526. if (!vvfl)
  527. return;
  528. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  529. vvfl->num_elements = count;
  530. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  531. if (f->remove) {
  532. vvfl->vlan_id[i] = f->vlan;
  533. i++;
  534. list_del(&f->list);
  535. kfree(f);
  536. }
  537. }
  538. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  539. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  540. kfree(vvfl);
  541. }
  542. /**
  543. * i40evf_set_promiscuous
  544. * @adapter: adapter structure
  545. * @flags: bitmask to control unicast/multicast promiscuous.
  546. *
  547. * Request that the PF enable promiscuous mode for our VSI.
  548. **/
  549. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  550. {
  551. struct i40e_virtchnl_promisc_info vpi;
  552. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  553. /* bail because we already have a command pending */
  554. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  555. __func__, adapter->current_op);
  556. return;
  557. }
  558. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  559. vpi.vsi_id = adapter->vsi_res->vsi_id;
  560. vpi.flags = flags;
  561. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  562. (u8 *)&vpi, sizeof(vpi));
  563. }
  564. /**
  565. * i40evf_request_stats
  566. * @adapter: adapter structure
  567. *
  568. * Request VSI statistics from PF.
  569. **/
  570. void i40evf_request_stats(struct i40evf_adapter *adapter)
  571. {
  572. struct i40e_virtchnl_queue_select vqs;
  573. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  574. /* no error message, this isn't crucial */
  575. return;
  576. }
  577. adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
  578. vqs.vsi_id = adapter->vsi_res->vsi_id;
  579. /* queue maps are ignored for this message - only the vsi is used */
  580. if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
  581. (u8 *)&vqs, sizeof(vqs)))
  582. /* if the request failed, don't lock out others */
  583. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  584. }
  585. /**
  586. * i40evf_request_reset
  587. * @adapter: adapter structure
  588. *
  589. * Request that the PF reset this VF. No response is expected.
  590. **/
  591. void i40evf_request_reset(struct i40evf_adapter *adapter)
  592. {
  593. /* Don't check CURRENT_OP - this is always higher priority */
  594. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  595. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  596. }
  597. /**
  598. * i40evf_virtchnl_completion
  599. * @adapter: adapter structure
  600. * @v_opcode: opcode sent by PF
  601. * @v_retval: retval sent by PF
  602. * @msg: message sent by PF
  603. * @msglen: message length
  604. *
  605. * Asynchronous completion function for admin queue messages. Rather than busy
  606. * wait, we fire off our requests and assume that no errors will be returned.
  607. * This function handles the reply messages.
  608. **/
  609. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  610. enum i40e_virtchnl_ops v_opcode,
  611. i40e_status v_retval,
  612. u8 *msg, u16 msglen)
  613. {
  614. struct net_device *netdev = adapter->netdev;
  615. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  616. struct i40e_virtchnl_pf_event *vpe =
  617. (struct i40e_virtchnl_pf_event *)msg;
  618. switch (vpe->event) {
  619. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  620. adapter->link_up =
  621. vpe->event_data.link_event.link_status;
  622. if (adapter->link_up && !netif_carrier_ok(netdev)) {
  623. dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
  624. netif_carrier_on(netdev);
  625. netif_tx_wake_all_queues(netdev);
  626. } else if (!adapter->link_up) {
  627. dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
  628. netif_carrier_off(netdev);
  629. netif_tx_stop_all_queues(netdev);
  630. }
  631. break;
  632. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  633. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  634. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  635. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  636. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  637. schedule_work(&adapter->reset_task);
  638. }
  639. break;
  640. default:
  641. dev_err(&adapter->pdev->dev,
  642. "%s: Unknown event %d from pf\n",
  643. __func__, vpe->event);
  644. break;
  645. }
  646. return;
  647. }
  648. if (v_retval) {
  649. dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d\n",
  650. __func__, v_retval, v_opcode);
  651. }
  652. switch (v_opcode) {
  653. case I40E_VIRTCHNL_OP_GET_STATS: {
  654. struct i40e_eth_stats *stats =
  655. (struct i40e_eth_stats *)msg;
  656. adapter->net_stats.rx_packets = stats->rx_unicast +
  657. stats->rx_multicast +
  658. stats->rx_broadcast;
  659. adapter->net_stats.tx_packets = stats->tx_unicast +
  660. stats->tx_multicast +
  661. stats->tx_broadcast;
  662. adapter->net_stats.rx_bytes = stats->rx_bytes;
  663. adapter->net_stats.tx_bytes = stats->tx_bytes;
  664. adapter->net_stats.tx_errors = stats->tx_errors;
  665. adapter->net_stats.rx_dropped = stats->rx_discards;
  666. adapter->net_stats.tx_dropped = stats->tx_discards;
  667. adapter->current_stats = *stats;
  668. }
  669. break;
  670. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  671. /* enable transmits */
  672. i40evf_irq_enable(adapter, true);
  673. netif_tx_start_all_queues(adapter->netdev);
  674. netif_carrier_on(adapter->netdev);
  675. break;
  676. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  677. i40evf_free_all_tx_resources(adapter);
  678. i40evf_free_all_rx_resources(adapter);
  679. break;
  680. case I40E_VIRTCHNL_OP_VERSION:
  681. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
  682. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  683. /* Don't display an error if we get these out of sequence.
  684. * If the firmware needed to get kicked, we'll get these and
  685. * it's no problem.
  686. */
  687. if (v_opcode != adapter->current_op)
  688. return;
  689. break;
  690. default:
  691. if (v_opcode != adapter->current_op)
  692. dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
  693. adapter->current_op, v_opcode);
  694. break;
  695. } /* switch v_opcode */
  696. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  697. }