i40evf_virtchnl.c 30 KB

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