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