vf.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2012 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, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "vf.h"
  21. #include "ixgbevf.h"
  22. /**
  23. * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  24. * @hw: pointer to hardware structure
  25. *
  26. * Starts the hardware by filling the bus info structure and media type, clears
  27. * all on chip counters, initializes receive address registers, multicast
  28. * table, VLAN filter table, calls routine to set up link and flow control
  29. * settings, and leaves transmit and receive units disabled and uninitialized
  30. **/
  31. static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
  32. {
  33. /* Clear adapter stopped flag */
  34. hw->adapter_stopped = false;
  35. return 0;
  36. }
  37. /**
  38. * ixgbevf_init_hw_vf - virtual function hardware initialization
  39. * @hw: pointer to hardware structure
  40. *
  41. * Initialize the hardware by resetting the hardware and then starting
  42. * the hardware
  43. **/
  44. static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
  45. {
  46. s32 status = hw->mac.ops.start_hw(hw);
  47. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  48. return status;
  49. }
  50. /**
  51. * ixgbevf_reset_hw_vf - Performs hardware reset
  52. * @hw: pointer to hardware structure
  53. *
  54. * Resets the hardware by reseting the transmit and receive units, masks and
  55. * clears all interrupts.
  56. **/
  57. static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
  58. {
  59. struct ixgbe_mbx_info *mbx = &hw->mbx;
  60. u32 timeout = IXGBE_VF_INIT_TIMEOUT;
  61. s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
  62. u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
  63. u8 *addr = (u8 *)(&msgbuf[1]);
  64. /* Call adapter stop to disable tx/rx and clear interrupts */
  65. hw->mac.ops.stop_adapter(hw);
  66. IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
  67. IXGBE_WRITE_FLUSH(hw);
  68. /* we cannot reset while the RSTI / RSTD bits are asserted */
  69. while (!mbx->ops.check_for_rst(hw) && timeout) {
  70. timeout--;
  71. udelay(5);
  72. }
  73. if (!timeout)
  74. return IXGBE_ERR_RESET_FAILED;
  75. /* mailbox timeout can now become active */
  76. mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
  77. msgbuf[0] = IXGBE_VF_RESET;
  78. mbx->ops.write_posted(hw, msgbuf, 1);
  79. msleep(10);
  80. /* set our "perm_addr" based on info provided by PF */
  81. /* also set up the mc_filter_type which is piggy backed
  82. * on the mac address in word 3 */
  83. ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN);
  84. if (ret_val)
  85. return ret_val;
  86. if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK))
  87. return IXGBE_ERR_INVALID_MAC_ADDR;
  88. memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
  89. hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
  90. return 0;
  91. }
  92. /**
  93. * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  94. * @hw: pointer to hardware structure
  95. *
  96. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  97. * disables transmit and receive units. The adapter_stopped flag is used by
  98. * the shared code and drivers to determine if the adapter is in a stopped
  99. * state and should not touch the hardware.
  100. **/
  101. static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
  102. {
  103. u32 number_of_queues;
  104. u32 reg_val;
  105. u16 i;
  106. /*
  107. * Set the adapter_stopped flag so other driver functions stop touching
  108. * the hardware
  109. */
  110. hw->adapter_stopped = true;
  111. /* Disable the receive unit by stopped each queue */
  112. number_of_queues = hw->mac.max_rx_queues;
  113. for (i = 0; i < number_of_queues; i++) {
  114. reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
  115. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  116. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  117. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
  118. }
  119. }
  120. IXGBE_WRITE_FLUSH(hw);
  121. /* Clear interrupt mask to stop from interrupts being generated */
  122. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
  123. /* Clear any pending interrupts */
  124. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  125. /* Disable the transmit unit. Each queue must be disabled. */
  126. number_of_queues = hw->mac.max_tx_queues;
  127. for (i = 0; i < number_of_queues; i++) {
  128. reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
  129. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  130. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  131. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
  132. }
  133. }
  134. return 0;
  135. }
  136. /**
  137. * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
  138. * @hw: pointer to hardware structure
  139. * @mc_addr: the multicast address
  140. *
  141. * Extracts the 12 bits, from a multicast address, to determine which
  142. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  143. * incoming rx multicast addresses, to determine the bit-vector to check in
  144. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  145. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  146. * to mc_filter_type.
  147. **/
  148. static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  149. {
  150. u32 vector = 0;
  151. switch (hw->mac.mc_filter_type) {
  152. case 0: /* use bits [47:36] of the address */
  153. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  154. break;
  155. case 1: /* use bits [46:35] of the address */
  156. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  157. break;
  158. case 2: /* use bits [45:34] of the address */
  159. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  160. break;
  161. case 3: /* use bits [43:32] of the address */
  162. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  163. break;
  164. default: /* Invalid mc_filter_type */
  165. break;
  166. }
  167. /* vector can only be 12-bits or boundary will be exceeded */
  168. vector &= 0xFFF;
  169. return vector;
  170. }
  171. /**
  172. * ixgbevf_get_mac_addr_vf - Read device MAC address
  173. * @hw: pointer to the HW structure
  174. * @mac_addr: pointer to storage for retrieved MAC address
  175. **/
  176. static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
  177. {
  178. memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN);
  179. return 0;
  180. }
  181. static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  182. {
  183. struct ixgbe_mbx_info *mbx = &hw->mbx;
  184. u32 msgbuf[3];
  185. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  186. s32 ret_val;
  187. memset(msgbuf, 0, sizeof(msgbuf));
  188. /*
  189. * If index is one then this is the start of a new list and needs
  190. * indication to the PF so it can do it's own list management.
  191. * If it is zero then that tells the PF to just clear all of
  192. * this VF's macvlans and there is no new list.
  193. */
  194. msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
  195. msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
  196. if (addr)
  197. memcpy(msg_addr, addr, 6);
  198. ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
  199. if (!ret_val)
  200. ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
  201. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  202. if (!ret_val)
  203. if (msgbuf[0] ==
  204. (IXGBE_VF_SET_MACVLAN | IXGBE_VT_MSGTYPE_NACK))
  205. ret_val = -ENOMEM;
  206. return ret_val;
  207. }
  208. /**
  209. * ixgbevf_set_rar_vf - set device MAC address
  210. * @hw: pointer to hardware structure
  211. * @index: Receive address register to write
  212. * @addr: Address to put into receive address register
  213. * @vmdq: Unused in this implementation
  214. **/
  215. static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  216. u32 vmdq)
  217. {
  218. struct ixgbe_mbx_info *mbx = &hw->mbx;
  219. u32 msgbuf[3];
  220. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  221. s32 ret_val;
  222. memset(msgbuf, 0, sizeof(msgbuf));
  223. msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
  224. memcpy(msg_addr, addr, 6);
  225. ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
  226. if (!ret_val)
  227. ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
  228. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  229. /* if nacked the address was rejected, use "perm_addr" */
  230. if (!ret_val &&
  231. (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK)))
  232. ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
  233. return ret_val;
  234. }
  235. static void ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw,
  236. u32 *msg, u16 size)
  237. {
  238. struct ixgbe_mbx_info *mbx = &hw->mbx;
  239. u32 retmsg[IXGBE_VFMAILBOX_SIZE];
  240. s32 retval = mbx->ops.write_posted(hw, msg, size);
  241. if (!retval)
  242. mbx->ops.read_posted(hw, retmsg, size);
  243. }
  244. /**
  245. * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
  246. * @hw: pointer to the HW structure
  247. * @netdev: pointer to net device structure
  248. *
  249. * Updates the Multicast Table Array.
  250. **/
  251. static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  252. struct net_device *netdev)
  253. {
  254. struct netdev_hw_addr *ha;
  255. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  256. u16 *vector_list = (u16 *)&msgbuf[1];
  257. u32 cnt, i;
  258. /* Each entry in the list uses 1 16 bit word. We have 30
  259. * 16 bit words available in our HW msg buffer (minus 1 for the
  260. * msg type). That's 30 hash values if we pack 'em right. If
  261. * there are more than 30 MC addresses to add then punt the
  262. * extras for now and then add code to handle more than 30 later.
  263. * It would be unusual for a server to request that many multi-cast
  264. * addresses except for in large enterprise network environments.
  265. */
  266. cnt = netdev_mc_count(netdev);
  267. if (cnt > 30)
  268. cnt = 30;
  269. msgbuf[0] = IXGBE_VF_SET_MULTICAST;
  270. msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
  271. i = 0;
  272. netdev_for_each_mc_addr(ha, netdev) {
  273. if (i == cnt)
  274. break;
  275. vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
  276. }
  277. ixgbevf_write_msg_read_ack(hw, msgbuf, IXGBE_VFMAILBOX_SIZE);
  278. return 0;
  279. }
  280. /**
  281. * ixgbevf_set_vfta_vf - Set/Unset vlan filter table address
  282. * @hw: pointer to the HW structure
  283. * @vlan: 12 bit VLAN ID
  284. * @vind: unused by VF drivers
  285. * @vlan_on: if true then set bit, else clear bit
  286. **/
  287. static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  288. bool vlan_on)
  289. {
  290. u32 msgbuf[2];
  291. msgbuf[0] = IXGBE_VF_SET_VLAN;
  292. msgbuf[1] = vlan;
  293. /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
  294. msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
  295. ixgbevf_write_msg_read_ack(hw, msgbuf, 2);
  296. return 0;
  297. }
  298. /**
  299. * ixgbevf_setup_mac_link_vf - Setup MAC link settings
  300. * @hw: pointer to hardware structure
  301. * @speed: Unused in this implementation
  302. * @autoneg: Unused in this implementation
  303. * @autoneg_wait_to_complete: Unused in this implementation
  304. *
  305. * Do nothing and return success. VF drivers are not allowed to change
  306. * global settings. Maintained for driver compatibility.
  307. **/
  308. static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
  309. ixgbe_link_speed speed, bool autoneg,
  310. bool autoneg_wait_to_complete)
  311. {
  312. return 0;
  313. }
  314. /**
  315. * ixgbevf_check_mac_link_vf - Get link/speed status
  316. * @hw: pointer to hardware structure
  317. * @speed: pointer to link speed
  318. * @link_up: true is link is up, false otherwise
  319. * @autoneg_wait_to_complete: true when waiting for completion is needed
  320. *
  321. * Reads the links register to determine if link is up and the current speed
  322. **/
  323. static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
  324. ixgbe_link_speed *speed,
  325. bool *link_up,
  326. bool autoneg_wait_to_complete)
  327. {
  328. u32 links_reg;
  329. if (!(hw->mbx.ops.check_for_rst(hw))) {
  330. *link_up = false;
  331. *speed = 0;
  332. return -1;
  333. }
  334. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  335. if (links_reg & IXGBE_LINKS_UP)
  336. *link_up = true;
  337. else
  338. *link_up = false;
  339. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  340. IXGBE_LINKS_SPEED_10G_82599)
  341. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  342. else
  343. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  344. return 0;
  345. }
  346. static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
  347. .init_hw = ixgbevf_init_hw_vf,
  348. .reset_hw = ixgbevf_reset_hw_vf,
  349. .start_hw = ixgbevf_start_hw_vf,
  350. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  351. .stop_adapter = ixgbevf_stop_hw_vf,
  352. .setup_link = ixgbevf_setup_mac_link_vf,
  353. .check_link = ixgbevf_check_mac_link_vf,
  354. .set_rar = ixgbevf_set_rar_vf,
  355. .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
  356. .set_uc_addr = ixgbevf_set_uc_addr_vf,
  357. .set_vfta = ixgbevf_set_vfta_vf,
  358. };
  359. const struct ixgbevf_info ixgbevf_82599_vf_info = {
  360. .mac = ixgbe_mac_82599_vf,
  361. .mac_ops = &ixgbevf_mac_ops,
  362. };
  363. const struct ixgbevf_info ixgbevf_X540_vf_info = {
  364. .mac = ixgbe_mac_X540_vf,
  365. .mac_ops = &ixgbevf_mac_ops,
  366. };