i40evf_virtchnl.c 30 KB

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