i40evf_virtchnl.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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;
  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_25GB:
  763. speed = "25 G";
  764. break;
  765. case I40E_LINK_SPEED_20GB:
  766. speed = "20 G";
  767. break;
  768. case I40E_LINK_SPEED_10GB:
  769. speed = "10 G";
  770. break;
  771. case I40E_LINK_SPEED_1GB:
  772. speed = "1000 M";
  773. break;
  774. case I40E_LINK_SPEED_100MB:
  775. speed = "100 M";
  776. break;
  777. default:
  778. break;
  779. }
  780. netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
  781. }
  782. /**
  783. * i40evf_request_reset
  784. * @adapter: adapter structure
  785. *
  786. * Request that the PF reset this VF. No response is expected.
  787. **/
  788. void i40evf_request_reset(struct i40evf_adapter *adapter)
  789. {
  790. /* Don't check CURRENT_OP - this is always higher priority */
  791. i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
  792. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  793. }
  794. /**
  795. * i40evf_virtchnl_completion
  796. * @adapter: adapter structure
  797. * @v_opcode: opcode sent by PF
  798. * @v_retval: retval sent by PF
  799. * @msg: message sent by PF
  800. * @msglen: message length
  801. *
  802. * Asynchronous completion function for admin queue messages. Rather than busy
  803. * wait, we fire off our requests and assume that no errors will be returned.
  804. * This function handles the reply messages.
  805. **/
  806. void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
  807. enum i40e_virtchnl_ops v_opcode,
  808. i40e_status v_retval,
  809. u8 *msg, u16 msglen)
  810. {
  811. struct net_device *netdev = adapter->netdev;
  812. if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
  813. struct i40e_virtchnl_pf_event *vpe =
  814. (struct i40e_virtchnl_pf_event *)msg;
  815. switch (vpe->event) {
  816. case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
  817. adapter->link_speed =
  818. vpe->event_data.link_event.link_speed;
  819. if (adapter->link_up !=
  820. vpe->event_data.link_event.link_status) {
  821. adapter->link_up =
  822. vpe->event_data.link_event.link_status;
  823. if (adapter->link_up) {
  824. netif_tx_start_all_queues(netdev);
  825. netif_carrier_on(netdev);
  826. } else {
  827. netif_tx_stop_all_queues(netdev);
  828. netif_carrier_off(netdev);
  829. }
  830. i40evf_print_link_message(adapter);
  831. }
  832. break;
  833. case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
  834. dev_info(&adapter->pdev->dev, "PF reset warning received\n");
  835. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
  836. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  837. dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
  838. schedule_work(&adapter->reset_task);
  839. }
  840. break;
  841. default:
  842. dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
  843. vpe->event);
  844. break;
  845. }
  846. return;
  847. }
  848. if (v_retval) {
  849. switch (v_opcode) {
  850. case I40E_VIRTCHNL_OP_ADD_VLAN:
  851. dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
  852. i40evf_stat_str(&adapter->hw, v_retval));
  853. break;
  854. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  855. dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
  856. i40evf_stat_str(&adapter->hw, v_retval));
  857. break;
  858. case I40E_VIRTCHNL_OP_DEL_VLAN:
  859. dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
  860. i40evf_stat_str(&adapter->hw, v_retval));
  861. break;
  862. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  863. dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
  864. i40evf_stat_str(&adapter->hw, v_retval));
  865. break;
  866. default:
  867. dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
  868. v_retval,
  869. i40evf_stat_str(&adapter->hw, v_retval),
  870. v_opcode);
  871. }
  872. }
  873. switch (v_opcode) {
  874. case I40E_VIRTCHNL_OP_GET_STATS: {
  875. struct i40e_eth_stats *stats =
  876. (struct i40e_eth_stats *)msg;
  877. adapter->net_stats.rx_packets = stats->rx_unicast +
  878. stats->rx_multicast +
  879. stats->rx_broadcast;
  880. adapter->net_stats.tx_packets = stats->tx_unicast +
  881. stats->tx_multicast +
  882. stats->tx_broadcast;
  883. adapter->net_stats.rx_bytes = stats->rx_bytes;
  884. adapter->net_stats.tx_bytes = stats->tx_bytes;
  885. adapter->net_stats.tx_errors = stats->tx_errors;
  886. adapter->net_stats.rx_dropped = stats->rx_discards;
  887. adapter->net_stats.tx_dropped = stats->tx_discards;
  888. adapter->current_stats = *stats;
  889. }
  890. break;
  891. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
  892. u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
  893. I40E_MAX_VF_VSI *
  894. sizeof(struct i40e_virtchnl_vsi_resource);
  895. memcpy(adapter->vf_res, msg, min(msglen, len));
  896. i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
  897. /* restore current mac address */
  898. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  899. i40evf_process_config(adapter);
  900. }
  901. break;
  902. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  903. /* enable transmits */
  904. i40evf_irq_enable(adapter, true);
  905. break;
  906. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  907. i40evf_free_all_tx_resources(adapter);
  908. i40evf_free_all_rx_resources(adapter);
  909. if (adapter->state == __I40EVF_DOWN_PENDING)
  910. adapter->state = __I40EVF_DOWN;
  911. break;
  912. case I40E_VIRTCHNL_OP_VERSION:
  913. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  914. /* Don't display an error if we get these out of sequence.
  915. * If the firmware needed to get kicked, we'll get these and
  916. * it's no problem.
  917. */
  918. if (v_opcode != adapter->current_op)
  919. return;
  920. break;
  921. case I40E_VIRTCHNL_OP_IWARP:
  922. /* Gobble zero-length replies from the PF. They indicate that
  923. * a previous message was received OK, and the client doesn't
  924. * care about that.
  925. */
  926. if (msglen && CLIENT_ENABLED(adapter))
  927. i40evf_notify_client_message(&adapter->vsi,
  928. msg, msglen);
  929. break;
  930. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  931. adapter->client_pending &=
  932. ~(BIT(I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
  933. break;
  934. case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
  935. struct i40e_virtchnl_rss_hena *vrh =
  936. (struct i40e_virtchnl_rss_hena *)msg;
  937. if (msglen == sizeof(*vrh))
  938. adapter->hena = vrh->hena;
  939. else
  940. dev_warn(&adapter->pdev->dev,
  941. "Invalid message %d from PF\n", v_opcode);
  942. }
  943. break;
  944. default:
  945. if (adapter->current_op && (v_opcode != adapter->current_op))
  946. dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
  947. adapter->current_op, v_opcode);
  948. break;
  949. } /* switch v_opcode */
  950. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  951. }