i40evf_virtchnl.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  5. * Copyright(c) 2013 - 2014 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #include "i40evf.h"
  28. #include "i40e_prototype.h"
  29. #include "i40evf_client.h"
  30. /* busy wait delay in msec */
  31. #define I40EVF_BUSY_WAIT_DELAY 10
  32. #define I40EVF_BUSY_WAIT_COUNT 50
  33. /**
  34. * i40evf_send_pf_msg
  35. * @adapter: adapter structure
  36. * @op: virtual channel opcode
  37. * @msg: pointer to message buffer
  38. * @len: message length
  39. *
  40. * Send message to PF and print status if failure.
  41. **/
  42. static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
  43. enum virtchnl_ops op, u8 *msg, u16 len)
  44. {
  45. struct i40e_hw *hw = &adapter->hw;
  46. i40e_status err;
  47. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
  48. return 0; /* nothing to see here, move along */
  49. err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
  50. if (err)
  51. dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
  52. op, i40evf_stat_str(hw, err),
  53. i40evf_aq_str(hw, hw->aq.asq_last_status));
  54. return err;
  55. }
  56. /**
  57. * i40evf_send_api_ver
  58. * @adapter: adapter structure
  59. *
  60. * Send API version admin queue message to the PF. The reply is not checked
  61. * in this function. Returns 0 if the message was successfully
  62. * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  63. **/
  64. int i40evf_send_api_ver(struct i40evf_adapter *adapter)
  65. {
  66. struct virtchnl_version_info vvi;
  67. vvi.major = VIRTCHNL_VERSION_MAJOR;
  68. vvi.minor = VIRTCHNL_VERSION_MINOR;
  69. return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
  70. sizeof(vvi));
  71. }
  72. /**
  73. * i40evf_verify_api_ver
  74. * @adapter: adapter structure
  75. *
  76. * Compare API versions with the PF. Must be called after admin queue is
  77. * initialized. Returns 0 if API versions match, -EIO if they do not,
  78. * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
  79. * from the firmware are propagated.
  80. **/
  81. int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
  82. {
  83. struct virtchnl_version_info *pf_vvi;
  84. struct i40e_hw *hw = &adapter->hw;
  85. struct i40e_arq_event_info event;
  86. enum virtchnl_ops op;
  87. i40e_status err;
  88. event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
  89. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  90. if (!event.msg_buf) {
  91. err = -ENOMEM;
  92. goto out;
  93. }
  94. while (1) {
  95. err = i40evf_clean_arq_element(hw, &event, NULL);
  96. /* When the AQ is empty, i40evf_clean_arq_element will return
  97. * nonzero and this loop will terminate.
  98. */
  99. if (err)
  100. goto out_alloc;
  101. op =
  102. (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  103. if (op == VIRTCHNL_OP_VERSION)
  104. break;
  105. }
  106. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  107. if (err)
  108. goto out_alloc;
  109. if (op != VIRTCHNL_OP_VERSION) {
  110. dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
  111. op);
  112. err = -EIO;
  113. goto out_alloc;
  114. }
  115. pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
  116. adapter->pf_version = *pf_vvi;
  117. if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
  118. ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
  119. (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
  120. err = -EIO;
  121. out_alloc:
  122. kfree(event.msg_buf);
  123. out:
  124. return err;
  125. }
  126. /**
  127. * i40evf_send_vf_config_msg
  128. * @adapter: adapter structure
  129. *
  130. * Send VF configuration request admin queue message to the PF. The reply
  131. * is not checked in this function. Returns 0 if the message was
  132. * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
  133. **/
  134. int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
  135. {
  136. u32 caps;
  137. caps = VIRTCHNL_VF_OFFLOAD_L2 |
  138. VIRTCHNL_VF_OFFLOAD_RSS_PF |
  139. VIRTCHNL_VF_OFFLOAD_RSS_AQ |
  140. VIRTCHNL_VF_OFFLOAD_RSS_REG |
  141. VIRTCHNL_VF_OFFLOAD_VLAN |
  142. VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
  143. VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
  144. VIRTCHNL_VF_OFFLOAD_ENCAP |
  145. VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
  146. VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
  147. VIRTCHNL_VF_OFFLOAD_ADQ;
  148. adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
  149. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
  150. if (PF_IS_V11(adapter))
  151. return i40evf_send_pf_msg(adapter,
  152. VIRTCHNL_OP_GET_VF_RESOURCES,
  153. (u8 *)&caps, sizeof(caps));
  154. else
  155. return i40evf_send_pf_msg(adapter,
  156. VIRTCHNL_OP_GET_VF_RESOURCES,
  157. NULL, 0);
  158. }
  159. /**
  160. * i40evf_get_vf_config
  161. * @hw: pointer to the hardware structure
  162. * @len: length of buffer
  163. *
  164. * Get VF configuration from PF and populate hw structure. Must be called after
  165. * admin queue is initialized. Busy waits until response is received from PF,
  166. * with maximum timeout. Response from PF is returned in the buffer for further
  167. * processing by the caller.
  168. **/
  169. int i40evf_get_vf_config(struct i40evf_adapter *adapter)
  170. {
  171. struct i40e_hw *hw = &adapter->hw;
  172. struct i40e_arq_event_info event;
  173. enum virtchnl_ops op;
  174. i40e_status err;
  175. u16 len;
  176. len = sizeof(struct virtchnl_vf_resource) +
  177. I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
  178. event.buf_len = len;
  179. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  180. if (!event.msg_buf) {
  181. err = -ENOMEM;
  182. goto out;
  183. }
  184. while (1) {
  185. /* When the AQ is empty, i40evf_clean_arq_element will return
  186. * nonzero and this loop will terminate.
  187. */
  188. err = i40evf_clean_arq_element(hw, &event, NULL);
  189. if (err)
  190. goto out_alloc;
  191. op =
  192. (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  193. if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
  194. break;
  195. }
  196. err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
  197. memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
  198. i40e_vf_parse_hw_config(hw, adapter->vf_res);
  199. out_alloc:
  200. kfree(event.msg_buf);
  201. out:
  202. return err;
  203. }
  204. /**
  205. * i40evf_configure_queues
  206. * @adapter: adapter structure
  207. *
  208. * Request that the PF set up our (previously allocated) queues.
  209. **/
  210. void i40evf_configure_queues(struct i40evf_adapter *adapter)
  211. {
  212. struct virtchnl_vsi_queue_config_info *vqci;
  213. struct virtchnl_queue_pair_info *vqpi;
  214. int pairs = adapter->num_active_queues;
  215. int i, len, max_frame = I40E_MAX_RXBUFFER;
  216. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  217. /* bail because we already have a command pending */
  218. dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
  219. adapter->current_op);
  220. return;
  221. }
  222. adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
  223. len = sizeof(struct virtchnl_vsi_queue_config_info) +
  224. (sizeof(struct virtchnl_queue_pair_info) * pairs);
  225. vqci = kzalloc(len, GFP_KERNEL);
  226. if (!vqci)
  227. return;
  228. /* Limit maximum frame size when jumbo frames is not enabled */
  229. if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
  230. (adapter->netdev->mtu <= ETH_DATA_LEN))
  231. max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  232. vqci->vsi_id = adapter->vsi_res->vsi_id;
  233. vqci->num_queue_pairs = pairs;
  234. vqpi = vqci->qpair;
  235. /* Size check is not needed here - HW max is 16 queue pairs, and we
  236. * can fit info for 31 of them into the AQ buffer before it overflows.
  237. */
  238. for (i = 0; i < pairs; i++) {
  239. vqpi->txq.vsi_id = vqci->vsi_id;
  240. vqpi->txq.queue_id = i;
  241. vqpi->txq.ring_len = adapter->tx_rings[i].count;
  242. vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
  243. vqpi->rxq.vsi_id = vqci->vsi_id;
  244. vqpi->rxq.queue_id = i;
  245. vqpi->rxq.ring_len = adapter->rx_rings[i].count;
  246. vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
  247. vqpi->rxq.max_pkt_size = max_frame;
  248. vqpi->rxq.databuffer_size =
  249. ALIGN(adapter->rx_rings[i].rx_buf_len,
  250. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  251. vqpi++;
  252. }
  253. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  254. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  255. (u8 *)vqci, len);
  256. kfree(vqci);
  257. }
  258. /**
  259. * i40evf_enable_queues
  260. * @adapter: adapter structure
  261. *
  262. * Request that the PF enable all of our queues.
  263. **/
  264. void i40evf_enable_queues(struct i40evf_adapter *adapter)
  265. {
  266. struct virtchnl_queue_select vqs;
  267. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  268. /* bail because we already have a command pending */
  269. dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
  270. adapter->current_op);
  271. return;
  272. }
  273. adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
  274. vqs.vsi_id = adapter->vsi_res->vsi_id;
  275. vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
  276. vqs.rx_queues = vqs.tx_queues;
  277. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
  278. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
  279. (u8 *)&vqs, sizeof(vqs));
  280. }
  281. /**
  282. * i40evf_disable_queues
  283. * @adapter: adapter structure
  284. *
  285. * Request that the PF disable all of our queues.
  286. **/
  287. void i40evf_disable_queues(struct i40evf_adapter *adapter)
  288. {
  289. struct virtchnl_queue_select vqs;
  290. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  291. /* bail because we already have a command pending */
  292. dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
  293. adapter->current_op);
  294. return;
  295. }
  296. adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
  297. vqs.vsi_id = adapter->vsi_res->vsi_id;
  298. vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
  299. vqs.rx_queues = vqs.tx_queues;
  300. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
  301. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
  302. (u8 *)&vqs, sizeof(vqs));
  303. }
  304. /**
  305. * i40evf_map_queues
  306. * @adapter: adapter structure
  307. *
  308. * Request that the PF map queues to interrupt vectors. Misc causes, including
  309. * admin queue, are always mapped to vector 0.
  310. **/
  311. void i40evf_map_queues(struct i40evf_adapter *adapter)
  312. {
  313. struct virtchnl_irq_map_info *vimi;
  314. struct virtchnl_vector_map *vecmap;
  315. int v_idx, q_vectors, len;
  316. struct i40e_q_vector *q_vector;
  317. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  318. /* bail because we already have a command pending */
  319. dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
  320. adapter->current_op);
  321. return;
  322. }
  323. adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
  324. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  325. len = sizeof(struct virtchnl_irq_map_info) +
  326. (adapter->num_msix_vectors *
  327. sizeof(struct virtchnl_vector_map));
  328. vimi = kzalloc(len, GFP_KERNEL);
  329. if (!vimi)
  330. return;
  331. vimi->num_vectors = adapter->num_msix_vectors;
  332. /* Queue vectors first */
  333. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  334. q_vector = &adapter->q_vectors[v_idx];
  335. vecmap = &vimi->vecmap[v_idx];
  336. vecmap->vsi_id = adapter->vsi_res->vsi_id;
  337. vecmap->vector_id = v_idx + NONQ_VECS;
  338. vecmap->txq_map = q_vector->ring_mask;
  339. vecmap->rxq_map = q_vector->ring_mask;
  340. vecmap->rxitr_idx = I40E_RX_ITR;
  341. vecmap->txitr_idx = I40E_TX_ITR;
  342. }
  343. /* Misc vector last - this is only for AdminQ messages */
  344. vecmap = &vimi->vecmap[v_idx];
  345. vecmap->vsi_id = adapter->vsi_res->vsi_id;
  346. vecmap->vector_id = 0;
  347. vecmap->txq_map = 0;
  348. vecmap->rxq_map = 0;
  349. adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
  350. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
  351. (u8 *)vimi, len);
  352. kfree(vimi);
  353. }
  354. /**
  355. * i40evf_request_queues
  356. * @adapter: adapter structure
  357. * @num: number of requested queues
  358. *
  359. * We get a default number of queues from the PF. This enables us to request a
  360. * different number. Returns 0 on success, negative on failure
  361. **/
  362. int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
  363. {
  364. struct virtchnl_vf_res_request vfres;
  365. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  366. /* bail because we already have a command pending */
  367. dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
  368. adapter->current_op);
  369. return -EBUSY;
  370. }
  371. vfres.num_queue_pairs = num;
  372. adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
  373. adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
  374. return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
  375. (u8 *)&vfres, sizeof(vfres));
  376. }
  377. /**
  378. * i40evf_add_ether_addrs
  379. * @adapter: adapter structure
  380. * @addrs: the MAC address filters to add (contiguous)
  381. * @count: number of filters
  382. *
  383. * Request that the PF add one or more addresses to our filters.
  384. **/
  385. void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
  386. {
  387. struct virtchnl_ether_addr_list *veal;
  388. int len, i = 0, count = 0;
  389. struct i40evf_mac_filter *f;
  390. bool more = false;
  391. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  392. /* bail because we already have a command pending */
  393. dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
  394. adapter->current_op);
  395. return;
  396. }
  397. spin_lock_bh(&adapter->mac_vlan_list_lock);
  398. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  399. if (f->add)
  400. count++;
  401. }
  402. if (!count) {
  403. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  404. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  405. return;
  406. }
  407. adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
  408. len = sizeof(struct virtchnl_ether_addr_list) +
  409. (count * sizeof(struct virtchnl_ether_addr));
  410. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  411. dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
  412. count = (I40EVF_MAX_AQ_BUF_SIZE -
  413. sizeof(struct virtchnl_ether_addr_list)) /
  414. sizeof(struct virtchnl_ether_addr);
  415. len = sizeof(struct virtchnl_ether_addr_list) +
  416. (count * sizeof(struct virtchnl_ether_addr));
  417. more = true;
  418. }
  419. veal = kzalloc(len, GFP_ATOMIC);
  420. if (!veal) {
  421. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  422. return;
  423. }
  424. veal->vsi_id = adapter->vsi_res->vsi_id;
  425. veal->num_elements = count;
  426. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  427. if (f->add) {
  428. ether_addr_copy(veal->list[i].addr, f->macaddr);
  429. i++;
  430. f->add = false;
  431. if (i == count)
  432. break;
  433. }
  434. }
  435. if (!more)
  436. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  437. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  438. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
  439. (u8 *)veal, len);
  440. kfree(veal);
  441. }
  442. /**
  443. * i40evf_del_ether_addrs
  444. * @adapter: adapter structure
  445. * @addrs: the MAC address filters to remove (contiguous)
  446. * @count: number of filtes
  447. *
  448. * Request that the PF remove one or more addresses from our filters.
  449. **/
  450. void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
  451. {
  452. struct virtchnl_ether_addr_list *veal;
  453. struct i40evf_mac_filter *f, *ftmp;
  454. int len, i = 0, count = 0;
  455. bool more = false;
  456. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  457. /* bail because we already have a command pending */
  458. dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
  459. adapter->current_op);
  460. return;
  461. }
  462. spin_lock_bh(&adapter->mac_vlan_list_lock);
  463. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  464. if (f->remove)
  465. count++;
  466. }
  467. if (!count) {
  468. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  469. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  470. return;
  471. }
  472. adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
  473. len = sizeof(struct virtchnl_ether_addr_list) +
  474. (count * sizeof(struct virtchnl_ether_addr));
  475. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  476. dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
  477. count = (I40EVF_MAX_AQ_BUF_SIZE -
  478. sizeof(struct virtchnl_ether_addr_list)) /
  479. sizeof(struct virtchnl_ether_addr);
  480. len = sizeof(struct virtchnl_ether_addr_list) +
  481. (count * sizeof(struct virtchnl_ether_addr));
  482. more = true;
  483. }
  484. veal = kzalloc(len, GFP_ATOMIC);
  485. if (!veal) {
  486. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  487. return;
  488. }
  489. veal->vsi_id = adapter->vsi_res->vsi_id;
  490. veal->num_elements = count;
  491. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  492. if (f->remove) {
  493. ether_addr_copy(veal->list[i].addr, f->macaddr);
  494. i++;
  495. list_del(&f->list);
  496. kfree(f);
  497. if (i == count)
  498. break;
  499. }
  500. }
  501. if (!more)
  502. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  503. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  504. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
  505. (u8 *)veal, len);
  506. kfree(veal);
  507. }
  508. /**
  509. * i40evf_add_vlans
  510. * @adapter: adapter structure
  511. * @vlans: the VLANs to add
  512. * @count: number of VLANs
  513. *
  514. * Request that the PF add one or more VLAN filters to our VSI.
  515. **/
  516. void i40evf_add_vlans(struct i40evf_adapter *adapter)
  517. {
  518. struct virtchnl_vlan_filter_list *vvfl;
  519. int len, i = 0, count = 0;
  520. struct i40evf_vlan_filter *f;
  521. bool more = false;
  522. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  523. /* bail because we already have a command pending */
  524. dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
  525. adapter->current_op);
  526. return;
  527. }
  528. spin_lock_bh(&adapter->mac_vlan_list_lock);
  529. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  530. if (f->add)
  531. count++;
  532. }
  533. if (!count) {
  534. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  535. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  536. return;
  537. }
  538. adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
  539. len = sizeof(struct virtchnl_vlan_filter_list) +
  540. (count * sizeof(u16));
  541. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  542. dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
  543. count = (I40EVF_MAX_AQ_BUF_SIZE -
  544. sizeof(struct virtchnl_vlan_filter_list)) /
  545. sizeof(u16);
  546. len = sizeof(struct virtchnl_vlan_filter_list) +
  547. (count * sizeof(u16));
  548. more = true;
  549. }
  550. vvfl = kzalloc(len, GFP_ATOMIC);
  551. if (!vvfl) {
  552. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  553. return;
  554. }
  555. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  556. vvfl->num_elements = count;
  557. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  558. if (f->add) {
  559. vvfl->vlan_id[i] = f->vlan;
  560. i++;
  561. f->add = false;
  562. if (i == count)
  563. break;
  564. }
  565. }
  566. if (!more)
  567. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  568. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  569. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
  570. kfree(vvfl);
  571. }
  572. /**
  573. * i40evf_del_vlans
  574. * @adapter: adapter structure
  575. * @vlans: the VLANs to remove
  576. * @count: number of VLANs
  577. *
  578. * Request that the PF remove one or more VLAN filters from our VSI.
  579. **/
  580. void i40evf_del_vlans(struct i40evf_adapter *adapter)
  581. {
  582. struct virtchnl_vlan_filter_list *vvfl;
  583. struct i40evf_vlan_filter *f, *ftmp;
  584. int len, i = 0, count = 0;
  585. bool more = false;
  586. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  587. /* bail because we already have a command pending */
  588. dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
  589. adapter->current_op);
  590. return;
  591. }
  592. spin_lock_bh(&adapter->mac_vlan_list_lock);
  593. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  594. if (f->remove)
  595. count++;
  596. }
  597. if (!count) {
  598. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  599. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  600. return;
  601. }
  602. adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
  603. len = sizeof(struct virtchnl_vlan_filter_list) +
  604. (count * sizeof(u16));
  605. if (len > I40EVF_MAX_AQ_BUF_SIZE) {
  606. dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
  607. count = (I40EVF_MAX_AQ_BUF_SIZE -
  608. sizeof(struct virtchnl_vlan_filter_list)) /
  609. sizeof(u16);
  610. len = sizeof(struct virtchnl_vlan_filter_list) +
  611. (count * sizeof(u16));
  612. more = true;
  613. }
  614. vvfl = kzalloc(len, GFP_ATOMIC);
  615. if (!vvfl) {
  616. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  617. return;
  618. }
  619. vvfl->vsi_id = adapter->vsi_res->vsi_id;
  620. vvfl->num_elements = count;
  621. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  622. if (f->remove) {
  623. vvfl->vlan_id[i] = f->vlan;
  624. i++;
  625. list_del(&f->list);
  626. kfree(f);
  627. if (i == count)
  628. break;
  629. }
  630. }
  631. if (!more)
  632. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  633. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  634. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
  635. kfree(vvfl);
  636. }
  637. /**
  638. * i40evf_set_promiscuous
  639. * @adapter: adapter structure
  640. * @flags: bitmask to control unicast/multicast promiscuous.
  641. *
  642. * Request that the PF enable promiscuous mode for our VSI.
  643. **/
  644. void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
  645. {
  646. struct virtchnl_promisc_info vpi;
  647. int promisc_all;
  648. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  649. /* bail because we already have a command pending */
  650. dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
  651. adapter->current_op);
  652. return;
  653. }
  654. promisc_all = FLAG_VF_UNICAST_PROMISC |
  655. FLAG_VF_MULTICAST_PROMISC;
  656. if ((flags & promisc_all) == promisc_all) {
  657. adapter->flags |= I40EVF_FLAG_PROMISC_ON;
  658. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
  659. dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
  660. }
  661. if (flags & FLAG_VF_MULTICAST_PROMISC) {
  662. adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
  663. adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
  664. dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
  665. }
  666. if (!flags) {
  667. adapter->flags &= ~(I40EVF_FLAG_PROMISC_ON |
  668. I40EVF_FLAG_ALLMULTI_ON);
  669. adapter->aq_required &= ~(I40EVF_FLAG_AQ_RELEASE_PROMISC |
  670. I40EVF_FLAG_AQ_RELEASE_ALLMULTI);
  671. dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
  672. }
  673. adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
  674. vpi.vsi_id = adapter->vsi_res->vsi_id;
  675. vpi.flags = flags;
  676. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  677. (u8 *)&vpi, sizeof(vpi));
  678. }
  679. /**
  680. * i40evf_request_stats
  681. * @adapter: adapter structure
  682. *
  683. * Request VSI statistics from PF.
  684. **/
  685. void i40evf_request_stats(struct i40evf_adapter *adapter)
  686. {
  687. struct virtchnl_queue_select vqs;
  688. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  689. /* no error message, this isn't crucial */
  690. return;
  691. }
  692. adapter->current_op = VIRTCHNL_OP_GET_STATS;
  693. vqs.vsi_id = adapter->vsi_res->vsi_id;
  694. /* queue maps are ignored for this message - only the vsi is used */
  695. if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
  696. (u8 *)&vqs, sizeof(vqs)))
  697. /* if the request failed, don't lock out others */
  698. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  699. }
  700. /**
  701. * i40evf_get_hena
  702. * @adapter: adapter structure
  703. *
  704. * Request hash enable capabilities from PF
  705. **/
  706. void i40evf_get_hena(struct i40evf_adapter *adapter)
  707. {
  708. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  709. /* bail because we already have a command pending */
  710. dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
  711. adapter->current_op);
  712. return;
  713. }
  714. adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
  715. adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
  716. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
  717. NULL, 0);
  718. }
  719. /**
  720. * i40evf_set_hena
  721. * @adapter: adapter structure
  722. *
  723. * Request the PF to set our RSS hash capabilities
  724. **/
  725. void i40evf_set_hena(struct i40evf_adapter *adapter)
  726. {
  727. struct virtchnl_rss_hena vrh;
  728. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  729. /* bail because we already have a command pending */
  730. dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
  731. adapter->current_op);
  732. return;
  733. }
  734. vrh.hena = adapter->hena;
  735. adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
  736. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
  737. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
  738. (u8 *)&vrh, sizeof(vrh));
  739. }
  740. /**
  741. * i40evf_set_rss_key
  742. * @adapter: adapter structure
  743. *
  744. * Request the PF to set our RSS hash key
  745. **/
  746. void i40evf_set_rss_key(struct i40evf_adapter *adapter)
  747. {
  748. struct virtchnl_rss_key *vrk;
  749. int len;
  750. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  751. /* bail because we already have a command pending */
  752. dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
  753. adapter->current_op);
  754. return;
  755. }
  756. len = sizeof(struct virtchnl_rss_key) +
  757. (adapter->rss_key_size * sizeof(u8)) - 1;
  758. vrk = kzalloc(len, GFP_KERNEL);
  759. if (!vrk)
  760. return;
  761. vrk->vsi_id = adapter->vsi.id;
  762. vrk->key_len = adapter->rss_key_size;
  763. memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
  764. adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
  765. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
  766. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
  767. (u8 *)vrk, len);
  768. kfree(vrk);
  769. }
  770. /**
  771. * i40evf_set_rss_lut
  772. * @adapter: adapter structure
  773. *
  774. * Request the PF to set our RSS lookup table
  775. **/
  776. void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
  777. {
  778. struct virtchnl_rss_lut *vrl;
  779. int len;
  780. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  781. /* bail because we already have a command pending */
  782. dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
  783. adapter->current_op);
  784. return;
  785. }
  786. len = sizeof(struct virtchnl_rss_lut) +
  787. (adapter->rss_lut_size * sizeof(u8)) - 1;
  788. vrl = kzalloc(len, GFP_KERNEL);
  789. if (!vrl)
  790. return;
  791. vrl->vsi_id = adapter->vsi.id;
  792. vrl->lut_entries = adapter->rss_lut_size;
  793. memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
  794. adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
  795. adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
  796. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
  797. (u8 *)vrl, len);
  798. kfree(vrl);
  799. }
  800. /**
  801. * i40evf_enable_vlan_stripping
  802. * @adapter: adapter structure
  803. *
  804. * Request VLAN header stripping to be enabled
  805. **/
  806. void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
  807. {
  808. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  809. /* bail because we already have a command pending */
  810. dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
  811. adapter->current_op);
  812. return;
  813. }
  814. adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
  815. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
  816. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
  817. NULL, 0);
  818. }
  819. /**
  820. * i40evf_disable_vlan_stripping
  821. * @adapter: adapter structure
  822. *
  823. * Request VLAN header stripping to be disabled
  824. **/
  825. void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
  826. {
  827. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  828. /* bail because we already have a command pending */
  829. dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
  830. adapter->current_op);
  831. return;
  832. }
  833. adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
  834. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
  835. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
  836. NULL, 0);
  837. }
  838. /**
  839. * i40evf_print_link_message - print link up or down
  840. * @adapter: adapter structure
  841. *
  842. * Log a message telling the world of our wonderous link status
  843. */
  844. static void i40evf_print_link_message(struct i40evf_adapter *adapter)
  845. {
  846. struct net_device *netdev = adapter->netdev;
  847. char *speed = "Unknown ";
  848. if (!adapter->link_up) {
  849. netdev_info(netdev, "NIC Link is Down\n");
  850. return;
  851. }
  852. switch (adapter->link_speed) {
  853. case I40E_LINK_SPEED_40GB:
  854. speed = "40 G";
  855. break;
  856. case I40E_LINK_SPEED_25GB:
  857. speed = "25 G";
  858. break;
  859. case I40E_LINK_SPEED_20GB:
  860. speed = "20 G";
  861. break;
  862. case I40E_LINK_SPEED_10GB:
  863. speed = "10 G";
  864. break;
  865. case I40E_LINK_SPEED_1GB:
  866. speed = "1000 M";
  867. break;
  868. case I40E_LINK_SPEED_100MB:
  869. speed = "100 M";
  870. break;
  871. default:
  872. break;
  873. }
  874. netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
  875. }
  876. /**
  877. * i40evf_enable_channel
  878. * @adapter: adapter structure
  879. *
  880. * Request that the PF enable channels as specified by
  881. * the user via tc tool.
  882. **/
  883. void i40evf_enable_channels(struct i40evf_adapter *adapter)
  884. {
  885. struct virtchnl_tc_info *vti = NULL;
  886. u16 len;
  887. int i;
  888. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  889. /* bail because we already have a command pending */
  890. dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
  891. adapter->current_op);
  892. return;
  893. }
  894. len = (adapter->num_tc * sizeof(struct virtchnl_channel_info)) +
  895. sizeof(struct virtchnl_tc_info);
  896. vti = kzalloc(len, GFP_KERNEL);
  897. if (!vti)
  898. return;
  899. vti->num_tc = adapter->num_tc;
  900. for (i = 0; i < vti->num_tc; i++) {
  901. vti->list[i].count = adapter->ch_config.ch_info[i].count;
  902. vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
  903. vti->list[i].pad = 0;
  904. vti->list[i].max_tx_rate =
  905. adapter->ch_config.ch_info[i].max_tx_rate;
  906. }
  907. adapter->ch_config.state = __I40EVF_TC_RUNNING;
  908. adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
  909. adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
  910. adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_CHANNELS;
  911. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS,
  912. (u8 *)vti, len);
  913. kfree(vti);
  914. }
  915. /**
  916. * i40evf_disable_channel
  917. * @adapter: adapter structure
  918. *
  919. * Request that the PF disable channels that are configured
  920. **/
  921. void i40evf_disable_channels(struct i40evf_adapter *adapter)
  922. {
  923. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  924. /* bail because we already have a command pending */
  925. dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
  926. adapter->current_op);
  927. return;
  928. }
  929. adapter->ch_config.state = __I40EVF_TC_INVALID;
  930. adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
  931. adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
  932. adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_CHANNELS;
  933. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS,
  934. NULL, 0);
  935. }
  936. /**
  937. * i40evf_print_cloud_filter
  938. * @adapter: adapter structure
  939. * @f: cloud filter to print
  940. *
  941. * Print the cloud filter
  942. **/
  943. static void i40evf_print_cloud_filter(struct i40evf_adapter *adapter,
  944. struct virtchnl_filter *f)
  945. {
  946. switch (f->flow_type) {
  947. case VIRTCHNL_TCP_V4_FLOW:
  948. dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
  949. &f->data.tcp_spec.dst_mac,
  950. &f->data.tcp_spec.src_mac,
  951. ntohs(f->data.tcp_spec.vlan_id),
  952. &f->data.tcp_spec.dst_ip[0],
  953. &f->data.tcp_spec.src_ip[0],
  954. ntohs(f->data.tcp_spec.dst_port),
  955. ntohs(f->data.tcp_spec.src_port));
  956. break;
  957. case VIRTCHNL_TCP_V6_FLOW:
  958. dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
  959. &f->data.tcp_spec.dst_mac,
  960. &f->data.tcp_spec.src_mac,
  961. ntohs(f->data.tcp_spec.vlan_id),
  962. &f->data.tcp_spec.dst_ip,
  963. &f->data.tcp_spec.src_ip,
  964. ntohs(f->data.tcp_spec.dst_port),
  965. ntohs(f->data.tcp_spec.src_port));
  966. break;
  967. }
  968. }
  969. /**
  970. * i40evf_add_cloud_filter
  971. * @adapter: adapter structure
  972. *
  973. * Request that the PF add cloud filters as specified
  974. * by the user via tc tool.
  975. **/
  976. void i40evf_add_cloud_filter(struct i40evf_adapter *adapter)
  977. {
  978. struct i40evf_cloud_filter *cf;
  979. struct virtchnl_filter *f;
  980. int len = 0, count = 0;
  981. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  982. /* bail because we already have a command pending */
  983. dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
  984. adapter->current_op);
  985. return;
  986. }
  987. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  988. if (cf->add) {
  989. count++;
  990. break;
  991. }
  992. }
  993. if (!count) {
  994. adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_CLOUD_FILTER;
  995. return;
  996. }
  997. adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
  998. len = sizeof(struct virtchnl_filter);
  999. f = kzalloc(len, GFP_KERNEL);
  1000. if (!f)
  1001. return;
  1002. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  1003. if (cf->add) {
  1004. memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
  1005. cf->add = false;
  1006. cf->state = __I40EVF_CF_ADD_PENDING;
  1007. i40evf_send_pf_msg(adapter,
  1008. VIRTCHNL_OP_ADD_CLOUD_FILTER,
  1009. (u8 *)f, len);
  1010. }
  1011. }
  1012. kfree(f);
  1013. }
  1014. /**
  1015. * i40evf_del_cloud_filter
  1016. * @adapter: adapter structure
  1017. *
  1018. * Request that the PF delete cloud filters as specified
  1019. * by the user via tc tool.
  1020. **/
  1021. void i40evf_del_cloud_filter(struct i40evf_adapter *adapter)
  1022. {
  1023. struct i40evf_cloud_filter *cf, *cftmp;
  1024. struct virtchnl_filter *f;
  1025. int len = 0, count = 0;
  1026. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  1027. /* bail because we already have a command pending */
  1028. dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
  1029. adapter->current_op);
  1030. return;
  1031. }
  1032. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  1033. if (cf->del) {
  1034. count++;
  1035. break;
  1036. }
  1037. }
  1038. if (!count) {
  1039. adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_CLOUD_FILTER;
  1040. return;
  1041. }
  1042. adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
  1043. len = sizeof(struct virtchnl_filter);
  1044. f = kzalloc(len, GFP_KERNEL);
  1045. if (!f)
  1046. return;
  1047. list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
  1048. if (cf->del) {
  1049. memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
  1050. cf->del = false;
  1051. cf->state = __I40EVF_CF_DEL_PENDING;
  1052. i40evf_send_pf_msg(adapter,
  1053. VIRTCHNL_OP_DEL_CLOUD_FILTER,
  1054. (u8 *)f, len);
  1055. }
  1056. }
  1057. kfree(f);
  1058. }
  1059. /**
  1060. * i40evf_request_reset
  1061. * @adapter: adapter structure
  1062. *
  1063. * Request that the PF reset this VF. No response is expected.
  1064. **/
  1065. void i40evf_request_reset(struct i40evf_adapter *adapter)
  1066. {
  1067. /* Don't check CURRENT_OP - this is always higher priority */
  1068. i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
  1069. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  1070. }
  1071. /**
  1072. * i40evf_virtchnl_completion
  1073. * @adapter: adapter structure
  1074. * @v_opcode: opcode sent by PF
  1075. * @v_retval: retval sent by PF
  1076. * @msg: message sent by PF
  1077. * @msglen: message length
  1078. *
  1079. * Asynchronous completion function for admin queue messages. Rather than busy
  1080. * wait, we fire off our requests and assume that no errors will be returned.
  1081. * This function handles the reply messages.
  1082. **/
  1083. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  1084. enum virtchnl_ops v_opcode,
  1085. i40e_status v_retval,
  1086. u8 *msg, u16 msglen)
  1087. {
  1088. struct net_device *netdev = adapter->netdev;
  1089. if (v_opcode == VIRTCHNL_OP_EVENT) {
  1090. struct virtchnl_pf_event *vpe =
  1091. (struct virtchnl_pf_event *)msg;
  1092. bool link_up = vpe->event_data.link_event.link_status;
  1093. switch (vpe->event) {
  1094. case VIRTCHNL_EVENT_LINK_CHANGE:
  1095. adapter->link_speed =
  1096. vpe->event_data.link_event.link_speed;
  1097. /* we've already got the right link status, bail */
  1098. if (adapter->link_up == link_up)
  1099. break;
  1100. if (link_up) {
  1101. /* If we get link up message and start queues
  1102. * before our queues are configured it will
  1103. * trigger a TX hang. In that case, just ignore
  1104. * the link status message,we'll get another one
  1105. * after we enable queues and actually prepared
  1106. * to send traffic.
  1107. */
  1108. if (adapter->state != __I40EVF_RUNNING)
  1109. break;
  1110. /* For ADq enabled VF, we reconfigure VSIs and
  1111. * re-allocate queues. Hence wait till all
  1112. * queues are enabled.
  1113. */
  1114. if (adapter->flags &
  1115. I40EVF_FLAG_QUEUES_DISABLED)
  1116. break;
  1117. }
  1118. adapter->link_up = link_up;
  1119. if (link_up) {
  1120. netif_tx_start_all_queues(netdev);
  1121. netif_carrier_on(netdev);
  1122. } else {
  1123. netif_tx_stop_all_queues(netdev);
  1124. netif_carrier_off(netdev);
  1125. }
  1126. i40evf_print_link_message(adapter);
  1127. break;
  1128. case VIRTCHNL_EVENT_RESET_IMPENDING:
  1129. dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
  1130. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  1131. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  1132. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  1133. schedule_work(&adapter->reset_task);
  1134. }
  1135. break;
  1136. default:
  1137. dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
  1138. vpe->event);
  1139. break;
  1140. }
  1141. return;
  1142. }
  1143. if (v_retval) {
  1144. switch (v_opcode) {
  1145. case VIRTCHNL_OP_ADD_VLAN:
  1146. dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
  1147. i40evf_stat_str(&adapter->hw, v_retval));
  1148. break;
  1149. case VIRTCHNL_OP_ADD_ETH_ADDR:
  1150. dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
  1151. i40evf_stat_str(&adapter->hw, v_retval));
  1152. break;
  1153. case VIRTCHNL_OP_DEL_VLAN:
  1154. dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
  1155. i40evf_stat_str(&adapter->hw, v_retval));
  1156. break;
  1157. case VIRTCHNL_OP_DEL_ETH_ADDR:
  1158. dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
  1159. i40evf_stat_str(&adapter->hw, v_retval));
  1160. break;
  1161. case VIRTCHNL_OP_ENABLE_CHANNELS:
  1162. dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
  1163. i40evf_stat_str(&adapter->hw, v_retval));
  1164. adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
  1165. adapter->ch_config.state = __I40EVF_TC_INVALID;
  1166. netdev_reset_tc(netdev);
  1167. netif_tx_start_all_queues(netdev);
  1168. break;
  1169. case VIRTCHNL_OP_DISABLE_CHANNELS:
  1170. dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
  1171. i40evf_stat_str(&adapter->hw, v_retval));
  1172. adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
  1173. adapter->ch_config.state = __I40EVF_TC_RUNNING;
  1174. netif_tx_start_all_queues(netdev);
  1175. break;
  1176. case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
  1177. struct i40evf_cloud_filter *cf, *cftmp;
  1178. list_for_each_entry_safe(cf, cftmp,
  1179. &adapter->cloud_filter_list,
  1180. list) {
  1181. if (cf->state == __I40EVF_CF_ADD_PENDING) {
  1182. cf->state = __I40EVF_CF_INVALID;
  1183. dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
  1184. i40evf_stat_str(&adapter->hw,
  1185. v_retval));
  1186. i40evf_print_cloud_filter(adapter,
  1187. &cf->f);
  1188. list_del(&cf->list);
  1189. kfree(cf);
  1190. adapter->num_cloud_filters--;
  1191. }
  1192. }
  1193. }
  1194. break;
  1195. case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
  1196. struct i40evf_cloud_filter *cf;
  1197. list_for_each_entry(cf, &adapter->cloud_filter_list,
  1198. list) {
  1199. if (cf->state == __I40EVF_CF_DEL_PENDING) {
  1200. cf->state = __I40EVF_CF_ACTIVE;
  1201. dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
  1202. i40evf_stat_str(&adapter->hw,
  1203. v_retval));
  1204. i40evf_print_cloud_filter(adapter,
  1205. &cf->f);
  1206. }
  1207. }
  1208. }
  1209. break;
  1210. default:
  1211. dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
  1212. v_retval,
  1213. i40evf_stat_str(&adapter->hw, v_retval),
  1214. v_opcode);
  1215. }
  1216. }
  1217. switch (v_opcode) {
  1218. case VIRTCHNL_OP_GET_STATS: {
  1219. struct i40e_eth_stats *stats =
  1220. (struct i40e_eth_stats *)msg;
  1221. netdev->stats.rx_packets = stats->rx_unicast +
  1222. stats->rx_multicast +
  1223. stats->rx_broadcast;
  1224. netdev->stats.tx_packets = stats->tx_unicast +
  1225. stats->tx_multicast +
  1226. stats->tx_broadcast;
  1227. netdev->stats.rx_bytes = stats->rx_bytes;
  1228. netdev->stats.tx_bytes = stats->tx_bytes;
  1229. netdev->stats.tx_errors = stats->tx_errors;
  1230. netdev->stats.rx_dropped = stats->rx_discards;
  1231. netdev->stats.tx_dropped = stats->tx_discards;
  1232. adapter->current_stats = *stats;
  1233. }
  1234. break;
  1235. case VIRTCHNL_OP_GET_VF_RESOURCES: {
  1236. u16 len = sizeof(struct virtchnl_vf_resource) +
  1237. I40E_MAX_VF_VSI *
  1238. sizeof(struct virtchnl_vsi_resource);
  1239. memcpy(adapter->vf_res, msg, min(msglen, len));
  1240. i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
  1241. /* restore current mac address */
  1242. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  1243. i40evf_process_config(adapter);
  1244. }
  1245. break;
  1246. case VIRTCHNL_OP_ENABLE_QUEUES:
  1247. /* enable transmits */
  1248. i40evf_irq_enable(adapter, true);
  1249. adapter->flags &= ~I40EVF_FLAG_QUEUES_DISABLED;
  1250. break;
  1251. case VIRTCHNL_OP_DISABLE_QUEUES:
  1252. i40evf_free_all_tx_resources(adapter);
  1253. i40evf_free_all_rx_resources(adapter);
  1254. if (adapter->state == __I40EVF_DOWN_PENDING) {
  1255. adapter->state = __I40EVF_DOWN;
  1256. wake_up(&adapter->down_waitqueue);
  1257. }
  1258. break;
  1259. case VIRTCHNL_OP_VERSION:
  1260. case VIRTCHNL_OP_CONFIG_IRQ_MAP:
  1261. /* Don't display an error if we get these out of sequence.
  1262. * If the firmware needed to get kicked, we'll get these and
  1263. * it's no problem.
  1264. */
  1265. if (v_opcode != adapter->current_op)
  1266. return;
  1267. break;
  1268. case VIRTCHNL_OP_IWARP:
  1269. /* Gobble zero-length replies from the PF. They indicate that
  1270. * a previous message was received OK, and the client doesn't
  1271. * care about that.
  1272. */
  1273. if (msglen && CLIENT_ENABLED(adapter))
  1274. i40evf_notify_client_message(&adapter->vsi,
  1275. msg, msglen);
  1276. break;
  1277. case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  1278. adapter->client_pending &=
  1279. ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
  1280. break;
  1281. case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
  1282. struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
  1283. if (msglen == sizeof(*vrh))
  1284. adapter->hena = vrh->hena;
  1285. else
  1286. dev_warn(&adapter->pdev->dev,
  1287. "Invalid message %d from PF\n", v_opcode);
  1288. }
  1289. break;
  1290. case VIRTCHNL_OP_REQUEST_QUEUES: {
  1291. struct virtchnl_vf_res_request *vfres =
  1292. (struct virtchnl_vf_res_request *)msg;
  1293. if (vfres->num_queue_pairs != adapter->num_req_queues) {
  1294. dev_info(&adapter->pdev->dev,
  1295. "Requested %d queues, PF can support %d\n",
  1296. adapter->num_req_queues,
  1297. vfres->num_queue_pairs);
  1298. adapter->num_req_queues = 0;
  1299. adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
  1300. }
  1301. }
  1302. break;
  1303. case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
  1304. struct i40evf_cloud_filter *cf;
  1305. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  1306. if (cf->state == __I40EVF_CF_ADD_PENDING)
  1307. cf->state = __I40EVF_CF_ACTIVE;
  1308. }
  1309. }
  1310. break;
  1311. case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
  1312. struct i40evf_cloud_filter *cf, *cftmp;
  1313. list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
  1314. list) {
  1315. if (cf->state == __I40EVF_CF_DEL_PENDING) {
  1316. cf->state = __I40EVF_CF_INVALID;
  1317. list_del(&cf->list);
  1318. kfree(cf);
  1319. adapter->num_cloud_filters--;
  1320. }
  1321. }
  1322. }
  1323. break;
  1324. default:
  1325. if (adapter->current_op && (v_opcode != adapter->current_op))
  1326. dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
  1327. adapter->current_op, v_opcode);
  1328. break;
  1329. } /* switch v_opcode */
  1330. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  1331. }