i40evf_virtchnl.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. #include "i40evf_client.h"
  29. /* busy wait delay in msec */
  30. #define I40EVF_BUSY_WAIT_DELAY 10
  31. #define I40EVF_BUSY_WAIT_COUNT 50
  32. /**
  33. * i40evf_send_pf_msg
  34. * @adapter: adapter structure
  35. * @op: virtual channel opcode
  36. * @msg: pointer to message buffer
  37. * @len: message length
  38. *
  39. * Send message to PF and print status if failure.
  40. **/
  41. static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
  42. enum i40e_virtchnl_ops op, u8 *msg, u16 len)
  43. {
  44. struct i40e_hw *hw = &adapter->hw;
  45. i40e_status err;
  46. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
  47. return 0; /* nothing to see here, move along */
  48. err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
  49. if (err)
  50. dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
  51. op, i40evf_stat_str(hw, err),
  52. i40evf_aq_str(hw, hw->aq.asq_last_status));
  53. return err;
  54. }
  55. /**
  56. * i40evf_send_api_ver
  57. * @adapter: adapter structure
  58. *
  59. * Send API version admin queue message to the PF. The reply is not checked
  60. * in this function. Returns 0 if the message was successfully
  61. * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  62. **/
  63. int i40evf_send_api_ver(struct i40evf_adapter *adapter)
  64. {
  65. struct i40e_virtchnl_version_info vvi;
  66. vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
  67. vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
  68. return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
  69. sizeof(vvi));
  70. }
  71. /**
  72. * i40evf_verify_api_ver
  73. * @adapter: adapter structure
  74. *
  75. * Compare API versions with the PF. Must be called after admin queue is
  76. * initialized. Returns 0 if API versions match, -EIO if they do not,
  77. * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
  78. * from the firmware are propagated.
  79. **/
  80. int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
  81. {
  82. struct i40e_virtchnl_version_info *pf_vvi;
  83. struct i40e_hw *hw = &adapter->hw;
  84. struct i40e_arq_event_info event;
  85. enum i40e_virtchnl_ops op;
  86. i40e_status err;
  87. event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
  88. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  89. if (!event.msg_buf) {
  90. err = -ENOMEM;
  91. goto out;
  92. }
  93. while (1) {
  94. err = i40evf_clean_arq_element(hw, &event, NULL);
  95. /* When the AQ is empty, i40evf_clean_arq_element will return
  96. * nonzero and this loop will terminate.
  97. */
  98. if (err)
  99. goto out_alloc;
  100. op =
  101. (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  102. if (op == I40E_VIRTCHNL_OP_VERSION)
  103. break;
  104. }
  105. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  106. if (err)
  107. goto out_alloc;
  108. if (op != I40E_VIRTCHNL_OP_VERSION) {
  109. dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
  110. op);
  111. err = -EIO;
  112. goto out_alloc;
  113. }
  114. pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
  115. adapter->pf_version = *pf_vvi;
  116. if ((pf_vvi->major > I40E_VIRTCHNL_VERSION_MAJOR) ||
  117. ((pf_vvi->major == I40E_VIRTCHNL_VERSION_MAJOR) &&
  118. (pf_vvi->minor > I40E_VIRTCHNL_VERSION_MINOR)))
  119. err = -EIO;
  120. out_alloc:
  121. kfree(event.msg_buf);
  122. out:
  123. return err;
  124. }
  125. /**
  126. * i40evf_send_vf_config_msg
  127. * @adapter: adapter structure
  128. *
  129. * Send VF configuration request admin queue message to the PF. The reply
  130. * is not checked in this function. Returns 0 if the message was
  131. * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  132. **/
  133. int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
  134. {
  135. u32 caps;
  136. adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
  137. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
  138. caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
  139. I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ |
  140. I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
  141. I40E_VIRTCHNL_VF_OFFLOAD_VLAN |
  142. I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
  143. I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
  144. I40E_VIRTCHNL_VF_OFFLOAD_ENCAP |
  145. I40E_VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
  146. adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
  147. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
  148. if (PF_IS_V11(adapter))
  149. return i40evf_send_pf_msg(adapter,
  150. I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  151. (u8 *)&caps, sizeof(caps));
  152. else
  153. return i40evf_send_pf_msg(adapter,
  154. I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  155. NULL, 0);
  156. }
  157. /**
  158. * i40evf_get_vf_config
  159. * @hw: pointer to the hardware structure
  160. * @len: length of buffer
  161. *
  162. * Get VF configuration from PF and populate hw structure. Must be called after
  163. * admin queue is initialized. Busy waits until response is received from PF,
  164. * with maximum timeout. Response from PF is returned in the buffer for further
  165. * processing by the caller.
  166. **/
  167. int i40evf_get_vf_config(struct i40evf_adapter *adapter)
  168. {
  169. struct i40e_hw *hw = &adapter->hw;
  170. struct i40e_arq_event_info event;
  171. enum i40e_virtchnl_ops op;
  172. i40e_status err;
  173. u16 len;
  174. len = sizeof(struct i40e_virtchnl_vf_resource) +
  175. I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
  176. event.buf_len = len;
  177. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  178. if (!event.msg_buf) {
  179. err = -ENOMEM;
  180. goto out;
  181. }
  182. while (1) {
  183. /* When the AQ is empty, i40evf_clean_arq_element will return
  184. * nonzero and this loop will terminate.
  185. */
  186. err = i40evf_clean_arq_element(hw, &event, NULL);
  187. if (err)
  188. goto out_alloc;
  189. op =
  190. (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  191. if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
  192. break;
  193. }
  194. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  195. memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
  196. i40e_vf_parse_hw_config(hw, adapter->vf_res);
  197. out_alloc:
  198. kfree(event.msg_buf);
  199. out:
  200. return err;
  201. }
  202. /**
  203. * i40evf_configure_queues
  204. * @adapter: adapter structure
  205. *
  206. * Request that the PF set up our (previously allocated) queues.
  207. **/
  208. void i40evf_configure_queues(struct i40evf_adapter *adapter)
  209. {
  210. struct i40e_virtchnl_vsi_queue_config_info *vqci;
  211. struct i40e_virtchnl_queue_pair_info *vqpi;
  212. int pairs = adapter->num_active_queues;
  213. int i, len, max_frame = I40E_MAX_RXBUFFER;
  214. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  215. /* bail because we already have a command pending */
  216. dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
  217. adapter->current_op);
  218. return;
  219. }
  220. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
  221. len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
  222. (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
  223. vqci = kzalloc(len, GFP_KERNEL);
  224. if (!vqci)
  225. return;
  226. /* Limit maximum frame size when jumbo frames is not enabled */
  227. if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
  228. (adapter->netdev->mtu <= ETH_DATA_LEN))
  229. max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  230. vqci->vsi_id = adapter->vsi_res->vsi_id;
  231. vqci->num_queue_pairs = pairs;
  232. vqpi = vqci->qpair;
  233. /* Size check is not needed here - HW max is 16 queue pairs, and we
  234. * can fit info for 31 of them into the AQ buffer before it overflows.
  235. */
  236. for (i = 0; i < pairs; i++) {
  237. vqpi->txq.vsi_id = vqci->vsi_id;
  238. vqpi->txq.queue_id = i;
  239. vqpi->txq.ring_len = adapter->tx_rings[i].count;
  240. vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
  241. vqpi->rxq.vsi_id = vqci->vsi_id;
  242. vqpi->rxq.queue_id = i;
  243. vqpi->rxq.ring_len = adapter->rx_rings[i].count;
  244. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
  245. vqpi->rxq.max_pkt_size = max_frame;
  246. vqpi->rxq.databuffer_size =
  247. ALIGN(adapter->rx_rings[i].rx_buf_len,
  248. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  249. vqpi++;
  250. }
  251. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  252. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  253. (u8 *)vqci, len);
  254. kfree(vqci);
  255. }
  256. /**
  257. * i40evf_enable_queues
  258. * @adapter: adapter structure
  259. *
  260. * Request that the PF enable all of our queues.
  261. **/
  262. void i40evf_enable_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, "Cannot enable queues, command %d pending\n",
  268. adapter->current_op);
  269. return;
  270. }
  271. adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
  272. vqs.vsi_id = adapter->vsi_res->vsi_id;
  273. vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
  274. vqs.rx_queues = vqs.tx_queues;
  275. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  276. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  277. (u8 *)&vqs, sizeof(vqs));
  278. }
  279. /**
  280. * i40evf_disable_queues
  281. * @adapter: adapter structure
  282. *
  283. * Request that the PF disable all of our queues.
  284. **/
  285. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  286. {
  287. struct i40e_virtchnl_queue_select vqs;
  288. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  289. /* bail because we already have a command pending */
  290. dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
  291. adapter->current_op);
  292. return;
  293. }
  294. adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
  295. vqs.vsi_id = adapter->vsi_res->vsi_id;
  296. vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
  297. vqs.rx_queues = vqs.tx_queues;
  298. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  299. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  300. (u8 *)&vqs, sizeof(vqs));
  301. }
  302. /**
  303. * i40evf_map_queues
  304. * @adapter: adapter structure
  305. *
  306. * Request that the PF map queues to interrupt vectors. Misc causes, including
  307. * admin queue, are always mapped to vector 0.
  308. **/
  309. void i40evf_map_queues(struct i40evf_adapter *adapter)
  310. {
  311. struct i40e_virtchnl_irq_map_info *vimi;
  312. int v_idx, q_vectors, len;
  313. struct i40e_q_vector *q_vector;
  314. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  315. /* bail because we already have a command pending */
  316. dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
  317. adapter->current_op);
  318. return;
  319. }
  320. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
  321. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  322. len = sizeof(struct i40e_virtchnl_irq_map_info) +
  323. (adapter->num_msix_vectors *
  324. sizeof(struct i40e_virtchnl_vector_map));
  325. vimi = kzalloc(len, GFP_KERNEL);
  326. if (!vimi)
  327. return;
  328. vimi->num_vectors = adapter->num_msix_vectors;
  329. /* Queue vectors first */
  330. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  331. q_vector = adapter->q_vectors + v_idx;
  332. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  333. vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
  334. vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
  335. vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
  336. }
  337. /* Misc vector last - this is only for AdminQ messages */
  338. vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
  339. vimi->vecmap[v_idx].vector_id = 0;
  340. vimi->vecmap[v_idx].txq_map = 0;
  341. vimi->vecmap[v_idx].rxq_map = 0;
  342. adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
  343. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  344. (u8 *)vimi, len);
  345. kfree(vimi);
  346. }
  347. /**
  348. * i40evf_add_ether_addrs
  349. * @adapter: adapter structure
  350. * @addrs: the MAC address filters to add (contiguous)
  351. * @count: number of filters
  352. *
  353. * Request that the PF add one or more addresses to our filters.
  354. **/
  355. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
  356. {
  357. struct i40e_virtchnl_ether_addr_list *veal;
  358. int len, i = 0, count = 0;
  359. struct i40evf_mac_filter *f;
  360. bool more = false;
  361. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  362. /* bail because we already have a command pending */
  363. dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
  364. adapter->current_op);
  365. return;
  366. }
  367. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  368. if (f->add)
  369. count++;
  370. }
  371. if (!count) {
  372. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  373. return;
  374. }
  375. adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
  376. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  377. (count * sizeof(struct i40e_virtchnl_ether_addr));
  378. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  379. dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
  380. count = (I40EVF_MAX_AQ_BUF_SIZE -
  381. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  382. sizeof(struct i40e_virtchnl_ether_addr);
  383. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  384. (count * sizeof(struct i40e_virtchnl_ether_addr));
  385. more = true;
  386. }
  387. veal = kzalloc(len, GFP_KERNEL);
  388. if (!veal)
  389. return;
  390. veal->vsi_id = adapter->vsi_res->vsi_id;
  391. veal->num_elements = count;
  392. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  393. if (f->add) {
  394. ether_addr_copy(veal->list[i].addr, f->macaddr);
  395. i++;
  396. f->add = false;
  397. if (i == count)
  398. break;
  399. }
  400. }
  401. if (!more)
  402. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  403. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  404. (u8 *)veal, len);
  405. kfree(veal);
  406. }
  407. /**
  408. * i40evf_del_ether_addrs
  409. * @adapter: adapter structure
  410. * @addrs: the MAC address filters to remove (contiguous)
  411. * @count: number of filtes
  412. *
  413. * Request that the PF remove one or more addresses from our filters.
  414. **/
  415. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  416. {
  417. struct i40e_virtchnl_ether_addr_list *veal;
  418. struct i40evf_mac_filter *f, *ftmp;
  419. int len, i = 0, count = 0;
  420. bool more = false;
  421. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  422. /* bail because we already have a command pending */
  423. dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
  424. adapter->current_op);
  425. return;
  426. }
  427. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  428. if (f->remove)
  429. count++;
  430. }
  431. if (!count) {
  432. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  433. return;
  434. }
  435. adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
  436. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  437. (count * sizeof(struct i40e_virtchnl_ether_addr));
  438. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  439. dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
  440. count = (I40EVF_MAX_AQ_BUF_SIZE -
  441. sizeof(struct i40e_virtchnl_ether_addr_list)) /
  442. sizeof(struct i40e_virtchnl_ether_addr);
  443. len = sizeof(struct i40e_virtchnl_ether_addr_list) +
  444. (count * sizeof(struct i40e_virtchnl_ether_addr));
  445. more = true;
  446. }
  447. veal = kzalloc(len, GFP_KERNEL);
  448. if (!veal)
  449. return;
  450. veal->vsi_id = adapter->vsi_res->vsi_id;
  451. veal->num_elements = count;
  452. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  453. if (f->remove) {
  454. ether_addr_copy(veal->list[i].addr, f->macaddr);
  455. i++;
  456. list_del(&f->list);
  457. kfree(f);
  458. if (i == count)
  459. break;
  460. }
  461. }
  462. if (!more)
  463. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  464. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  465. (u8 *)veal, len);
  466. kfree(veal);
  467. }
  468. /**
  469. * i40evf_add_vlans
  470. * @adapter: adapter structure
  471. * @vlans: the VLANs to add
  472. * @count: number of VLANs
  473. *
  474. * Request that the PF add one or more VLAN filters to our VSI.
  475. **/
  476. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  477. {
  478. struct i40e_virtchnl_vlan_filter_list *vvfl;
  479. int len, i = 0, count = 0;
  480. struct i40evf_vlan_filter *f;
  481. bool more = false;
  482. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  483. /* bail because we already have a command pending */
  484. dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
  485. adapter->current_op);
  486. return;
  487. }
  488. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  489. if (f->add)
  490. count++;
  491. }
  492. if (!count) {
  493. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  494. return;
  495. }
  496. adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
  497. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  498. (count * sizeof(u16));
  499. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  500. dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
  501. count = (I40EVF_MAX_AQ_BUF_SIZE -
  502. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  503. sizeof(u16);
  504. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  505. (count * sizeof(u16));
  506. more = true;
  507. }
  508. vvfl = kzalloc(len, GFP_KERNEL);
  509. if (!vvfl)
  510. return;
  511. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  512. vvfl->num_elements = count;
  513. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  514. if (f->add) {
  515. vvfl->vlan_id[i] = f->vlan;
  516. i++;
  517. f->add = false;
  518. if (i == count)
  519. break;
  520. }
  521. }
  522. if (!more)
  523. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  524. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  525. kfree(vvfl);
  526. }
  527. /**
  528. * i40evf_del_vlans
  529. * @adapter: adapter structure
  530. * @vlans: the VLANs to remove
  531. * @count: number of VLANs
  532. *
  533. * Request that the PF remove one or more VLAN filters from our VSI.
  534. **/
  535. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  536. {
  537. struct i40e_virtchnl_vlan_filter_list *vvfl;
  538. struct i40evf_vlan_filter *f, *ftmp;
  539. int len, i = 0, count = 0;
  540. bool more = false;
  541. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  542. /* bail because we already have a command pending */
  543. dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
  544. adapter->current_op);
  545. return;
  546. }
  547. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  548. if (f->remove)
  549. count++;
  550. }
  551. if (!count) {
  552. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  553. return;
  554. }
  555. adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
  556. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  557. (count * sizeof(u16));
  558. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  559. dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
  560. count = (I40EVF_MAX_AQ_BUF_SIZE -
  561. sizeof(struct i40e_virtchnl_vlan_filter_list)) /
  562. sizeof(u16);
  563. len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
  564. (count * sizeof(u16));
  565. more = true;
  566. }
  567. vvfl = kzalloc(len, GFP_KERNEL);
  568. if (!vvfl)
  569. return;
  570. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  571. vvfl->num_elements = count;
  572. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  573. if (f->remove) {
  574. vvfl->vlan_id[i] = f->vlan;
  575. i++;
  576. list_del(&f->list);
  577. kfree(f);
  578. if (i == count)
  579. break;
  580. }
  581. }
  582. if (!more)
  583. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  584. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  585. kfree(vvfl);
  586. }
  587. /**
  588. * i40evf_set_promiscuous
  589. * @adapter: adapter structure
  590. * @flags: bitmask to control unicast/multicast promiscuous.
  591. *
  592. * Request that the PF enable promiscuous mode for our VSI.
  593. **/
  594. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  595. {
  596. struct i40e_virtchnl_promisc_info vpi;
  597. int promisc_all;
  598. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  599. /* bail because we already have a command pending */
  600. dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
  601. adapter->current_op);
  602. return;
  603. }
  604. promisc_all = I40E_FLAG_VF_UNICAST_PROMISC |
  605. I40E_FLAG_VF_MULTICAST_PROMISC;
  606. if ((flags & promisc_all) == promisc_all) {
  607. adapter->flags |= I40EVF_FLAG_PROMISC_ON;
  608. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
  609. dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
  610. }
  611. if (flags & I40E_FLAG_VF_MULTICAST_PROMISC) {
  612. adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
  613. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
  614. dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
  615. }
  616. if (!flags) {
  617. adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
  618. adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
  619. dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
  620. }
  621. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  622. vpi.vsi_id = adapter->vsi_res->vsi_id;
  623. vpi.flags = flags;
  624. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  625. (u8 *)&vpi, sizeof(vpi));
  626. }
  627. /**
  628. * i40evf_request_stats
  629. * @adapter: adapter structure
  630. *
  631. * Request VSI statistics from PF.
  632. **/
  633. void i40evf_request_stats(struct i40evf_adapter *adapter)
  634. {
  635. struct i40e_virtchnl_queue_select vqs;
  636. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  637. /* no error message, this isn't crucial */
  638. return;
  639. }
  640. adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
  641. vqs.vsi_id = adapter->vsi_res->vsi_id;
  642. /* queue maps are ignored for this message - only the vsi is used */
  643. if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
  644. (u8 *)&vqs, sizeof(vqs)))
  645. /* if the request failed, don't lock out others */
  646. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  647. }
  648. /**
  649. * i40evf_get_hena
  650. * @adapter: adapter structure
  651. *
  652. * Request hash enable capabilities from PF
  653. **/
  654. void i40evf_get_hena(struct i40evf_adapter *adapter)
  655. {
  656. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  657. /* bail because we already have a command pending */
  658. dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
  659. adapter->current_op);
  660. return;
  661. }
  662. adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS;
  663. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
  664. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
  665. NULL, 0);
  666. }
  667. /**
  668. * i40evf_set_hena
  669. * @adapter: adapter structure
  670. *
  671. * Request the PF to set our RSS hash capabilities
  672. **/
  673. void i40evf_set_hena(struct i40evf_adapter *adapter)
  674. {
  675. struct i40e_virtchnl_rss_hena vrh;
  676. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  677. /* bail because we already have a command pending */
  678. dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
  679. adapter->current_op);
  680. return;
  681. }
  682. vrh.hena = adapter->hena;
  683. adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA;
  684. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
  685. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA,
  686. (u8 *)&vrh, sizeof(vrh));
  687. }
  688. /**
  689. * i40evf_set_rss_key
  690. * @adapter: adapter structure
  691. *
  692. * Request the PF to set our RSS hash key
  693. **/
  694. void i40evf_set_rss_key(struct i40evf_adapter *adapter)
  695. {
  696. struct i40e_virtchnl_rss_key *vrk;
  697. int len;
  698. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  699. /* bail because we already have a command pending */
  700. dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
  701. adapter->current_op);
  702. return;
  703. }
  704. len = sizeof(struct i40e_virtchnl_rss_key) +
  705. (adapter->rss_key_size * sizeof(u8)) - 1;
  706. vrk = kzalloc(len, GFP_KERNEL);
  707. if (!vrk)
  708. return;
  709. vrk->vsi_id = adapter->vsi.id;
  710. vrk->key_len = adapter->rss_key_size;
  711. memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
  712. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY;
  713. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
  714. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
  715. (u8 *)vrk, len);
  716. kfree(vrk);
  717. }
  718. /**
  719. * i40evf_set_rss_lut
  720. * @adapter: adapter structure
  721. *
  722. * Request the PF to set our RSS lookup table
  723. **/
  724. void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
  725. {
  726. struct i40e_virtchnl_rss_lut *vrl;
  727. int len;
  728. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  729. /* bail because we already have a command pending */
  730. dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
  731. adapter->current_op);
  732. return;
  733. }
  734. len = sizeof(struct i40e_virtchnl_rss_lut) +
  735. (adapter->rss_lut_size * sizeof(u8)) - 1;
  736. vrl = kzalloc(len, GFP_KERNEL);
  737. if (!vrl)
  738. return;
  739. vrl->vsi_id = adapter->vsi.id;
  740. vrl->lut_entries = adapter->rss_lut_size;
  741. memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
  742. adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT;
  743. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
  744. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
  745. (u8 *)vrl, len);
  746. kfree(vrl);
  747. }
  748. /**
  749. * i40evf_print_link_message - print link up or down
  750. * @adapter: adapter structure
  751. *
  752. * Log a message telling the world of our wonderous link status
  753. */
  754. static void i40evf_print_link_message(struct i40evf_adapter *adapter)
  755. {
  756. struct net_device *netdev = adapter->netdev;
  757. char *speed = "Unknown ";
  758. if (!adapter->link_up) {
  759. netdev_info(netdev, "NIC Link is Down\n");
  760. return;
  761. }
  762. switch (adapter->link_speed) {
  763. case I40E_LINK_SPEED_40GB:
  764. speed = "40 G";
  765. break;
  766. case I40E_LINK_SPEED_25GB:
  767. speed = "25 G";
  768. break;
  769. case I40E_LINK_SPEED_20GB:
  770. speed = "20 G";
  771. break;
  772. case I40E_LINK_SPEED_10GB:
  773. speed = "10 G";
  774. break;
  775. case I40E_LINK_SPEED_1GB:
  776. speed = "1000 M";
  777. break;
  778. case I40E_LINK_SPEED_100MB:
  779. speed = "100 M";
  780. break;
  781. default:
  782. break;
  783. }
  784. netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
  785. }
  786. /**
  787. * i40evf_request_reset
  788. * @adapter: adapter structure
  789. *
  790. * Request that the PF reset this VF. No response is expected.
  791. **/
  792. void i40evf_request_reset(struct i40evf_adapter *adapter)
  793. {
  794. /* Don't check CURRENT_OP - this is always higher priority */
  795. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  796. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  797. }
  798. /**
  799. * i40evf_virtchnl_completion
  800. * @adapter: adapter structure
  801. * @v_opcode: opcode sent by PF
  802. * @v_retval: retval sent by PF
  803. * @msg: message sent by PF
  804. * @msglen: message length
  805. *
  806. * Asynchronous completion function for admin queue messages. Rather than busy
  807. * wait, we fire off our requests and assume that no errors will be returned.
  808. * This function handles the reply messages.
  809. **/
  810. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  811. enum i40e_virtchnl_ops v_opcode,
  812. i40e_status v_retval,
  813. u8 *msg, u16 msglen)
  814. {
  815. struct net_device *netdev = adapter->netdev;
  816. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  817. struct i40e_virtchnl_pf_event *vpe =
  818. (struct i40e_virtchnl_pf_event *)msg;
  819. switch (vpe->event) {
  820. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  821. adapter->link_speed =
  822. vpe->event_data.link_event.link_speed;
  823. if (adapter->link_up !=
  824. vpe->event_data.link_event.link_status) {
  825. adapter->link_up =
  826. vpe->event_data.link_event.link_status;
  827. if (adapter->link_up) {
  828. netif_tx_start_all_queues(netdev);
  829. netif_carrier_on(netdev);
  830. } else {
  831. netif_tx_stop_all_queues(netdev);
  832. netif_carrier_off(netdev);
  833. }
  834. i40evf_print_link_message(adapter);
  835. }
  836. break;
  837. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  838. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  839. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  840. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  841. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  842. schedule_work(&adapter->reset_task);
  843. }
  844. break;
  845. default:
  846. dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
  847. vpe->event);
  848. break;
  849. }
  850. return;
  851. }
  852. if (v_retval) {
  853. switch (v_opcode) {
  854. case I40E_VIRTCHNL_OP_ADD_VLAN:
  855. dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
  856. i40evf_stat_str(&adapter->hw, v_retval));
  857. break;
  858. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  859. dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
  860. i40evf_stat_str(&adapter->hw, v_retval));
  861. break;
  862. case I40E_VIRTCHNL_OP_DEL_VLAN:
  863. dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
  864. i40evf_stat_str(&adapter->hw, v_retval));
  865. break;
  866. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  867. dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
  868. i40evf_stat_str(&adapter->hw, v_retval));
  869. break;
  870. default:
  871. dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
  872. v_retval,
  873. i40evf_stat_str(&adapter->hw, v_retval),
  874. v_opcode);
  875. }
  876. }
  877. switch (v_opcode) {
  878. case I40E_VIRTCHNL_OP_GET_STATS: {
  879. struct i40e_eth_stats *stats =
  880. (struct i40e_eth_stats *)msg;
  881. netdev->stats.rx_packets = stats->rx_unicast +
  882. stats->rx_multicast +
  883. stats->rx_broadcast;
  884. netdev->stats.tx_packets = stats->tx_unicast +
  885. stats->tx_multicast +
  886. stats->tx_broadcast;
  887. netdev->stats.rx_bytes = stats->rx_bytes;
  888. netdev->stats.tx_bytes = stats->tx_bytes;
  889. netdev->stats.tx_errors = stats->tx_errors;
  890. netdev->stats.rx_dropped = stats->rx_discards;
  891. netdev->stats.tx_dropped = stats->tx_discards;
  892. adapter->current_stats = *stats;
  893. }
  894. break;
  895. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
  896. u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
  897. I40E_MAX_VF_VSI *
  898. sizeof(struct i40e_virtchnl_vsi_resource);
  899. memcpy(adapter->vf_res, msg, min(msglen, len));
  900. i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
  901. /* restore current mac address */
  902. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  903. i40evf_process_config(adapter);
  904. }
  905. break;
  906. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  907. /* enable transmits */
  908. i40evf_irq_enable(adapter, true);
  909. break;
  910. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  911. i40evf_free_all_tx_resources(adapter);
  912. i40evf_free_all_rx_resources(adapter);
  913. if (adapter->state == __I40EVF_DOWN_PENDING)
  914. adapter->state = __I40EVF_DOWN;
  915. break;
  916. case I40E_VIRTCHNL_OP_VERSION:
  917. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  918. /* Don't display an error if we get these out of sequence.
  919. * If the firmware needed to get kicked, we'll get these and
  920. * it's no problem.
  921. */
  922. if (v_opcode != adapter->current_op)
  923. return;
  924. break;
  925. case I40E_VIRTCHNL_OP_IWARP:
  926. /* Gobble zero-length replies from the PF. They indicate that
  927. * a previous message was received OK, and the client doesn't
  928. * care about that.
  929. */
  930. if (msglen && CLIENT_ENABLED(adapter))
  931. i40evf_notify_client_message(&adapter->vsi,
  932. msg, msglen);
  933. break;
  934. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  935. adapter->client_pending &=
  936. ~(BIT(I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
  937. break;
  938. case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
  939. struct i40e_virtchnl_rss_hena *vrh =
  940. (struct i40e_virtchnl_rss_hena *)msg;
  941. if (msglen == sizeof(*vrh))
  942. adapter->hena = vrh->hena;
  943. else
  944. dev_warn(&adapter->pdev->dev,
  945. "Invalid message %d from PF\n", v_opcode);
  946. }
  947. break;
  948. default:
  949. if (adapter->current_op && (v_opcode != adapter->current_op))
  950. dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
  951. adapter->current_op, v_opcode);
  952. break;
  953. } /* switch v_opcode */
  954. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  955. }