i40evf_virtchnl.c 30 KB

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