vf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2015 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, see <http://www.gnu.org/licenses/>.
  13. The full GNU General Public License is included in this distribution in
  14. the file called "COPYING".
  15. Contact Information:
  16. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. *******************************************************************************/
  19. #include "vf.h"
  20. #include "ixgbevf.h"
  21. /**
  22. * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  23. * @hw: pointer to hardware structure
  24. *
  25. * Starts the hardware by filling the bus info structure and media type, clears
  26. * all on chip counters, initializes receive address registers, multicast
  27. * table, VLAN filter table, calls routine to set up link and flow control
  28. * settings, and leaves transmit and receive units disabled and uninitialized
  29. **/
  30. static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
  31. {
  32. /* Clear adapter stopped flag */
  33. hw->adapter_stopped = false;
  34. return 0;
  35. }
  36. /**
  37. * ixgbevf_init_hw_vf - virtual function hardware initialization
  38. * @hw: pointer to hardware structure
  39. *
  40. * Initialize the hardware by resetting the hardware and then starting
  41. * the hardware
  42. **/
  43. static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
  44. {
  45. s32 status = hw->mac.ops.start_hw(hw);
  46. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  47. return status;
  48. }
  49. /**
  50. * ixgbevf_reset_hw_vf - Performs hardware reset
  51. * @hw: pointer to hardware structure
  52. *
  53. * Resets the hardware by resetting the transmit and receive units, masks and
  54. * clears all interrupts.
  55. **/
  56. static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
  57. {
  58. struct ixgbe_mbx_info *mbx = &hw->mbx;
  59. u32 timeout = IXGBE_VF_INIT_TIMEOUT;
  60. s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
  61. u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
  62. u8 *addr = (u8 *)(&msgbuf[1]);
  63. /* Call adapter stop to disable tx/rx and clear interrupts */
  64. hw->mac.ops.stop_adapter(hw);
  65. /* reset the api version */
  66. hw->api_version = ixgbe_mbox_api_10;
  67. IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
  68. IXGBE_WRITE_FLUSH(hw);
  69. /* we cannot reset while the RSTI / RSTD bits are asserted */
  70. while (!mbx->ops.check_for_rst(hw) && timeout) {
  71. timeout--;
  72. udelay(5);
  73. }
  74. if (!timeout)
  75. return IXGBE_ERR_RESET_FAILED;
  76. /* mailbox timeout can now become active */
  77. mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
  78. msgbuf[0] = IXGBE_VF_RESET;
  79. mbx->ops.write_posted(hw, msgbuf, 1);
  80. mdelay(10);
  81. /* set our "perm_addr" based on info provided by PF
  82. * also set up the mc_filter_type which is piggy backed
  83. * on the mac address in word 3
  84. */
  85. ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN);
  86. if (ret_val)
  87. return ret_val;
  88. /* New versions of the PF may NACK the reset return message
  89. * to indicate that no MAC address has yet been assigned for
  90. * the VF.
  91. */
  92. if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
  93. msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
  94. return IXGBE_ERR_INVALID_MAC_ADDR;
  95. ether_addr_copy(hw->mac.perm_addr, addr);
  96. hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
  97. return 0;
  98. }
  99. /**
  100. * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  101. * @hw: pointer to hardware structure
  102. *
  103. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  104. * disables transmit and receive units. The adapter_stopped flag is used by
  105. * the shared code and drivers to determine if the adapter is in a stopped
  106. * state and should not touch the hardware.
  107. **/
  108. static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
  109. {
  110. u32 number_of_queues;
  111. u32 reg_val;
  112. u16 i;
  113. /* Set the adapter_stopped flag so other driver functions stop touching
  114. * the hardware
  115. */
  116. hw->adapter_stopped = true;
  117. /* Disable the receive unit by stopped each queue */
  118. number_of_queues = hw->mac.max_rx_queues;
  119. for (i = 0; i < number_of_queues; i++) {
  120. reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
  121. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  122. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  123. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
  124. }
  125. }
  126. IXGBE_WRITE_FLUSH(hw);
  127. /* Clear interrupt mask to stop from interrupts being generated */
  128. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
  129. /* Clear any pending interrupts */
  130. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  131. /* Disable the transmit unit. Each queue must be disabled. */
  132. number_of_queues = hw->mac.max_tx_queues;
  133. for (i = 0; i < number_of_queues; i++) {
  134. reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
  135. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  136. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  137. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
  138. }
  139. }
  140. return 0;
  141. }
  142. /**
  143. * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
  144. * @hw: pointer to hardware structure
  145. * @mc_addr: the multicast address
  146. *
  147. * Extracts the 12 bits, from a multicast address, to determine which
  148. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  149. * incoming Rx multicast addresses, to determine the bit-vector to check in
  150. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  151. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  152. * to mc_filter_type.
  153. **/
  154. static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  155. {
  156. u32 vector = 0;
  157. switch (hw->mac.mc_filter_type) {
  158. case 0: /* use bits [47:36] of the address */
  159. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  160. break;
  161. case 1: /* use bits [46:35] of the address */
  162. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  163. break;
  164. case 2: /* use bits [45:34] of the address */
  165. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  166. break;
  167. case 3: /* use bits [43:32] of the address */
  168. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  169. break;
  170. default: /* Invalid mc_filter_type */
  171. break;
  172. }
  173. /* vector can only be 12-bits or boundary will be exceeded */
  174. vector &= 0xFFF;
  175. return vector;
  176. }
  177. /**
  178. * ixgbevf_get_mac_addr_vf - Read device MAC address
  179. * @hw: pointer to the HW structure
  180. * @mac_addr: pointer to storage for retrieved MAC address
  181. **/
  182. static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
  183. {
  184. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  185. return 0;
  186. }
  187. static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  188. {
  189. struct ixgbe_mbx_info *mbx = &hw->mbx;
  190. u32 msgbuf[3];
  191. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  192. s32 ret_val;
  193. memset(msgbuf, 0, sizeof(msgbuf));
  194. /* If index is one then this is the start of a new list and needs
  195. * indication to the PF so it can do it's own list management.
  196. * If it is zero then that tells the PF to just clear all of
  197. * this VF's macvlans and there is no new list.
  198. */
  199. msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
  200. msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
  201. if (addr)
  202. ether_addr_copy(msg_addr, addr);
  203. ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
  204. if (!ret_val)
  205. ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
  206. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  207. if (!ret_val)
  208. if (msgbuf[0] ==
  209. (IXGBE_VF_SET_MACVLAN | IXGBE_VT_MSGTYPE_NACK))
  210. ret_val = -ENOMEM;
  211. return ret_val;
  212. }
  213. /**
  214. * ixgbevf_get_reta_locked - get the RSS redirection table (RETA) contents.
  215. * @adapter: pointer to the port handle
  216. * @reta: buffer to fill with RETA contents.
  217. * @num_rx_queues: Number of Rx queues configured for this port
  218. *
  219. * The "reta" buffer should be big enough to contain 32 registers.
  220. *
  221. * Returns: 0 on success.
  222. * if API doesn't support this operation - (-EOPNOTSUPP).
  223. */
  224. int ixgbevf_get_reta_locked(struct ixgbe_hw *hw, u32 *reta, int num_rx_queues)
  225. {
  226. int err, i, j;
  227. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  228. u32 *hw_reta = &msgbuf[1];
  229. u32 mask = 0;
  230. /* We have to use a mailbox for 82599 and x540 devices only.
  231. * For these devices RETA has 128 entries.
  232. * Also these VFs support up to 4 RSS queues. Therefore PF will compress
  233. * 16 RETA entries in each DWORD giving 2 bits to each entry.
  234. */
  235. int dwords = IXGBEVF_82599_RETA_SIZE / 16;
  236. /* We support the RSS querying for 82599 and x540 devices only.
  237. * Thus return an error if API doesn't support RETA querying or querying
  238. * is not supported for this device type.
  239. */
  240. if (hw->api_version != ixgbe_mbox_api_12 ||
  241. hw->mac.type >= ixgbe_mac_X550_vf)
  242. return -EOPNOTSUPP;
  243. msgbuf[0] = IXGBE_VF_GET_RETA;
  244. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  245. if (err)
  246. return err;
  247. err = hw->mbx.ops.read_posted(hw, msgbuf, dwords + 1);
  248. if (err)
  249. return err;
  250. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  251. /* If the operation has been refused by a PF return -EPERM */
  252. if (msgbuf[0] == (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_NACK))
  253. return -EPERM;
  254. /* If we didn't get an ACK there must have been
  255. * some sort of mailbox error so we should treat it
  256. * as such.
  257. */
  258. if (msgbuf[0] != (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_ACK))
  259. return IXGBE_ERR_MBX;
  260. /* ixgbevf doesn't support more than 2 queues at the moment */
  261. if (num_rx_queues > 1)
  262. mask = 0x1;
  263. for (i = 0; i < dwords; i++)
  264. for (j = 0; j < 16; j++)
  265. reta[i * 16 + j] = (hw_reta[i] >> (2 * j)) & mask;
  266. return 0;
  267. }
  268. /**
  269. * ixgbevf_get_rss_key_locked - get the RSS Random Key
  270. * @hw: pointer to the HW structure
  271. * @rss_key: buffer to fill with RSS Hash Key contents.
  272. *
  273. * The "rss_key" buffer should be big enough to contain 10 registers.
  274. *
  275. * Returns: 0 on success.
  276. * if API doesn't support this operation - (-EOPNOTSUPP).
  277. */
  278. int ixgbevf_get_rss_key_locked(struct ixgbe_hw *hw, u8 *rss_key)
  279. {
  280. int err;
  281. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  282. /* We currently support the RSS Random Key retrieval for 82599 and x540
  283. * devices only.
  284. *
  285. * Thus return an error if API doesn't support RSS Random Key retrieval
  286. * or if the operation is not supported for this device type.
  287. */
  288. if (hw->api_version != ixgbe_mbox_api_12 ||
  289. hw->mac.type >= ixgbe_mac_X550_vf)
  290. return -EOPNOTSUPP;
  291. msgbuf[0] = IXGBE_VF_GET_RSS_KEY;
  292. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  293. if (err)
  294. return err;
  295. err = hw->mbx.ops.read_posted(hw, msgbuf, 11);
  296. if (err)
  297. return err;
  298. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  299. /* If the operation has been refused by a PF return -EPERM */
  300. if (msgbuf[0] == (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_NACK))
  301. return -EPERM;
  302. /* If we didn't get an ACK there must have been
  303. * some sort of mailbox error so we should treat it
  304. * as such.
  305. */
  306. if (msgbuf[0] != (IXGBE_VF_GET_RSS_KEY | IXGBE_VT_MSGTYPE_ACK))
  307. return IXGBE_ERR_MBX;
  308. memcpy(rss_key, msgbuf + 1, IXGBEVF_RSS_HASH_KEY_SIZE);
  309. return 0;
  310. }
  311. /**
  312. * ixgbevf_set_rar_vf - set device MAC address
  313. * @hw: pointer to hardware structure
  314. * @index: Receive address register to write
  315. * @addr: Address to put into receive address register
  316. * @vmdq: Unused in this implementation
  317. **/
  318. static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  319. u32 vmdq)
  320. {
  321. struct ixgbe_mbx_info *mbx = &hw->mbx;
  322. u32 msgbuf[3];
  323. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  324. s32 ret_val;
  325. memset(msgbuf, 0, sizeof(msgbuf));
  326. msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
  327. ether_addr_copy(msg_addr, addr);
  328. ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
  329. if (!ret_val)
  330. ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
  331. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  332. /* if nacked the address was rejected, use "perm_addr" */
  333. if (!ret_val &&
  334. (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK)))
  335. ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
  336. return ret_val;
  337. }
  338. static void ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw,
  339. u32 *msg, u16 size)
  340. {
  341. struct ixgbe_mbx_info *mbx = &hw->mbx;
  342. u32 retmsg[IXGBE_VFMAILBOX_SIZE];
  343. s32 retval = mbx->ops.write_posted(hw, msg, size);
  344. if (!retval)
  345. mbx->ops.read_posted(hw, retmsg, size);
  346. }
  347. /**
  348. * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
  349. * @hw: pointer to the HW structure
  350. * @netdev: pointer to net device structure
  351. *
  352. * Updates the Multicast Table Array.
  353. **/
  354. static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  355. struct net_device *netdev)
  356. {
  357. struct netdev_hw_addr *ha;
  358. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  359. u16 *vector_list = (u16 *)&msgbuf[1];
  360. u32 cnt, i;
  361. /* Each entry in the list uses 1 16 bit word. We have 30
  362. * 16 bit words available in our HW msg buffer (minus 1 for the
  363. * msg type). That's 30 hash values if we pack 'em right. If
  364. * there are more than 30 MC addresses to add then punt the
  365. * extras for now and then add code to handle more than 30 later.
  366. * It would be unusual for a server to request that many multi-cast
  367. * addresses except for in large enterprise network environments.
  368. */
  369. cnt = netdev_mc_count(netdev);
  370. if (cnt > 30)
  371. cnt = 30;
  372. msgbuf[0] = IXGBE_VF_SET_MULTICAST;
  373. msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
  374. i = 0;
  375. netdev_for_each_mc_addr(ha, netdev) {
  376. if (i == cnt)
  377. break;
  378. if (is_link_local_ether_addr(ha->addr))
  379. continue;
  380. vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
  381. }
  382. ixgbevf_write_msg_read_ack(hw, msgbuf, IXGBE_VFMAILBOX_SIZE);
  383. return 0;
  384. }
  385. /**
  386. * ixgbevf_set_vfta_vf - Set/Unset VLAN filter table address
  387. * @hw: pointer to the HW structure
  388. * @vlan: 12 bit VLAN ID
  389. * @vind: unused by VF drivers
  390. * @vlan_on: if true then set bit, else clear bit
  391. **/
  392. static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  393. bool vlan_on)
  394. {
  395. struct ixgbe_mbx_info *mbx = &hw->mbx;
  396. u32 msgbuf[2];
  397. s32 err;
  398. msgbuf[0] = IXGBE_VF_SET_VLAN;
  399. msgbuf[1] = vlan;
  400. /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
  401. msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
  402. err = mbx->ops.write_posted(hw, msgbuf, 2);
  403. if (err)
  404. goto mbx_err;
  405. err = mbx->ops.read_posted(hw, msgbuf, 2);
  406. if (err)
  407. goto mbx_err;
  408. /* remove extra bits from the message */
  409. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  410. msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT);
  411. if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK))
  412. err = IXGBE_ERR_INVALID_ARGUMENT;
  413. mbx_err:
  414. return err;
  415. }
  416. /**
  417. * ixgbevf_setup_mac_link_vf - Setup MAC link settings
  418. * @hw: pointer to hardware structure
  419. * @speed: Unused in this implementation
  420. * @autoneg: Unused in this implementation
  421. * @autoneg_wait_to_complete: Unused in this implementation
  422. *
  423. * Do nothing and return success. VF drivers are not allowed to change
  424. * global settings. Maintained for driver compatibility.
  425. **/
  426. static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
  427. ixgbe_link_speed speed, bool autoneg,
  428. bool autoneg_wait_to_complete)
  429. {
  430. return 0;
  431. }
  432. /**
  433. * ixgbevf_check_mac_link_vf - Get link/speed status
  434. * @hw: pointer to hardware structure
  435. * @speed: pointer to link speed
  436. * @link_up: true is link is up, false otherwise
  437. * @autoneg_wait_to_complete: true when waiting for completion is needed
  438. *
  439. * Reads the links register to determine if link is up and the current speed
  440. **/
  441. static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
  442. ixgbe_link_speed *speed,
  443. bool *link_up,
  444. bool autoneg_wait_to_complete)
  445. {
  446. struct ixgbe_mbx_info *mbx = &hw->mbx;
  447. struct ixgbe_mac_info *mac = &hw->mac;
  448. s32 ret_val = 0;
  449. u32 links_reg;
  450. u32 in_msg = 0;
  451. /* If we were hit with a reset drop the link */
  452. if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
  453. mac->get_link_status = true;
  454. if (!mac->get_link_status)
  455. goto out;
  456. /* if link status is down no point in checking to see if pf is up */
  457. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  458. if (!(links_reg & IXGBE_LINKS_UP))
  459. goto out;
  460. /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
  461. * before the link status is correct
  462. */
  463. if (mac->type == ixgbe_mac_82599_vf) {
  464. int i;
  465. for (i = 0; i < 5; i++) {
  466. udelay(100);
  467. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  468. if (!(links_reg & IXGBE_LINKS_UP))
  469. goto out;
  470. }
  471. }
  472. switch (links_reg & IXGBE_LINKS_SPEED_82599) {
  473. case IXGBE_LINKS_SPEED_10G_82599:
  474. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  475. break;
  476. case IXGBE_LINKS_SPEED_1G_82599:
  477. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  478. break;
  479. case IXGBE_LINKS_SPEED_100_82599:
  480. *speed = IXGBE_LINK_SPEED_100_FULL;
  481. break;
  482. }
  483. /* if the read failed it could just be a mailbox collision, best wait
  484. * until we are called again and don't report an error
  485. */
  486. if (mbx->ops.read(hw, &in_msg, 1))
  487. goto out;
  488. if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
  489. /* msg is not CTS and is NACK we must have lost CTS status */
  490. if (in_msg & IXGBE_VT_MSGTYPE_NACK)
  491. ret_val = -1;
  492. goto out;
  493. }
  494. /* the pf is talking, if we timed out in the past we reinit */
  495. if (!mbx->timeout) {
  496. ret_val = -1;
  497. goto out;
  498. }
  499. /* if we passed all the tests above then the link is up and we no
  500. * longer need to check for link
  501. */
  502. mac->get_link_status = false;
  503. out:
  504. *link_up = !mac->get_link_status;
  505. return ret_val;
  506. }
  507. /**
  508. * ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  509. * @hw: pointer to the HW structure
  510. * @max_size: value to assign to max frame size
  511. **/
  512. void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
  513. {
  514. u32 msgbuf[2];
  515. msgbuf[0] = IXGBE_VF_SET_LPE;
  516. msgbuf[1] = max_size;
  517. ixgbevf_write_msg_read_ack(hw, msgbuf, 2);
  518. }
  519. /**
  520. * ixgbevf_negotiate_api_version - Negotiate supported API version
  521. * @hw: pointer to the HW structure
  522. * @api: integer containing requested API version
  523. **/
  524. int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
  525. {
  526. int err;
  527. u32 msg[3];
  528. /* Negotiate the mailbox API version */
  529. msg[0] = IXGBE_VF_API_NEGOTIATE;
  530. msg[1] = api;
  531. msg[2] = 0;
  532. err = hw->mbx.ops.write_posted(hw, msg, 3);
  533. if (!err)
  534. err = hw->mbx.ops.read_posted(hw, msg, 3);
  535. if (!err) {
  536. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  537. /* Store value and return 0 on success */
  538. if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
  539. hw->api_version = api;
  540. return 0;
  541. }
  542. err = IXGBE_ERR_INVALID_ARGUMENT;
  543. }
  544. return err;
  545. }
  546. int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
  547. unsigned int *default_tc)
  548. {
  549. int err;
  550. u32 msg[5];
  551. /* do nothing if API doesn't support ixgbevf_get_queues */
  552. switch (hw->api_version) {
  553. case ixgbe_mbox_api_11:
  554. case ixgbe_mbox_api_12:
  555. break;
  556. default:
  557. return 0;
  558. }
  559. /* Fetch queue configuration from the PF */
  560. msg[0] = IXGBE_VF_GET_QUEUE;
  561. msg[1] = msg[2] = msg[3] = msg[4] = 0;
  562. err = hw->mbx.ops.write_posted(hw, msg, 5);
  563. if (!err)
  564. err = hw->mbx.ops.read_posted(hw, msg, 5);
  565. if (!err) {
  566. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  567. /* if we we didn't get an ACK there must have been
  568. * some sort of mailbox error so we should treat it
  569. * as such
  570. */
  571. if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK))
  572. return IXGBE_ERR_MBX;
  573. /* record and validate values from message */
  574. hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
  575. if (hw->mac.max_tx_queues == 0 ||
  576. hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
  577. hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
  578. hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
  579. if (hw->mac.max_rx_queues == 0 ||
  580. hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
  581. hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
  582. *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
  583. /* in case of unknown state assume we cannot tag frames */
  584. if (*num_tcs > hw->mac.max_rx_queues)
  585. *num_tcs = 1;
  586. *default_tc = msg[IXGBE_VF_DEF_QUEUE];
  587. /* default to queue 0 on out-of-bounds queue number */
  588. if (*default_tc >= hw->mac.max_tx_queues)
  589. *default_tc = 0;
  590. }
  591. return err;
  592. }
  593. static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
  594. .init_hw = ixgbevf_init_hw_vf,
  595. .reset_hw = ixgbevf_reset_hw_vf,
  596. .start_hw = ixgbevf_start_hw_vf,
  597. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  598. .stop_adapter = ixgbevf_stop_hw_vf,
  599. .setup_link = ixgbevf_setup_mac_link_vf,
  600. .check_link = ixgbevf_check_mac_link_vf,
  601. .set_rar = ixgbevf_set_rar_vf,
  602. .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
  603. .set_uc_addr = ixgbevf_set_uc_addr_vf,
  604. .set_vfta = ixgbevf_set_vfta_vf,
  605. };
  606. const struct ixgbevf_info ixgbevf_82599_vf_info = {
  607. .mac = ixgbe_mac_82599_vf,
  608. .mac_ops = &ixgbevf_mac_ops,
  609. };
  610. const struct ixgbevf_info ixgbevf_X540_vf_info = {
  611. .mac = ixgbe_mac_X540_vf,
  612. .mac_ops = &ixgbevf_mac_ops,
  613. };
  614. const struct ixgbevf_info ixgbevf_X550_vf_info = {
  615. .mac = ixgbe_mac_X550_vf,
  616. .mac_ops = &ixgbevf_mac_ops,
  617. };
  618. const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
  619. .mac = ixgbe_mac_X550EM_x_vf,
  620. .mac_ops = &ixgbevf_mac_ops,
  621. };