i40evf_virtchnl.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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 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 virtchnl_version_info vvi;
  66. vvi.major = VIRTCHNL_VERSION_MAJOR;
  67. vvi.minor = VIRTCHNL_VERSION_MINOR;
  68. return i40evf_send_pf_msg(adapter, 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 virtchnl_version_info *pf_vvi;
  83. struct i40e_hw *hw = &adapter->hw;
  84. struct i40e_arq_event_info event;
  85. enum 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 virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  102. if (op == 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 != 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 virtchnl_version_info *)event.msg_buf;
  115. adapter->pf_version = *pf_vvi;
  116. if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
  117. ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
  118. (pf_vvi->minor > 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. caps = VIRTCHNL_VF_OFFLOAD_L2 |
  137. VIRTCHNL_VF_OFFLOAD_RSS_PF |
  138. VIRTCHNL_VF_OFFLOAD_RSS_AQ |
  139. VIRTCHNL_VF_OFFLOAD_RSS_REG |
  140. VIRTCHNL_VF_OFFLOAD_VLAN |
  141. VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
  142. VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
  143. VIRTCHNL_VF_OFFLOAD_ENCAP |
  144. VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
  145. adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
  146. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
  147. if (PF_IS_V11(adapter))
  148. return i40evf_send_pf_msg(adapter,
  149. VIRTCHNL_OP_GET_VF_RESOURCES,
  150. (u8 *)&caps, sizeof(caps));
  151. else
  152. return i40evf_send_pf_msg(adapter,
  153. VIRTCHNL_OP_GET_VF_RESOURCES,
  154. NULL, 0);
  155. }
  156. /**
  157. * i40evf_get_vf_config
  158. * @hw: pointer to the hardware structure
  159. * @len: length of buffer
  160. *
  161. * Get VF configuration from PF and populate hw structure. Must be called after
  162. * admin queue is initialized. Busy waits until response is received from PF,
  163. * with maximum timeout. Response from PF is returned in the buffer for further
  164. * processing by the caller.
  165. **/
  166. int i40evf_get_vf_config(struct i40evf_adapter *adapter)
  167. {
  168. struct i40e_hw *hw = &adapter->hw;
  169. struct i40e_arq_event_info event;
  170. enum virtchnl_ops op;
  171. i40e_status err;
  172. u16 len;
  173. len = sizeof(struct virtchnl_vf_resource) +
  174. I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
  175. event.buf_len = len;
  176. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  177. if (!event.msg_buf) {
  178. err = -ENOMEM;
  179. goto out;
  180. }
  181. while (1) {
  182. /* When the AQ is empty, i40evf_clean_arq_element will return
  183. * nonzero and this loop will terminate.
  184. */
  185. err = i40evf_clean_arq_element(hw, &event, NULL);
  186. if (err)
  187. goto out_alloc;
  188. op =
  189. (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  190. if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
  191. break;
  192. }
  193. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  194. memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
  195. i40e_vf_parse_hw_config(hw, adapter->vf_res);
  196. out_alloc:
  197. kfree(event.msg_buf);
  198. out:
  199. return err;
  200. }
  201. /**
  202. * i40evf_configure_queues
  203. * @adapter: adapter structure
  204. *
  205. * Request that the PF set up our (previously allocated) queues.
  206. **/
  207. void i40evf_configure_queues(struct i40evf_adapter *adapter)
  208. {
  209. struct virtchnl_vsi_queue_config_info *vqci;
  210. struct virtchnl_queue_pair_info *vqpi;
  211. int pairs = adapter->num_active_queues;
  212. int i, len, max_frame = I40E_MAX_RXBUFFER;
  213. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  214. /* bail because we already have a command pending */
  215. dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
  216. adapter->current_op);
  217. return;
  218. }
  219. adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
  220. len = sizeof(struct virtchnl_vsi_queue_config_info) +
  221. (sizeof(struct virtchnl_queue_pair_info) * pairs);
  222. vqci = kzalloc(len, GFP_KERNEL);
  223. if (!vqci)
  224. return;
  225. /* Limit maximum frame size when jumbo frames is not enabled */
  226. if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
  227. (adapter->netdev->mtu <= ETH_DATA_LEN))
  228. max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  229. vqci->vsi_id = adapter->vsi_res->vsi_id;
  230. vqci->num_queue_pairs = pairs;
  231. vqpi = vqci->qpair;
  232. /* Size check is not needed here - HW max is 16 queue pairs, and we
  233. * can fit info for 31 of them into the AQ buffer before it overflows.
  234. */
  235. for (i = 0; i < pairs; i++) {
  236. vqpi->txq.vsi_id = vqci->vsi_id;
  237. vqpi->txq.queue_id = i;
  238. vqpi->txq.ring_len = adapter->tx_rings[i].count;
  239. vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
  240. vqpi->rxq.vsi_id = vqci->vsi_id;
  241. vqpi->rxq.queue_id = i;
  242. vqpi->rxq.ring_len = adapter->rx_rings[i].count;
  243. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
  244. vqpi->rxq.max_pkt_size = max_frame;
  245. vqpi->rxq.databuffer_size =
  246. ALIGN(adapter->rx_rings[i].rx_buf_len,
  247. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  248. vqpi++;
  249. }
  250. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  251. i40evf_send_pf_msg(adapter, 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 virtchnl_queue_select vqs;
  264. if (adapter->current_op != 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 = 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, 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 virtchnl_queue_select vqs;
  287. if (adapter->current_op != 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 = 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, 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 virtchnl_irq_map_info *vimi;
  311. int v_idx, q_vectors, len;
  312. struct i40e_q_vector *q_vector;
  313. if (adapter->current_op != 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 = VIRTCHNL_OP_CONFIG_IRQ_MAP;
  320. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  321. len = sizeof(struct virtchnl_irq_map_info) +
  322. (adapter->num_msix_vectors *
  323. sizeof(struct 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, 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 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 != 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 = VIRTCHNL_OP_ADD_ETH_ADDR;
  375. len = sizeof(struct virtchnl_ether_addr_list) +
  376. (count * sizeof(struct 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 virtchnl_ether_addr_list)) /
  381. sizeof(struct virtchnl_ether_addr);
  382. len = sizeof(struct virtchnl_ether_addr_list) +
  383. (count * sizeof(struct 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. if (i == count)
  397. break;
  398. }
  399. }
  400. if (!more)
  401. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  402. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
  403. (u8 *)veal, len);
  404. kfree(veal);
  405. }
  406. /**
  407. * i40evf_del_ether_addrs
  408. * @adapter: adapter structure
  409. * @addrs: the MAC address filters to remove (contiguous)
  410. * @count: number of filtes
  411. *
  412. * Request that the PF remove one or more addresses from our filters.
  413. **/
  414. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  415. {
  416. struct virtchnl_ether_addr_list *veal;
  417. struct i40evf_mac_filter *f, *ftmp;
  418. int len, i = 0, count = 0;
  419. bool more = false;
  420. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  421. /* bail because we already have a command pending */
  422. dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
  423. adapter->current_op);
  424. return;
  425. }
  426. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  427. if (f->remove)
  428. count++;
  429. }
  430. if (!count) {
  431. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  432. return;
  433. }
  434. adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
  435. len = sizeof(struct virtchnl_ether_addr_list) +
  436. (count * sizeof(struct virtchnl_ether_addr));
  437. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  438. dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
  439. count = (I40EVF_MAX_AQ_BUF_SIZE -
  440. sizeof(struct virtchnl_ether_addr_list)) /
  441. sizeof(struct virtchnl_ether_addr);
  442. len = sizeof(struct virtchnl_ether_addr_list) +
  443. (count * sizeof(struct virtchnl_ether_addr));
  444. more = true;
  445. }
  446. veal = kzalloc(len, GFP_KERNEL);
  447. if (!veal)
  448. return;
  449. veal->vsi_id = adapter->vsi_res->vsi_id;
  450. veal->num_elements = count;
  451. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  452. if (f->remove) {
  453. ether_addr_copy(veal->list[i].addr, f->macaddr);
  454. i++;
  455. list_del(&f->list);
  456. kfree(f);
  457. if (i == count)
  458. break;
  459. }
  460. }
  461. if (!more)
  462. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  463. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
  464. (u8 *)veal, len);
  465. kfree(veal);
  466. }
  467. /**
  468. * i40evf_add_vlans
  469. * @adapter: adapter structure
  470. * @vlans: the VLANs to add
  471. * @count: number of VLANs
  472. *
  473. * Request that the PF add one or more VLAN filters to our VSI.
  474. **/
  475. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  476. {
  477. struct virtchnl_vlan_filter_list *vvfl;
  478. int len, i = 0, count = 0;
  479. struct i40evf_vlan_filter *f;
  480. bool more = false;
  481. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  482. /* bail because we already have a command pending */
  483. dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
  484. adapter->current_op);
  485. return;
  486. }
  487. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  488. if (f->add)
  489. count++;
  490. }
  491. if (!count) {
  492. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  493. return;
  494. }
  495. adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
  496. len = sizeof(struct virtchnl_vlan_filter_list) +
  497. (count * sizeof(u16));
  498. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  499. dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
  500. count = (I40EVF_MAX_AQ_BUF_SIZE -
  501. sizeof(struct virtchnl_vlan_filter_list)) /
  502. sizeof(u16);
  503. len = sizeof(struct virtchnl_vlan_filter_list) +
  504. (count * sizeof(u16));
  505. more = true;
  506. }
  507. vvfl = kzalloc(len, GFP_KERNEL);
  508. if (!vvfl)
  509. return;
  510. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  511. vvfl->num_elements = count;
  512. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  513. if (f->add) {
  514. vvfl->vlan_id[i] = f->vlan;
  515. i++;
  516. f->add = false;
  517. if (i == count)
  518. break;
  519. }
  520. }
  521. if (!more)
  522. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  523. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  524. kfree(vvfl);
  525. }
  526. /**
  527. * i40evf_del_vlans
  528. * @adapter: adapter structure
  529. * @vlans: the VLANs to remove
  530. * @count: number of VLANs
  531. *
  532. * Request that the PF remove one or more VLAN filters from our VSI.
  533. **/
  534. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  535. {
  536. struct virtchnl_vlan_filter_list *vvfl;
  537. struct i40evf_vlan_filter *f, *ftmp;
  538. int len, i = 0, count = 0;
  539. bool more = false;
  540. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  541. /* bail because we already have a command pending */
  542. dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
  543. adapter->current_op);
  544. return;
  545. }
  546. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  547. if (f->remove)
  548. count++;
  549. }
  550. if (!count) {
  551. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  552. return;
  553. }
  554. adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
  555. len = sizeof(struct virtchnl_vlan_filter_list) +
  556. (count * sizeof(u16));
  557. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  558. dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
  559. count = (I40EVF_MAX_AQ_BUF_SIZE -
  560. sizeof(struct virtchnl_vlan_filter_list)) /
  561. sizeof(u16);
  562. len = sizeof(struct virtchnl_vlan_filter_list) +
  563. (count * sizeof(u16));
  564. more = true;
  565. }
  566. vvfl = kzalloc(len, GFP_KERNEL);
  567. if (!vvfl)
  568. return;
  569. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  570. vvfl->num_elements = count;
  571. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  572. if (f->remove) {
  573. vvfl->vlan_id[i] = f->vlan;
  574. i++;
  575. list_del(&f->list);
  576. kfree(f);
  577. if (i == count)
  578. break;
  579. }
  580. }
  581. if (!more)
  582. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  583. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  584. kfree(vvfl);
  585. }
  586. /**
  587. * i40evf_set_promiscuous
  588. * @adapter: adapter structure
  589. * @flags: bitmask to control unicast/multicast promiscuous.
  590. *
  591. * Request that the PF enable promiscuous mode for our VSI.
  592. **/
  593. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  594. {
  595. struct virtchnl_promisc_info vpi;
  596. int promisc_all;
  597. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  598. /* bail because we already have a command pending */
  599. dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
  600. adapter->current_op);
  601. return;
  602. }
  603. promisc_all = FLAG_VF_UNICAST_PROMISC |
  604. FLAG_VF_MULTICAST_PROMISC;
  605. if ((flags & promisc_all) == promisc_all) {
  606. adapter->flags |= I40EVF_FLAG_PROMISC_ON;
  607. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
  608. dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
  609. }
  610. if (flags & FLAG_VF_MULTICAST_PROMISC) {
  611. adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
  612. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
  613. dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
  614. }
  615. if (!flags) {
  616. adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
  617. adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
  618. dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
  619. }
  620. adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  621. vpi.vsi_id = adapter->vsi_res->vsi_id;
  622. vpi.flags = flags;
  623. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  624. (u8 *)&vpi, sizeof(vpi));
  625. }
  626. /**
  627. * i40evf_request_stats
  628. * @adapter: adapter structure
  629. *
  630. * Request VSI statistics from PF.
  631. **/
  632. void i40evf_request_stats(struct i40evf_adapter *adapter)
  633. {
  634. struct virtchnl_queue_select vqs;
  635. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  636. /* no error message, this isn't crucial */
  637. return;
  638. }
  639. adapter->current_op = VIRTCHNL_OP_GET_STATS;
  640. vqs.vsi_id = adapter->vsi_res->vsi_id;
  641. /* queue maps are ignored for this message - only the vsi is used */
  642. if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
  643. (u8 *)&vqs, sizeof(vqs)))
  644. /* if the request failed, don't lock out others */
  645. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  646. }
  647. /**
  648. * i40evf_get_hena
  649. * @adapter: adapter structure
  650. *
  651. * Request hash enable capabilities from PF
  652. **/
  653. void i40evf_get_hena(struct i40evf_adapter *adapter)
  654. {
  655. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  656. /* bail because we already have a command pending */
  657. dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
  658. adapter->current_op);
  659. return;
  660. }
  661. adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
  662. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
  663. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
  664. NULL, 0);
  665. }
  666. /**
  667. * i40evf_set_hena
  668. * @adapter: adapter structure
  669. *
  670. * Request the PF to set our RSS hash capabilities
  671. **/
  672. void i40evf_set_hena(struct i40evf_adapter *adapter)
  673. {
  674. struct virtchnl_rss_hena vrh;
  675. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  676. /* bail because we already have a command pending */
  677. dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
  678. adapter->current_op);
  679. return;
  680. }
  681. vrh.hena = adapter->hena;
  682. adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
  683. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
  684. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
  685. (u8 *)&vrh, sizeof(vrh));
  686. }
  687. /**
  688. * i40evf_set_rss_key
  689. * @adapter: adapter structure
  690. *
  691. * Request the PF to set our RSS hash key
  692. **/
  693. void i40evf_set_rss_key(struct i40evf_adapter *adapter)
  694. {
  695. struct virtchnl_rss_key *vrk;
  696. int len;
  697. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  698. /* bail because we already have a command pending */
  699. dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
  700. adapter->current_op);
  701. return;
  702. }
  703. len = sizeof(struct virtchnl_rss_key) +
  704. (adapter->rss_key_size * sizeof(u8)) - 1;
  705. vrk = kzalloc(len, GFP_KERNEL);
  706. if (!vrk)
  707. return;
  708. vrk->vsi_id = adapter->vsi.id;
  709. vrk->key_len = adapter->rss_key_size;
  710. memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
  711. adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
  712. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
  713. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
  714. (u8 *)vrk, len);
  715. kfree(vrk);
  716. }
  717. /**
  718. * i40evf_set_rss_lut
  719. * @adapter: adapter structure
  720. *
  721. * Request the PF to set our RSS lookup table
  722. **/
  723. void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
  724. {
  725. struct virtchnl_rss_lut *vrl;
  726. int len;
  727. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  728. /* bail because we already have a command pending */
  729. dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
  730. adapter->current_op);
  731. return;
  732. }
  733. len = sizeof(struct virtchnl_rss_lut) +
  734. (adapter->rss_lut_size * sizeof(u8)) - 1;
  735. vrl = kzalloc(len, GFP_KERNEL);
  736. if (!vrl)
  737. return;
  738. vrl->vsi_id = adapter->vsi.id;
  739. vrl->lut_entries = adapter->rss_lut_size;
  740. memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
  741. adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
  742. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
  743. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
  744. (u8 *)vrl, len);
  745. kfree(vrl);
  746. }
  747. /**
  748. * i40evf_enable_vlan_stripping
  749. * @adapter: adapter structure
  750. *
  751. * Request VLAN header stripping to be enabled
  752. **/
  753. void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
  754. {
  755. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  756. /* bail because we already have a command pending */
  757. dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
  758. adapter->current_op);
  759. return;
  760. }
  761. adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
  762. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
  763. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
  764. NULL, 0);
  765. }
  766. /**
  767. * i40evf_disable_vlan_stripping
  768. * @adapter: adapter structure
  769. *
  770. * Request VLAN header stripping to be disabled
  771. **/
  772. void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
  773. {
  774. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  775. /* bail because we already have a command pending */
  776. dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
  777. adapter->current_op);
  778. return;
  779. }
  780. adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
  781. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
  782. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
  783. NULL, 0);
  784. }
  785. /**
  786. * i40evf_print_link_message - print link up or down
  787. * @adapter: adapter structure
  788. *
  789. * Log a message telling the world of our wonderous link status
  790. */
  791. static void i40evf_print_link_message(struct i40evf_adapter *adapter)
  792. {
  793. struct net_device *netdev = adapter->netdev;
  794. char *speed = "Unknown ";
  795. if (!adapter->link_up) {
  796. netdev_info(netdev, "NIC Link is Down\n");
  797. return;
  798. }
  799. switch (adapter->link_speed) {
  800. case I40E_LINK_SPEED_40GB:
  801. speed = "40 G";
  802. break;
  803. case I40E_LINK_SPEED_25GB:
  804. speed = "25 G";
  805. break;
  806. case I40E_LINK_SPEED_20GB:
  807. speed = "20 G";
  808. break;
  809. case I40E_LINK_SPEED_10GB:
  810. speed = "10 G";
  811. break;
  812. case I40E_LINK_SPEED_1GB:
  813. speed = "1000 M";
  814. break;
  815. case I40E_LINK_SPEED_100MB:
  816. speed = "100 M";
  817. break;
  818. default:
  819. break;
  820. }
  821. netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
  822. }
  823. /**
  824. * i40evf_request_reset
  825. * @adapter: adapter structure
  826. *
  827. * Request that the PF reset this VF. No response is expected.
  828. **/
  829. void i40evf_request_reset(struct i40evf_adapter *adapter)
  830. {
  831. /* Don't check CURRENT_OP - this is always higher priority */
  832. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
  833. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  834. }
  835. /**
  836. * i40evf_virtchnl_completion
  837. * @adapter: adapter structure
  838. * @v_opcode: opcode sent by PF
  839. * @v_retval: retval sent by PF
  840. * @msg: message sent by PF
  841. * @msglen: message length
  842. *
  843. * Asynchronous completion function for admin queue messages. Rather than busy
  844. * wait, we fire off our requests and assume that no errors will be returned.
  845. * This function handles the reply messages.
  846. **/
  847. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  848. enum virtchnl_ops v_opcode,
  849. i40e_status v_retval,
  850. u8 *msg, u16 msglen)
  851. {
  852. struct net_device *netdev = adapter->netdev;
  853. if (v_opcode == VIRTCHNL_OP_EVENT) {
  854. struct virtchnl_pf_event *vpe =
  855. (struct virtchnl_pf_event *)msg;
  856. switch (vpe->event) {
  857. case VIRTCHNL_EVENT_LINK_CHANGE:
  858. adapter->link_speed =
  859. vpe->event_data.link_event.link_speed;
  860. if (adapter->link_up !=
  861. vpe->event_data.link_event.link_status) {
  862. adapter->link_up =
  863. vpe->event_data.link_event.link_status;
  864. if (adapter->link_up) {
  865. netif_tx_start_all_queues(netdev);
  866. netif_carrier_on(netdev);
  867. } else {
  868. netif_tx_stop_all_queues(netdev);
  869. netif_carrier_off(netdev);
  870. }
  871. i40evf_print_link_message(adapter);
  872. }
  873. break;
  874. case VIRTCHNL_EVENT_RESET_IMPENDING:
  875. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  876. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  877. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  878. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  879. schedule_work(&adapter->reset_task);
  880. }
  881. break;
  882. default:
  883. dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
  884. vpe->event);
  885. break;
  886. }
  887. return;
  888. }
  889. if (v_retval) {
  890. switch (v_opcode) {
  891. case VIRTCHNL_OP_ADD_VLAN:
  892. dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
  893. i40evf_stat_str(&adapter->hw, v_retval));
  894. break;
  895. case VIRTCHNL_OP_ADD_ETH_ADDR:
  896. dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
  897. i40evf_stat_str(&adapter->hw, v_retval));
  898. break;
  899. case VIRTCHNL_OP_DEL_VLAN:
  900. dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
  901. i40evf_stat_str(&adapter->hw, v_retval));
  902. break;
  903. case VIRTCHNL_OP_DEL_ETH_ADDR:
  904. dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
  905. i40evf_stat_str(&adapter->hw, v_retval));
  906. break;
  907. default:
  908. dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
  909. v_retval,
  910. i40evf_stat_str(&adapter->hw, v_retval),
  911. v_opcode);
  912. }
  913. }
  914. switch (v_opcode) {
  915. case VIRTCHNL_OP_GET_STATS: {
  916. struct i40e_eth_stats *stats =
  917. (struct i40e_eth_stats *)msg;
  918. netdev->stats.rx_packets = stats->rx_unicast +
  919. stats->rx_multicast +
  920. stats->rx_broadcast;
  921. netdev->stats.tx_packets = stats->tx_unicast +
  922. stats->tx_multicast +
  923. stats->tx_broadcast;
  924. netdev->stats.rx_bytes = stats->rx_bytes;
  925. netdev->stats.tx_bytes = stats->tx_bytes;
  926. netdev->stats.tx_errors = stats->tx_errors;
  927. netdev->stats.rx_dropped = stats->rx_discards;
  928. netdev->stats.tx_dropped = stats->tx_discards;
  929. adapter->current_stats = *stats;
  930. }
  931. break;
  932. case VIRTCHNL_OP_GET_VF_RESOURCES: {
  933. u16 len = sizeof(struct virtchnl_vf_resource) +
  934. I40E_MAX_VF_VSI *
  935. sizeof(struct virtchnl_vsi_resource);
  936. memcpy(adapter->vf_res, msg, min(msglen, len));
  937. i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
  938. /* restore current mac address */
  939. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  940. i40evf_process_config(adapter);
  941. }
  942. break;
  943. case VIRTCHNL_OP_ENABLE_QUEUES:
  944. /* enable transmits */
  945. i40evf_irq_enable(adapter, true);
  946. break;
  947. case VIRTCHNL_OP_DISABLE_QUEUES:
  948. i40evf_free_all_tx_resources(adapter);
  949. i40evf_free_all_rx_resources(adapter);
  950. if (adapter->state == __I40EVF_DOWN_PENDING) {
  951. adapter->state = __I40EVF_DOWN;
  952. wake_up(&adapter->down_waitqueue);
  953. }
  954. break;
  955. case VIRTCHNL_OP_VERSION:
  956. case VIRTCHNL_OP_CONFIG_IRQ_MAP:
  957. /* Don't display an error if we get these out of sequence.
  958. * If the firmware needed to get kicked, we'll get these and
  959. * it's no problem.
  960. */
  961. if (v_opcode != adapter->current_op)
  962. return;
  963. break;
  964. case VIRTCHNL_OP_IWARP:
  965. /* Gobble zero-length replies from the PF. They indicate that
  966. * a previous message was received OK, and the client doesn't
  967. * care about that.
  968. */
  969. if (msglen && CLIENT_ENABLED(adapter))
  970. i40evf_notify_client_message(&adapter->vsi,
  971. msg, msglen);
  972. break;
  973. case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  974. adapter->client_pending &=
  975. ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
  976. break;
  977. case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
  978. struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
  979. if (msglen == sizeof(*vrh))
  980. adapter->hena = vrh->hena;
  981. else
  982. dev_warn(&adapter->pdev->dev,
  983. "Invalid message %d from PF\n", v_opcode);
  984. }
  985. break;
  986. default:
  987. if (adapter->current_op && (v_opcode != adapter->current_op))
  988. dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
  989. adapter->current_op, v_opcode);
  990. break;
  991. } /* switch v_opcode */
  992. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  993. }