選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

igbvf_mbx.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*******************************************************************************
  2. Intel(R) 82576 Virtual Function Linux driver
  3. Copyright(c) 1999 - 2008 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. FILE_LICENCE ( GPL2_ONLY );
  22. #include "igbvf_mbx.h"
  23. /**
  24. * igbvf_poll_for_msg - Wait for message notification
  25. * @hw: pointer to the HW structure
  26. * @mbx_id: id of mailbox to write
  27. *
  28. * returns SUCCESS if it successfully received a message notification
  29. **/
  30. static s32 igbvf_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
  31. {
  32. struct e1000_mbx_info *mbx = &hw->mbx;
  33. int countdown = mbx->timeout;
  34. DEBUGFUNC("igbvf_poll_for_msg");
  35. if (!countdown || !mbx->ops.check_for_msg)
  36. goto out;
  37. while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
  38. countdown--;
  39. if (!countdown)
  40. break;
  41. usec_delay(mbx->usec_delay);
  42. }
  43. /* if we failed, all future posted messages fail until reset */
  44. if (!countdown)
  45. mbx->timeout = 0;
  46. out:
  47. return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
  48. }
  49. /**
  50. * igbvf_poll_for_ack - Wait for message acknowledgement
  51. * @hw: pointer to the HW structure
  52. * @mbx_id: id of mailbox to write
  53. *
  54. * returns SUCCESS if it successfully received a message acknowledgement
  55. **/
  56. static s32 igbvf_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
  57. {
  58. struct e1000_mbx_info *mbx = &hw->mbx;
  59. int countdown = mbx->timeout;
  60. DEBUGFUNC("igbvf_poll_for_ack");
  61. if (!countdown || !mbx->ops.check_for_ack)
  62. goto out;
  63. while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
  64. countdown--;
  65. if (!countdown)
  66. break;
  67. usec_delay(mbx->usec_delay);
  68. }
  69. /* if we failed, all future posted messages fail until reset */
  70. if (!countdown)
  71. mbx->timeout = 0;
  72. out:
  73. return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
  74. }
  75. /**
  76. * igbvf_read_posted_mbx - Wait for message notification and receive message
  77. * @hw: pointer to the HW structure
  78. * @msg: The message buffer
  79. * @size: Length of buffer
  80. * @mbx_id: id of mailbox to write
  81. *
  82. * returns SUCCESS if it successfully received a message notification and
  83. * copied it into the receive buffer.
  84. **/
  85. static s32 igbvf_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size,
  86. u16 mbx_id)
  87. {
  88. struct e1000_mbx_info *mbx = &hw->mbx;
  89. s32 ret_val = -E1000_ERR_MBX;
  90. DEBUGFUNC("igbvf_read_posted_mbx");
  91. if (!mbx->ops.read)
  92. goto out;
  93. ret_val = igbvf_poll_for_msg(hw, mbx_id);
  94. /* if ack received read message, otherwise we timed out */
  95. if (!ret_val)
  96. ret_val = mbx->ops.read(hw, msg, size, mbx_id);
  97. out:
  98. return ret_val;
  99. }
  100. /**
  101. * igbvf_write_posted_mbx - Write a message to the mailbox, wait for ack
  102. * @hw: pointer to the HW structure
  103. * @msg: The message buffer
  104. * @size: Length of buffer
  105. * @mbx_id: id of mailbox to write
  106. *
  107. * returns SUCCESS if it successfully copied message into the buffer and
  108. * received an ack to that message within delay * timeout period
  109. **/
  110. static s32 igbvf_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size,
  111. u16 mbx_id)
  112. {
  113. struct e1000_mbx_info *mbx = &hw->mbx;
  114. s32 ret_val = -E1000_ERR_MBX;
  115. DEBUGFUNC("igbvf_write_posted_mbx");
  116. /* exit if either we can't write or there isn't a defined timeout */
  117. if (!mbx->ops.write || !mbx->timeout)
  118. goto out;
  119. /* send msg */
  120. ret_val = mbx->ops.write(hw, msg, size, mbx_id);
  121. /* if msg sent wait until we receive an ack */
  122. if (!ret_val)
  123. ret_val = igbvf_poll_for_ack(hw, mbx_id);
  124. out:
  125. return ret_val;
  126. }
  127. /**
  128. * igbvf_init_mbx_ops_generic - Initialize NVM function pointers
  129. * @hw: pointer to the HW structure
  130. *
  131. * Setups up the function pointers to no-op functions
  132. **/
  133. void igbvf_init_mbx_ops_generic(struct e1000_hw *hw)
  134. {
  135. struct e1000_mbx_info *mbx = &hw->mbx;
  136. mbx->ops.read_posted = igbvf_read_posted_mbx;
  137. mbx->ops.write_posted = igbvf_write_posted_mbx;
  138. }
  139. /**
  140. * igbvf_read_v2p_mailbox - read v2p mailbox
  141. * @hw: pointer to the HW structure
  142. *
  143. * This function is used to read the v2p mailbox without losing the read to
  144. * clear status bits.
  145. **/
  146. static u32 igbvf_read_v2p_mailbox(struct e1000_hw *hw)
  147. {
  148. u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
  149. v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
  150. hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
  151. return v2p_mailbox;
  152. }
  153. /**
  154. * igbvf_check_for_bit_vf - Determine if a status bit was set
  155. * @hw: pointer to the HW structure
  156. * @mask: bitmask for bits to be tested and cleared
  157. *
  158. * This function is used to check for the read to clear bits within
  159. * the V2P mailbox.
  160. **/
  161. static s32 igbvf_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
  162. {
  163. u32 v2p_mailbox = igbvf_read_v2p_mailbox(hw);
  164. s32 ret_val = -E1000_ERR_MBX;
  165. if (v2p_mailbox & mask)
  166. ret_val = E1000_SUCCESS;
  167. hw->dev_spec.vf.v2p_mailbox &= ~mask;
  168. return ret_val;
  169. }
  170. /**
  171. * igbvf_check_for_msg_vf - checks to see if the PF has sent mail
  172. * @hw: pointer to the HW structure
  173. * @mbx_id: id of mailbox to check
  174. *
  175. * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
  176. **/
  177. static s32 igbvf_check_for_msg_vf(struct e1000_hw *hw, u16 mbx_id __unused)
  178. {
  179. s32 ret_val = -E1000_ERR_MBX;
  180. DEBUGFUNC("igbvf_check_for_msg_vf");
  181. if (!igbvf_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
  182. ret_val = E1000_SUCCESS;
  183. hw->mbx.stats.reqs++;
  184. }
  185. return ret_val;
  186. }
  187. /**
  188. * igbvf_check_for_ack_vf - checks to see if the PF has ACK'd
  189. * @hw: pointer to the HW structure
  190. * @mbx_id: id of mailbox to check
  191. *
  192. * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
  193. **/
  194. static s32 igbvf_check_for_ack_vf(struct e1000_hw *hw, u16 mbx_id __unused)
  195. {
  196. s32 ret_val = -E1000_ERR_MBX;
  197. DEBUGFUNC("igbvf_check_for_ack_vf");
  198. if (!igbvf_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
  199. ret_val = E1000_SUCCESS;
  200. hw->mbx.stats.acks++;
  201. }
  202. return ret_val;
  203. }
  204. /**
  205. * igbvf_check_for_rst_vf - checks to see if the PF has reset
  206. * @hw: pointer to the HW structure
  207. * @mbx_id: id of mailbox to check
  208. *
  209. * returns true if the PF has set the reset done bit or else false
  210. **/
  211. static s32 igbvf_check_for_rst_vf(struct e1000_hw *hw, u16 mbx_id __unused)
  212. {
  213. s32 ret_val = -E1000_ERR_MBX;
  214. DEBUGFUNC("igbvf_check_for_rst_vf");
  215. if (!igbvf_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
  216. E1000_V2PMAILBOX_RSTI))) {
  217. ret_val = E1000_SUCCESS;
  218. hw->mbx.stats.rsts++;
  219. }
  220. return ret_val;
  221. }
  222. /**
  223. * igbvf_obtain_mbx_lock_vf - obtain mailbox lock
  224. * @hw: pointer to the HW structure
  225. *
  226. * return SUCCESS if we obtained the mailbox lock
  227. **/
  228. static s32 igbvf_obtain_mbx_lock_vf(struct e1000_hw *hw)
  229. {
  230. s32 ret_val = -E1000_ERR_MBX;
  231. DEBUGFUNC("igbvf_obtain_mbx_lock_vf");
  232. /* Take ownership of the buffer */
  233. E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
  234. /* reserve mailbox for vf use */
  235. if (igbvf_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU)
  236. ret_val = E1000_SUCCESS;
  237. return ret_val;
  238. }
  239. /**
  240. * igbvf_write_mbx_vf - Write a message to the mailbox
  241. * @hw: pointer to the HW structure
  242. * @msg: The message buffer
  243. * @size: Length of buffer
  244. * @mbx_id: id of mailbox to write
  245. *
  246. * returns SUCCESS if it successfully copied message into the buffer
  247. **/
  248. static s32 igbvf_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
  249. u16 mbx_id __unused)
  250. {
  251. s32 ret_val;
  252. u16 i;
  253. DEBUGFUNC("igbvf_write_mbx_vf");
  254. /* lock the mailbox to prevent pf/vf race condition */
  255. ret_val = igbvf_obtain_mbx_lock_vf(hw);
  256. if (ret_val)
  257. goto out_no_write;
  258. /* flush msg and acks as we are overwriting the message buffer */
  259. igbvf_check_for_msg_vf(hw, 0);
  260. igbvf_check_for_ack_vf(hw, 0);
  261. /* copy the caller specified message to the mailbox memory buffer */
  262. for (i = 0; i < size; i++)
  263. E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(0), i, msg[i]);
  264. /* update stats */
  265. hw->mbx.stats.msgs_tx++;
  266. /* Drop VFU and interrupt the PF to tell it a message has been sent */
  267. E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
  268. out_no_write:
  269. return ret_val;
  270. }
  271. /**
  272. * igbvf_read_mbx_vf - Reads a message from the inbox intended for vf
  273. * @hw: pointer to the HW structure
  274. * @msg: The message buffer
  275. * @size: Length of buffer
  276. * @mbx_id: id of mailbox to read
  277. *
  278. * returns SUCCESS if it successfuly read message from buffer
  279. **/
  280. static s32 igbvf_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
  281. u16 mbx_id __unused)
  282. {
  283. s32 ret_val = E1000_SUCCESS;
  284. u16 i;
  285. DEBUGFUNC("igbvf_read_mbx_vf");
  286. /* lock the mailbox to prevent pf/vf race condition */
  287. ret_val = igbvf_obtain_mbx_lock_vf(hw);
  288. if (ret_val)
  289. goto out_no_read;
  290. /* copy the message from the mailbox memory buffer */
  291. for (i = 0; i < size; i++)
  292. msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(0), i);
  293. /* Acknowledge receipt and release mailbox, then we're done */
  294. E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
  295. /* update stats */
  296. hw->mbx.stats.msgs_rx++;
  297. out_no_read:
  298. return ret_val;
  299. }
  300. /**
  301. * igbvf_init_mbx_params_vf - set initial values for vf mailbox
  302. * @hw: pointer to the HW structure
  303. *
  304. * Initializes the hw->mbx struct to correct values for vf mailbox
  305. */
  306. s32 igbvf_init_mbx_params_vf(struct e1000_hw *hw)
  307. {
  308. struct e1000_mbx_info *mbx = &hw->mbx;
  309. /* start mailbox as timed out and let the reset_hw call set the timeout
  310. * value to begin communications */
  311. mbx->timeout = 0;
  312. mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
  313. mbx->size = E1000_VFMAILBOX_SIZE;
  314. mbx->ops.read = igbvf_read_mbx_vf;
  315. mbx->ops.write = igbvf_write_mbx_vf;
  316. mbx->ops.read_posted = igbvf_read_posted_mbx;
  317. mbx->ops.write_posted = igbvf_write_posted_mbx;
  318. mbx->ops.check_for_msg = igbvf_check_for_msg_vf;
  319. mbx->ops.check_for_ack = igbvf_check_for_ack_vf;
  320. mbx->ops.check_for_rst = igbvf_check_for_rst_vf;
  321. mbx->stats.msgs_tx = 0;
  322. mbx->stats.msgs_rx = 0;
  323. mbx->stats.reqs = 0;
  324. mbx->stats.acks = 0;
  325. mbx->stats.rsts = 0;
  326. return E1000_SUCCESS;
  327. }