i40evf_virtchnl.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  227. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  228. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  229. (u8 *)vqci, len);
  230. kfree(vqci);
  231. }
  232. /**
  233. * i40evf_enable_queues
  234. * @adapter: adapter structure
  235. *
  236. * Request that the PF enable all of our queues.
  237. **/
  238. void i40evf_enable_queues(struct i40evf_adapter *adapter)
  239. {
  240. struct i40e_virtchnl_queue_select vqs;
  241. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  242. /* bail because we already have a command pending */
  243. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  244. __func__, adapter->current_op);
  245. return;
  246. }
  247. adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
  248. vqs.vsi_id = adapter->vsi_res->vsi_id;
  249. vqs.tx_queues = (1 << adapter->num_active_queues) - 1;
  250. vqs.rx_queues = vqs.tx_queues;
  251. adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
  252. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  253. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  254. (u8 *)&vqs, sizeof(vqs));
  255. }
  256. /**
  257. * i40evf_disable_queues
  258. * @adapter: adapter structure
  259. *
  260. * Request that the PF disable all of our queues.
  261. **/
  262. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  263. {
  264. struct i40e_virtchnl_queue_select vqs;
  265. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  266. /* bail because we already have a command pending */
  267. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  268. __func__, adapter->current_op);
  269. return;
  270. }
  271. adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
  272. vqs.vsi_id = adapter->vsi_res->vsi_id;
  273. vqs.tx_queues = (1 << adapter->num_active_queues) - 1;
  274. vqs.rx_queues = vqs.tx_queues;
  275. adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
  276. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  277. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  278. (u8 *)&vqs, sizeof(vqs));
  279. }
  280. /**
  281. * i40evf_map_queues
  282. * @adapter: adapter structure
  283. *
  284. * Request that the PF map queues to interrupt vectors. Misc causes, including
  285. * admin queue, are always mapped to vector 0.
  286. **/
  287. void i40evf_map_queues(struct i40evf_adapter *adapter)
  288. {
  289. struct i40e_virtchnl_irq_map_info *vimi;
  290. int v_idx, q_vectors, len;
  291. struct i40e_q_vector *q_vector;
  292. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  293. /* bail because we already have a command pending */
  294. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  295. __func__, adapter->current_op);
  296. return;
  297. }
  298. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
  299. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  300. len = sizeof(struct i40e_virtchnl_irq_map_info) +
  301. (adapter->num_msix_vectors *
  302. sizeof(struct i40e_virtchnl_vector_map));
  303. vimi = kzalloc(len, GFP_ATOMIC);
  304. if (!vimi)
  305. return;
  306. vimi->num_vectors = adapter->num_msix_vectors;
  307. /* Queue vectors first */
  308. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  309. q_vector = adapter->q_vector[v_idx];
  310. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  311. vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
  312. vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
  313. vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
  314. }
  315. /* Misc vector last - this is only for AdminQ messages */
  316. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  317. vimi->vecmap[v_idx].vector_id = 0;
  318. vimi->vecmap[v_idx].txq_map = 0;
  319. vimi->vecmap[v_idx].rxq_map = 0;
  320. adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS;
  321. adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
  322. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  323. (u8 *)vimi, len);
  324. kfree(vimi);
  325. }
  326. /**
  327. * i40evf_add_ether_addrs
  328. * @adapter: adapter structure
  329. * @addrs: the MAC address filters to add (contiguous)
  330. * @count: number of filters
  331. *
  332. * Request that the PF add one or more addresses to our filters.
  333. **/
  334. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
  335. {
  336. struct i40e_virtchnl_ether_addr_list *veal;
  337. int len, i = 0, count = 0;
  338. struct i40evf_mac_filter *f;
  339. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  340. /* bail because we already have a command pending */
  341. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  342. __func__, adapter->current_op);
  343. return;
  344. }
  345. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  346. if (f->add)
  347. count++;
  348. }
  349. if (!count) {
  350. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  351. return;
  352. }
  353. adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
  354. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  355. (count * sizeof(struct i40e_virtchnl_ether_addr));
  356. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  357. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
  358. __func__);
  359. count = (I40EVF_MAX_AQ_BUF_SIZE -
  360. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  361. sizeof(struct i40e_virtchnl_ether_addr);
  362. len = I40EVF_MAX_AQ_BUF_SIZE;
  363. }
  364. veal = kzalloc(len, GFP_ATOMIC);
  365. if (!veal)
  366. return;
  367. veal->vsi_id = adapter->vsi_res->vsi_id;
  368. veal->num_elements = count;
  369. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  370. if (f->add) {
  371. ether_addr_copy(veal->list[i].addr, f->macaddr);
  372. i++;
  373. f->add = false;
  374. }
  375. }
  376. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  377. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  378. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  379. (u8 *)veal, len);
  380. kfree(veal);
  381. }
  382. /**
  383. * i40evf_del_ether_addrs
  384. * @adapter: adapter structure
  385. * @addrs: the MAC address filters to remove (contiguous)
  386. * @count: number of filtes
  387. *
  388. * Request that the PF remove one or more addresses from our filters.
  389. **/
  390. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  391. {
  392. struct i40e_virtchnl_ether_addr_list *veal;
  393. struct i40evf_mac_filter *f, *ftmp;
  394. int len, i = 0, count = 0;
  395. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  396. /* bail because we already have a command pending */
  397. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  398. __func__, adapter->current_op);
  399. return;
  400. }
  401. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  402. if (f->remove)
  403. count++;
  404. }
  405. if (!count) {
  406. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  407. return;
  408. }
  409. adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
  410. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  411. (count * sizeof(struct i40e_virtchnl_ether_addr));
  412. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  413. dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
  414. __func__);
  415. count = (I40EVF_MAX_AQ_BUF_SIZE -
  416. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  417. sizeof(struct i40e_virtchnl_ether_addr);
  418. len = I40EVF_MAX_AQ_BUF_SIZE;
  419. }
  420. veal = kzalloc(len, GFP_ATOMIC);
  421. if (!veal)
  422. return;
  423. veal->vsi_id = adapter->vsi_res->vsi_id;
  424. veal->num_elements = count;
  425. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  426. if (f->remove) {
  427. ether_addr_copy(veal->list[i].addr, f->macaddr);
  428. i++;
  429. list_del(&f->list);
  430. kfree(f);
  431. }
  432. }
  433. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  434. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  435. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  436. (u8 *)veal, len);
  437. kfree(veal);
  438. }
  439. /**
  440. * i40evf_add_vlans
  441. * @adapter: adapter structure
  442. * @vlans: the VLANs to add
  443. * @count: number of VLANs
  444. *
  445. * Request that the PF add one or more VLAN filters to our VSI.
  446. **/
  447. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  448. {
  449. struct i40e_virtchnl_vlan_filter_list *vvfl;
  450. int len, i = 0, count = 0;
  451. struct i40evf_vlan_filter *f;
  452. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  453. /* bail because we already have a command pending */
  454. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  455. __func__, adapter->current_op);
  456. return;
  457. }
  458. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  459. if (f->add)
  460. count++;
  461. }
  462. if (!count) {
  463. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  464. return;
  465. }
  466. adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
  467. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  468. (count * sizeof(u16));
  469. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  470. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
  471. __func__);
  472. count = (I40EVF_MAX_AQ_BUF_SIZE -
  473. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  474. sizeof(u16);
  475. len = I40EVF_MAX_AQ_BUF_SIZE;
  476. }
  477. vvfl = kzalloc(len, GFP_ATOMIC);
  478. if (!vvfl)
  479. return;
  480. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  481. vvfl->num_elements = count;
  482. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  483. if (f->add) {
  484. vvfl->vlan_id[i] = f->vlan;
  485. i++;
  486. f->add = false;
  487. }
  488. }
  489. adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  490. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  491. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  492. kfree(vvfl);
  493. }
  494. /**
  495. * i40evf_del_vlans
  496. * @adapter: adapter structure
  497. * @vlans: the VLANs to remove
  498. * @count: number of VLANs
  499. *
  500. * Request that the PF remove one or more VLAN filters from our VSI.
  501. **/
  502. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  503. {
  504. struct i40e_virtchnl_vlan_filter_list *vvfl;
  505. struct i40evf_vlan_filter *f, *ftmp;
  506. int len, i = 0, count = 0;
  507. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  508. /* bail because we already have a command pending */
  509. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  510. __func__, adapter->current_op);
  511. return;
  512. }
  513. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  514. if (f->remove)
  515. count++;
  516. }
  517. if (!count) {
  518. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  519. return;
  520. }
  521. adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
  522. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  523. (count * sizeof(u16));
  524. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  525. dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
  526. __func__);
  527. count = (I40EVF_MAX_AQ_BUF_SIZE -
  528. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  529. sizeof(u16);
  530. len = I40EVF_MAX_AQ_BUF_SIZE;
  531. }
  532. vvfl = kzalloc(len, GFP_ATOMIC);
  533. if (!vvfl)
  534. return;
  535. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  536. vvfl->num_elements = count;
  537. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  538. if (f->remove) {
  539. vvfl->vlan_id[i] = f->vlan;
  540. i++;
  541. list_del(&f->list);
  542. kfree(f);
  543. }
  544. }
  545. adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  546. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  547. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  548. kfree(vvfl);
  549. }
  550. /**
  551. * i40evf_set_promiscuous
  552. * @adapter: adapter structure
  553. * @flags: bitmask to control unicast/multicast promiscuous.
  554. *
  555. * Request that the PF enable promiscuous mode for our VSI.
  556. **/
  557. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  558. {
  559. struct i40e_virtchnl_promisc_info vpi;
  560. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  561. /* bail because we already have a command pending */
  562. dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
  563. __func__, adapter->current_op);
  564. return;
  565. }
  566. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  567. vpi.vsi_id = adapter->vsi_res->vsi_id;
  568. vpi.flags = flags;
  569. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  570. (u8 *)&vpi, sizeof(vpi));
  571. }
  572. /**
  573. * i40evf_request_stats
  574. * @adapter: adapter structure
  575. *
  576. * Request VSI statistics from PF.
  577. **/
  578. void i40evf_request_stats(struct i40evf_adapter *adapter)
  579. {
  580. struct i40e_virtchnl_queue_select vqs;
  581. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  582. /* no error message, this isn't crucial */
  583. return;
  584. }
  585. adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
  586. vqs.vsi_id = adapter->vsi_res->vsi_id;
  587. /* queue maps are ignored for this message - only the vsi is used */
  588. if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
  589. (u8 *)&vqs, sizeof(vqs)))
  590. /* if the request failed, don't lock out others */
  591. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  592. }
  593. /**
  594. * i40evf_request_reset
  595. * @adapter: adapter structure
  596. *
  597. * Request that the PF reset this VF. No response is expected.
  598. **/
  599. void i40evf_request_reset(struct i40evf_adapter *adapter)
  600. {
  601. /* Don't check CURRENT_OP - this is always higher priority */
  602. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  603. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  604. }
  605. /**
  606. * i40evf_virtchnl_completion
  607. * @adapter: adapter structure
  608. * @v_opcode: opcode sent by PF
  609. * @v_retval: retval sent by PF
  610. * @msg: message sent by PF
  611. * @msglen: message length
  612. *
  613. * Asynchronous completion function for admin queue messages. Rather than busy
  614. * wait, we fire off our requests and assume that no errors will be returned.
  615. * This function handles the reply messages.
  616. **/
  617. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  618. enum i40e_virtchnl_ops v_opcode,
  619. i40e_status v_retval,
  620. u8 *msg, u16 msglen)
  621. {
  622. struct net_device *netdev = adapter->netdev;
  623. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  624. struct i40e_virtchnl_pf_event *vpe =
  625. (struct i40e_virtchnl_pf_event *)msg;
  626. switch (vpe->event) {
  627. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  628. adapter->link_up =
  629. vpe->event_data.link_event.link_status;
  630. if (adapter->link_up && !netif_carrier_ok(netdev)) {
  631. dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
  632. netif_carrier_on(netdev);
  633. netif_tx_wake_all_queues(netdev);
  634. } else if (!adapter->link_up) {
  635. dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
  636. netif_carrier_off(netdev);
  637. netif_tx_stop_all_queues(netdev);
  638. }
  639. break;
  640. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  641. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  642. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  643. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  644. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  645. schedule_work(&adapter->reset_task);
  646. }
  647. break;
  648. default:
  649. dev_err(&adapter->pdev->dev,
  650. "%s: Unknown event %d from pf\n",
  651. __func__, vpe->event);
  652. break;
  653. }
  654. return;
  655. }
  656. if (v_retval) {
  657. dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d\n",
  658. __func__, v_retval, v_opcode);
  659. }
  660. switch (v_opcode) {
  661. case I40E_VIRTCHNL_OP_VERSION:
  662. /* no action, but also not an error */
  663. break;
  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. i40evf_free_all_tx_resources(adapter);
  703. i40evf_free_all_rx_resources(adapter);
  704. break;
  705. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  706. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
  707. break;
  708. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  709. adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
  710. break;
  711. default:
  712. dev_info(&adapter->pdev->dev, "Received unexpected message %d from PF\n",
  713. v_opcode);
  714. break;
  715. } /* switch v_opcode */
  716. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  717. }