vf.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include "vf.h"
  4. #include "ixgbevf.h"
  5. /* On Hyper-V, to reset, we need to read from this offset
  6. * from the PCI config space. This is the mechanism used on
  7. * Hyper-V to support PF/VF communication.
  8. */
  9. #define IXGBE_HV_RESET_OFFSET 0x201
  10. static inline s32 ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw, u32 *msg,
  11. u32 *retmsg, u16 size)
  12. {
  13. struct ixgbe_mbx_info *mbx = &hw->mbx;
  14. s32 retval = mbx->ops.write_posted(hw, msg, size);
  15. if (retval)
  16. return retval;
  17. return mbx->ops.read_posted(hw, retmsg, size);
  18. }
  19. /**
  20. * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  21. * @hw: pointer to hardware structure
  22. *
  23. * Starts the hardware by filling the bus info structure and media type, clears
  24. * all on chip counters, initializes receive address registers, multicast
  25. * table, VLAN filter table, calls routine to set up link and flow control
  26. * settings, and leaves transmit and receive units disabled and uninitialized
  27. **/
  28. static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
  29. {
  30. /* Clear adapter stopped flag */
  31. hw->adapter_stopped = false;
  32. return 0;
  33. }
  34. /**
  35. * ixgbevf_init_hw_vf - virtual function hardware initialization
  36. * @hw: pointer to hardware structure
  37. *
  38. * Initialize the hardware by resetting the hardware and then starting
  39. * the hardware
  40. **/
  41. static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
  42. {
  43. s32 status = hw->mac.ops.start_hw(hw);
  44. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  45. return status;
  46. }
  47. /**
  48. * ixgbevf_reset_hw_vf - Performs hardware reset
  49. * @hw: pointer to hardware structure
  50. *
  51. * Resets the hardware by resetting the transmit and receive units, masks and
  52. * clears all interrupts.
  53. **/
  54. static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
  55. {
  56. struct ixgbe_mbx_info *mbx = &hw->mbx;
  57. u32 timeout = IXGBE_VF_INIT_TIMEOUT;
  58. s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
  59. u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
  60. u8 *addr = (u8 *)(&msgbuf[1]);
  61. /* Call adapter stop to disable tx/rx and clear interrupts */
  62. hw->mac.ops.stop_adapter(hw);
  63. /* reset the api version */
  64. hw->api_version = ixgbe_mbox_api_10;
  65. IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
  66. IXGBE_WRITE_FLUSH(hw);
  67. /* we cannot reset while the RSTI / RSTD bits are asserted */
  68. while (!mbx->ops.check_for_rst(hw) && timeout) {
  69. timeout--;
  70. udelay(5);
  71. }
  72. if (!timeout)
  73. return IXGBE_ERR_RESET_FAILED;
  74. /* mailbox timeout can now become active */
  75. mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
  76. msgbuf[0] = IXGBE_VF_RESET;
  77. mbx->ops.write_posted(hw, msgbuf, 1);
  78. mdelay(10);
  79. /* set our "perm_addr" based on info provided by PF
  80. * also set up the mc_filter_type which is piggy backed
  81. * on the mac address in word 3
  82. */
  83. ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN);
  84. if (ret_val)
  85. return ret_val;
  86. /* New versions of the PF may NACK the reset return message
  87. * to indicate that no MAC address has yet been assigned for
  88. * the VF.
  89. */
  90. if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
  91. msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
  92. return IXGBE_ERR_INVALID_MAC_ADDR;
  93. if (msgbuf[0] == (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK))
  94. ether_addr_copy(hw->mac.perm_addr, addr);
  95. hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
  96. return 0;
  97. }
  98. /**
  99. * Hyper-V variant; the VF/PF communication is through the PCI
  100. * config space.
  101. * @hw: pointer to private hardware struct
  102. */
  103. static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
  104. {
  105. #if IS_ENABLED(CONFIG_PCI_MMCONFIG)
  106. struct ixgbevf_adapter *adapter = hw->back;
  107. int i;
  108. for (i = 0; i < 6; i++)
  109. pci_read_config_byte(adapter->pdev,
  110. (i + IXGBE_HV_RESET_OFFSET),
  111. &hw->mac.perm_addr[i]);
  112. return 0;
  113. #else
  114. pr_err("PCI_MMCONFIG needs to be enabled for Hyper-V\n");
  115. return -EOPNOTSUPP;
  116. #endif
  117. }
  118. /**
  119. * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  120. * @hw: pointer to hardware structure
  121. *
  122. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  123. * disables transmit and receive units. The adapter_stopped flag is used by
  124. * the shared code and drivers to determine if the adapter is in a stopped
  125. * state and should not touch the hardware.
  126. **/
  127. static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
  128. {
  129. u32 number_of_queues;
  130. u32 reg_val;
  131. u16 i;
  132. /* Set the adapter_stopped flag so other driver functions stop touching
  133. * the hardware
  134. */
  135. hw->adapter_stopped = true;
  136. /* Disable the receive unit by stopped each queue */
  137. number_of_queues = hw->mac.max_rx_queues;
  138. for (i = 0; i < number_of_queues; i++) {
  139. reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
  140. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  141. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  142. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
  143. }
  144. }
  145. IXGBE_WRITE_FLUSH(hw);
  146. /* Clear interrupt mask to stop from interrupts being generated */
  147. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
  148. /* Clear any pending interrupts */
  149. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  150. /* Disable the transmit unit. Each queue must be disabled. */
  151. number_of_queues = hw->mac.max_tx_queues;
  152. for (i = 0; i < number_of_queues; i++) {
  153. reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
  154. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  155. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  156. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
  157. }
  158. }
  159. return 0;
  160. }
  161. /**
  162. * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
  163. * @hw: pointer to hardware structure
  164. * @mc_addr: the multicast address
  165. *
  166. * Extracts the 12 bits, from a multicast address, to determine which
  167. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  168. * incoming Rx multicast addresses, to determine the bit-vector to check in
  169. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  170. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  171. * to mc_filter_type.
  172. **/
  173. static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  174. {
  175. u32 vector = 0;
  176. switch (hw->mac.mc_filter_type) {
  177. case 0: /* use bits [47:36] of the address */
  178. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  179. break;
  180. case 1: /* use bits [46:35] of the address */
  181. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  182. break;
  183. case 2: /* use bits [45:34] of the address */
  184. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  185. break;
  186. case 3: /* use bits [43:32] of the address */
  187. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  188. break;
  189. default: /* Invalid mc_filter_type */
  190. break;
  191. }
  192. /* vector can only be 12-bits or boundary will be exceeded */
  193. vector &= 0xFFF;
  194. return vector;
  195. }
  196. /**
  197. * ixgbevf_get_mac_addr_vf - Read device MAC address
  198. * @hw: pointer to the HW structure
  199. * @mac_addr: pointer to storage for retrieved MAC address
  200. **/
  201. static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
  202. {
  203. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  204. return 0;
  205. }
  206. static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  207. {
  208. u32 msgbuf[3], msgbuf_chk;
  209. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  210. s32 ret_val;
  211. memset(msgbuf, 0, sizeof(msgbuf));
  212. /* If index is one then this is the start of a new list and needs
  213. * indication to the PF so it can do it's own list management.
  214. * If it is zero then that tells the PF to just clear all of
  215. * this VF's macvlans and there is no new list.
  216. */
  217. msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
  218. msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
  219. msgbuf_chk = msgbuf[0];
  220. if (addr)
  221. ether_addr_copy(msg_addr, addr);
  222. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  223. ARRAY_SIZE(msgbuf));
  224. if (!ret_val) {
  225. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  226. if (msgbuf[0] == (msgbuf_chk | IXGBE_VT_MSGTYPE_NACK))
  227. return -ENOMEM;
  228. }
  229. return ret_val;
  230. }
  231. static s32 ixgbevf_hv_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  232. {
  233. return -EOPNOTSUPP;
  234. }
  235. /**
  236. * ixgbevf_get_reta_locked - get the RSS redirection table (RETA) contents.
  237. * @hw: pointer to hardware structure
  238. * @reta: buffer to fill with RETA contents.
  239. * @num_rx_queues: Number of Rx queues configured for this port
  240. *
  241. * The "reta" buffer should be big enough to contain 32 registers.
  242. *
  243. * Returns: 0 on success.
  244. * if API doesn't support this operation - (-EOPNOTSUPP).
  245. */
  246. int ixgbevf_get_reta_locked(struct ixgbe_hw *hw, u32 *reta, int num_rx_queues)
  247. {
  248. int err, i, j;
  249. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  250. u32 *hw_reta = &msgbuf[1];
  251. u32 mask = 0;
  252. /* We have to use a mailbox for 82599 and x540 devices only.
  253. * For these devices RETA has 128 entries.
  254. * Also these VFs support up to 4 RSS queues. Therefore PF will compress
  255. * 16 RETA entries in each DWORD giving 2 bits to each entry.
  256. */
  257. int dwords = IXGBEVF_82599_RETA_SIZE / 16;
  258. /* We support the RSS querying for 82599 and x540 devices only.
  259. * Thus return an error if API doesn't support RETA querying or querying
  260. * is not supported for this device type.
  261. */
  262. switch (hw->api_version) {
  263. case ixgbe_mbox_api_13:
  264. case ixgbe_mbox_api_12:
  265. if (hw->mac.type < ixgbe_mac_X550_vf)
  266. break;
  267. /* fall through */
  268. default:
  269. return -EOPNOTSUPP;
  270. }
  271. msgbuf[0] = IXGBE_VF_GET_RETA;
  272. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  273. if (err)
  274. return err;
  275. err = hw->mbx.ops.read_posted(hw, msgbuf, dwords + 1);
  276. if (err)
  277. return err;
  278. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  279. /* If the operation has been refused by a PF return -EPERM */
  280. if (msgbuf[0] == (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_NACK))
  281. return -EPERM;
  282. /* If we didn't get an ACK there must have been
  283. * some sort of mailbox error so we should treat it
  284. * as such.
  285. */
  286. if (msgbuf[0] != (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_ACK))
  287. return IXGBE_ERR_MBX;
  288. /* ixgbevf doesn't support more than 2 queues at the moment */
  289. if (num_rx_queues > 1)
  290. mask = 0x1;
  291. for (i = 0; i < dwords; i++)
  292. for (j = 0; j < 16; j++)
  293. reta[i * 16 + j] = (hw_reta[i] >> (2 * j)) & mask;
  294. return 0;
  295. }
  296. /**
  297. * ixgbevf_get_rss_key_locked - get the RSS Random Key
  298. * @hw: pointer to the HW structure
  299. * @rss_key: buffer to fill with RSS Hash Key contents.
  300. *
  301. * The "rss_key" buffer should be big enough to contain 10 registers.
  302. *
  303. * Returns: 0 on success.
  304. * if API doesn't support this operation - (-EOPNOTSUPP).
  305. */
  306. int ixgbevf_get_rss_key_locked(struct ixgbe_hw *hw, u8 *rss_key)
  307. {
  308. int err;
  309. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  310. /* We currently support the RSS Random Key retrieval for 82599 and x540
  311. * devices only.
  312. *
  313. * Thus return an error if API doesn't support RSS Random Key retrieval
  314. * or if the operation is not supported for this device type.
  315. */
  316. switch (hw->api_version) {
  317. case ixgbe_mbox_api_13:
  318. case ixgbe_mbox_api_12:
  319. if (hw->mac.type < ixgbe_mac_X550_vf)
  320. break;
  321. /* fall through */
  322. default:
  323. return -EOPNOTSUPP;
  324. }
  325. msgbuf[0] = IXGBE_VF_GET_RSS_KEY;
  326. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  327. if (err)
  328. return err;
  329. err = hw->mbx.ops.read_posted(hw, msgbuf, 11);
  330. if (err)
  331. return err;
  332. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  333. /* If the operation has been refused by a PF return -EPERM */
  334. if (msgbuf[0] == (IXGBE_VF_GET_RSS_KEY | IXGBE_VT_MSGTYPE_NACK))
  335. return -EPERM;
  336. /* If we didn't get an ACK there must have been
  337. * some sort of mailbox error so we should treat it
  338. * as such.
  339. */
  340. if (msgbuf[0] != (IXGBE_VF_GET_RSS_KEY | IXGBE_VT_MSGTYPE_ACK))
  341. return IXGBE_ERR_MBX;
  342. memcpy(rss_key, msgbuf + 1, IXGBEVF_RSS_HASH_KEY_SIZE);
  343. return 0;
  344. }
  345. /**
  346. * ixgbevf_set_rar_vf - set device MAC address
  347. * @hw: pointer to hardware structure
  348. * @index: Receive address register to write
  349. * @addr: Address to put into receive address register
  350. * @vmdq: Unused in this implementation
  351. **/
  352. static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  353. u32 vmdq)
  354. {
  355. u32 msgbuf[3];
  356. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  357. s32 ret_val;
  358. memset(msgbuf, 0, sizeof(msgbuf));
  359. msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
  360. ether_addr_copy(msg_addr, addr);
  361. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  362. ARRAY_SIZE(msgbuf));
  363. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  364. /* if nacked the address was rejected, use "perm_addr" */
  365. if (!ret_val &&
  366. (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK))) {
  367. ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
  368. return IXGBE_ERR_MBX;
  369. }
  370. return ret_val;
  371. }
  372. /**
  373. * ixgbevf_hv_set_rar_vf - set device MAC address Hyper-V variant
  374. * @hw: pointer to hardware structure
  375. * @index: Receive address register to write
  376. * @addr: Address to put into receive address register
  377. * @vmdq: Unused in this implementation
  378. *
  379. * We don't really allow setting the device MAC address. However,
  380. * if the address being set is the permanent MAC address we will
  381. * permit that.
  382. **/
  383. static s32 ixgbevf_hv_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  384. u32 vmdq)
  385. {
  386. if (ether_addr_equal(addr, hw->mac.perm_addr))
  387. return 0;
  388. return -EOPNOTSUPP;
  389. }
  390. /**
  391. * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
  392. * @hw: pointer to the HW structure
  393. * @netdev: pointer to net device structure
  394. *
  395. * Updates the Multicast Table Array.
  396. **/
  397. static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  398. struct net_device *netdev)
  399. {
  400. struct netdev_hw_addr *ha;
  401. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  402. u16 *vector_list = (u16 *)&msgbuf[1];
  403. u32 cnt, i;
  404. /* Each entry in the list uses 1 16 bit word. We have 30
  405. * 16 bit words available in our HW msg buffer (minus 1 for the
  406. * msg type). That's 30 hash values if we pack 'em right. If
  407. * there are more than 30 MC addresses to add then punt the
  408. * extras for now and then add code to handle more than 30 later.
  409. * It would be unusual for a server to request that many multi-cast
  410. * addresses except for in large enterprise network environments.
  411. */
  412. cnt = netdev_mc_count(netdev);
  413. if (cnt > 30)
  414. cnt = 30;
  415. msgbuf[0] = IXGBE_VF_SET_MULTICAST;
  416. msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
  417. i = 0;
  418. netdev_for_each_mc_addr(ha, netdev) {
  419. if (i == cnt)
  420. break;
  421. if (is_link_local_ether_addr(ha->addr))
  422. continue;
  423. vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
  424. }
  425. ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, IXGBE_VFMAILBOX_SIZE);
  426. return 0;
  427. }
  428. /**
  429. * Hyper-V variant - just a stub.
  430. * @hw: unused
  431. * @netdev: unused
  432. */
  433. static s32 ixgbevf_hv_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  434. struct net_device *netdev)
  435. {
  436. return -EOPNOTSUPP;
  437. }
  438. /**
  439. * ixgbevf_update_xcast_mode - Update Multicast mode
  440. * @hw: pointer to the HW structure
  441. * @xcast_mode: new multicast mode
  442. *
  443. * Updates the Multicast Mode of VF.
  444. **/
  445. static s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
  446. {
  447. u32 msgbuf[2];
  448. s32 err;
  449. switch (hw->api_version) {
  450. case ixgbe_mbox_api_12:
  451. /* promisc introduced in 1.3 version */
  452. if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
  453. return -EOPNOTSUPP;
  454. /* Fall threw */
  455. case ixgbe_mbox_api_13:
  456. break;
  457. default:
  458. return -EOPNOTSUPP;
  459. }
  460. msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
  461. msgbuf[1] = xcast_mode;
  462. err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  463. ARRAY_SIZE(msgbuf));
  464. if (err)
  465. return err;
  466. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  467. if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_NACK))
  468. return -EPERM;
  469. return 0;
  470. }
  471. /**
  472. * Hyper-V variant - just a stub.
  473. * @hw: unused
  474. * @xcast_mode: unused
  475. */
  476. static s32 ixgbevf_hv_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
  477. {
  478. return -EOPNOTSUPP;
  479. }
  480. /**
  481. * ixgbevf_set_vfta_vf - Set/Unset VLAN filter table address
  482. * @hw: pointer to the HW structure
  483. * @vlan: 12 bit VLAN ID
  484. * @vind: unused by VF drivers
  485. * @vlan_on: if true then set bit, else clear bit
  486. **/
  487. static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  488. bool vlan_on)
  489. {
  490. u32 msgbuf[2];
  491. s32 err;
  492. msgbuf[0] = IXGBE_VF_SET_VLAN;
  493. msgbuf[1] = vlan;
  494. /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
  495. msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
  496. err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  497. ARRAY_SIZE(msgbuf));
  498. if (err)
  499. goto mbx_err;
  500. /* remove extra bits from the message */
  501. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  502. msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT);
  503. if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK))
  504. err = IXGBE_ERR_INVALID_ARGUMENT;
  505. mbx_err:
  506. return err;
  507. }
  508. /**
  509. * Hyper-V variant - just a stub.
  510. * @hw: unused
  511. * @vlan: unused
  512. * @vind: unused
  513. * @vlan_on: unused
  514. */
  515. static s32 ixgbevf_hv_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  516. bool vlan_on)
  517. {
  518. return -EOPNOTSUPP;
  519. }
  520. /**
  521. * ixgbevf_setup_mac_link_vf - Setup MAC link settings
  522. * @hw: pointer to hardware structure
  523. * @speed: Unused in this implementation
  524. * @autoneg: Unused in this implementation
  525. * @autoneg_wait_to_complete: Unused in this implementation
  526. *
  527. * Do nothing and return success. VF drivers are not allowed to change
  528. * global settings. Maintained for driver compatibility.
  529. **/
  530. static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
  531. ixgbe_link_speed speed, bool autoneg,
  532. bool autoneg_wait_to_complete)
  533. {
  534. return 0;
  535. }
  536. /**
  537. * ixgbevf_check_mac_link_vf - Get link/speed status
  538. * @hw: pointer to hardware structure
  539. * @speed: pointer to link speed
  540. * @link_up: true is link is up, false otherwise
  541. * @autoneg_wait_to_complete: unused
  542. *
  543. * Reads the links register to determine if link is up and the current speed
  544. **/
  545. static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
  546. ixgbe_link_speed *speed,
  547. bool *link_up,
  548. bool autoneg_wait_to_complete)
  549. {
  550. struct ixgbe_mbx_info *mbx = &hw->mbx;
  551. struct ixgbe_mac_info *mac = &hw->mac;
  552. s32 ret_val = 0;
  553. u32 links_reg;
  554. u32 in_msg = 0;
  555. /* If we were hit with a reset drop the link */
  556. if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
  557. mac->get_link_status = true;
  558. if (!mac->get_link_status)
  559. goto out;
  560. /* if link status is down no point in checking to see if pf is up */
  561. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  562. if (!(links_reg & IXGBE_LINKS_UP))
  563. goto out;
  564. /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
  565. * before the link status is correct
  566. */
  567. if (mac->type == ixgbe_mac_82599_vf) {
  568. int i;
  569. for (i = 0; i < 5; i++) {
  570. udelay(100);
  571. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  572. if (!(links_reg & IXGBE_LINKS_UP))
  573. goto out;
  574. }
  575. }
  576. switch (links_reg & IXGBE_LINKS_SPEED_82599) {
  577. case IXGBE_LINKS_SPEED_10G_82599:
  578. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  579. break;
  580. case IXGBE_LINKS_SPEED_1G_82599:
  581. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  582. break;
  583. case IXGBE_LINKS_SPEED_100_82599:
  584. *speed = IXGBE_LINK_SPEED_100_FULL;
  585. break;
  586. }
  587. /* if the read failed it could just be a mailbox collision, best wait
  588. * until we are called again and don't report an error
  589. */
  590. if (mbx->ops.read(hw, &in_msg, 1))
  591. goto out;
  592. if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
  593. /* msg is not CTS and is NACK we must have lost CTS status */
  594. if (in_msg & IXGBE_VT_MSGTYPE_NACK)
  595. ret_val = -1;
  596. goto out;
  597. }
  598. /* the pf is talking, if we timed out in the past we reinit */
  599. if (!mbx->timeout) {
  600. ret_val = -1;
  601. goto out;
  602. }
  603. /* if we passed all the tests above then the link is up and we no
  604. * longer need to check for link
  605. */
  606. mac->get_link_status = false;
  607. out:
  608. *link_up = !mac->get_link_status;
  609. return ret_val;
  610. }
  611. /**
  612. * Hyper-V variant; there is no mailbox communication.
  613. * @hw: pointer to private hardware struct
  614. * @speed: pointer to link speed
  615. * @link_up: true is link is up, false otherwise
  616. * @autoneg_wait_to_complete: unused
  617. */
  618. static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
  619. ixgbe_link_speed *speed,
  620. bool *link_up,
  621. bool autoneg_wait_to_complete)
  622. {
  623. struct ixgbe_mbx_info *mbx = &hw->mbx;
  624. struct ixgbe_mac_info *mac = &hw->mac;
  625. u32 links_reg;
  626. /* If we were hit with a reset drop the link */
  627. if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
  628. mac->get_link_status = true;
  629. if (!mac->get_link_status)
  630. goto out;
  631. /* if link status is down no point in checking to see if pf is up */
  632. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  633. if (!(links_reg & IXGBE_LINKS_UP))
  634. goto out;
  635. /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
  636. * before the link status is correct
  637. */
  638. if (mac->type == ixgbe_mac_82599_vf) {
  639. int i;
  640. for (i = 0; i < 5; i++) {
  641. udelay(100);
  642. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  643. if (!(links_reg & IXGBE_LINKS_UP))
  644. goto out;
  645. }
  646. }
  647. switch (links_reg & IXGBE_LINKS_SPEED_82599) {
  648. case IXGBE_LINKS_SPEED_10G_82599:
  649. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  650. break;
  651. case IXGBE_LINKS_SPEED_1G_82599:
  652. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  653. break;
  654. case IXGBE_LINKS_SPEED_100_82599:
  655. *speed = IXGBE_LINK_SPEED_100_FULL;
  656. break;
  657. }
  658. /* if we passed all the tests above then the link is up and we no
  659. * longer need to check for link
  660. */
  661. mac->get_link_status = false;
  662. out:
  663. *link_up = !mac->get_link_status;
  664. return 0;
  665. }
  666. /**
  667. * ixgbevf_set_rlpml_vf - Set the maximum receive packet length
  668. * @hw: pointer to the HW structure
  669. * @max_size: value to assign to max frame size
  670. **/
  671. static s32 ixgbevf_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
  672. {
  673. u32 msgbuf[2];
  674. s32 ret_val;
  675. msgbuf[0] = IXGBE_VF_SET_LPE;
  676. msgbuf[1] = max_size;
  677. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  678. ARRAY_SIZE(msgbuf));
  679. if (ret_val)
  680. return ret_val;
  681. if ((msgbuf[0] & IXGBE_VF_SET_LPE) &&
  682. (msgbuf[0] & IXGBE_VT_MSGTYPE_NACK))
  683. return IXGBE_ERR_MBX;
  684. return 0;
  685. }
  686. /**
  687. * ixgbevf_hv_set_rlpml_vf - Set the maximum receive packet length
  688. * @hw: pointer to the HW structure
  689. * @max_size: value to assign to max frame size
  690. * Hyper-V variant.
  691. **/
  692. static s32 ixgbevf_hv_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
  693. {
  694. u32 reg;
  695. /* If we are on Hyper-V, we implement this functionality
  696. * differently.
  697. */
  698. reg = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
  699. /* CRC == 4 */
  700. reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
  701. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
  702. return 0;
  703. }
  704. /**
  705. * ixgbevf_negotiate_api_version_vf - Negotiate supported API version
  706. * @hw: pointer to the HW structure
  707. * @api: integer containing requested API version
  708. **/
  709. static int ixgbevf_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
  710. {
  711. int err;
  712. u32 msg[3];
  713. /* Negotiate the mailbox API version */
  714. msg[0] = IXGBE_VF_API_NEGOTIATE;
  715. msg[1] = api;
  716. msg[2] = 0;
  717. err = ixgbevf_write_msg_read_ack(hw, msg, msg, ARRAY_SIZE(msg));
  718. if (!err) {
  719. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  720. /* Store value and return 0 on success */
  721. if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
  722. hw->api_version = api;
  723. return 0;
  724. }
  725. err = IXGBE_ERR_INVALID_ARGUMENT;
  726. }
  727. return err;
  728. }
  729. /**
  730. * ixgbevf_hv_negotiate_api_version_vf - Negotiate supported API version
  731. * @hw: pointer to the HW structure
  732. * @api: integer containing requested API version
  733. * Hyper-V version - only ixgbe_mbox_api_10 supported.
  734. **/
  735. static int ixgbevf_hv_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
  736. {
  737. /* Hyper-V only supports api version ixgbe_mbox_api_10 */
  738. if (api != ixgbe_mbox_api_10)
  739. return IXGBE_ERR_INVALID_ARGUMENT;
  740. return 0;
  741. }
  742. int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
  743. unsigned int *default_tc)
  744. {
  745. int err;
  746. u32 msg[5];
  747. /* do nothing if API doesn't support ixgbevf_get_queues */
  748. switch (hw->api_version) {
  749. case ixgbe_mbox_api_11:
  750. case ixgbe_mbox_api_12:
  751. case ixgbe_mbox_api_13:
  752. break;
  753. default:
  754. return 0;
  755. }
  756. /* Fetch queue configuration from the PF */
  757. msg[0] = IXGBE_VF_GET_QUEUE;
  758. msg[1] = msg[2] = msg[3] = msg[4] = 0;
  759. err = ixgbevf_write_msg_read_ack(hw, msg, msg, ARRAY_SIZE(msg));
  760. if (!err) {
  761. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  762. /* if we we didn't get an ACK there must have been
  763. * some sort of mailbox error so we should treat it
  764. * as such
  765. */
  766. if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK))
  767. return IXGBE_ERR_MBX;
  768. /* record and validate values from message */
  769. hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
  770. if (hw->mac.max_tx_queues == 0 ||
  771. hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
  772. hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
  773. hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
  774. if (hw->mac.max_rx_queues == 0 ||
  775. hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
  776. hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
  777. *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
  778. /* in case of unknown state assume we cannot tag frames */
  779. if (*num_tcs > hw->mac.max_rx_queues)
  780. *num_tcs = 1;
  781. *default_tc = msg[IXGBE_VF_DEF_QUEUE];
  782. /* default to queue 0 on out-of-bounds queue number */
  783. if (*default_tc >= hw->mac.max_tx_queues)
  784. *default_tc = 0;
  785. }
  786. return err;
  787. }
  788. static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
  789. .init_hw = ixgbevf_init_hw_vf,
  790. .reset_hw = ixgbevf_reset_hw_vf,
  791. .start_hw = ixgbevf_start_hw_vf,
  792. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  793. .stop_adapter = ixgbevf_stop_hw_vf,
  794. .setup_link = ixgbevf_setup_mac_link_vf,
  795. .check_link = ixgbevf_check_mac_link_vf,
  796. .negotiate_api_version = ixgbevf_negotiate_api_version_vf,
  797. .set_rar = ixgbevf_set_rar_vf,
  798. .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
  799. .update_xcast_mode = ixgbevf_update_xcast_mode,
  800. .set_uc_addr = ixgbevf_set_uc_addr_vf,
  801. .set_vfta = ixgbevf_set_vfta_vf,
  802. .set_rlpml = ixgbevf_set_rlpml_vf,
  803. };
  804. static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
  805. .init_hw = ixgbevf_init_hw_vf,
  806. .reset_hw = ixgbevf_hv_reset_hw_vf,
  807. .start_hw = ixgbevf_start_hw_vf,
  808. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  809. .stop_adapter = ixgbevf_stop_hw_vf,
  810. .setup_link = ixgbevf_setup_mac_link_vf,
  811. .check_link = ixgbevf_hv_check_mac_link_vf,
  812. .negotiate_api_version = ixgbevf_hv_negotiate_api_version_vf,
  813. .set_rar = ixgbevf_hv_set_rar_vf,
  814. .update_mc_addr_list = ixgbevf_hv_update_mc_addr_list_vf,
  815. .update_xcast_mode = ixgbevf_hv_update_xcast_mode,
  816. .set_uc_addr = ixgbevf_hv_set_uc_addr_vf,
  817. .set_vfta = ixgbevf_hv_set_vfta_vf,
  818. .set_rlpml = ixgbevf_hv_set_rlpml_vf,
  819. };
  820. const struct ixgbevf_info ixgbevf_82599_vf_info = {
  821. .mac = ixgbe_mac_82599_vf,
  822. .mac_ops = &ixgbevf_mac_ops,
  823. };
  824. const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
  825. .mac = ixgbe_mac_82599_vf,
  826. .mac_ops = &ixgbevf_hv_mac_ops,
  827. };
  828. const struct ixgbevf_info ixgbevf_X540_vf_info = {
  829. .mac = ixgbe_mac_X540_vf,
  830. .mac_ops = &ixgbevf_mac_ops,
  831. };
  832. const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
  833. .mac = ixgbe_mac_X540_vf,
  834. .mac_ops = &ixgbevf_hv_mac_ops,
  835. };
  836. const struct ixgbevf_info ixgbevf_X550_vf_info = {
  837. .mac = ixgbe_mac_X550_vf,
  838. .mac_ops = &ixgbevf_mac_ops,
  839. };
  840. const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
  841. .mac = ixgbe_mac_X550_vf,
  842. .mac_ops = &ixgbevf_hv_mac_ops,
  843. };
  844. const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
  845. .mac = ixgbe_mac_X550EM_x_vf,
  846. .mac_ops = &ixgbevf_mac_ops,
  847. };
  848. const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
  849. .mac = ixgbe_mac_X550EM_x_vf,
  850. .mac_ops = &ixgbevf_hv_mac_ops,
  851. };
  852. const struct ixgbevf_info ixgbevf_x550em_a_vf_info = {
  853. .mac = ixgbe_mac_x550em_a_vf,
  854. .mac_ops = &ixgbevf_mac_ops,
  855. };