i40evf_virtchnl.c 25 KB

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