1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001 - 2015 Intel Corporation
8 * e1000_null_mbx_check_for_flag - No-op function, return 0
9 * @hw: pointer to the HW structure
11 STATIC s32 e1000_null_mbx_check_for_flag(struct e1000_hw E1000_UNUSEDARG *hw,
12 u16 E1000_UNUSEDARG mbx_id)
14 DEBUGFUNC("e1000_null_mbx_check_flag");
15 UNREFERENCED_2PARAMETER(hw, mbx_id);
21 * e1000_null_mbx_transact - No-op function, return 0
22 * @hw: pointer to the HW structure
24 STATIC s32 e1000_null_mbx_transact(struct e1000_hw E1000_UNUSEDARG *hw,
25 u32 E1000_UNUSEDARG *msg,
26 u16 E1000_UNUSEDARG size,
27 u16 E1000_UNUSEDARG mbx_id)
29 DEBUGFUNC("e1000_null_mbx_rw_msg");
30 UNREFERENCED_4PARAMETER(hw, msg, size, mbx_id);
36 * e1000_read_mbx - Reads a message from the mailbox
37 * @hw: pointer to the HW structure
38 * @msg: The message buffer
39 * @size: Length of buffer
40 * @mbx_id: id of mailbox to read
42 * returns SUCCESS if it successfully read message from buffer
44 s32 e1000_read_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
46 struct e1000_mbx_info *mbx = &hw->mbx;
47 s32 ret_val = -E1000_ERR_MBX;
49 DEBUGFUNC("e1000_read_mbx");
51 /* limit read to size of mailbox */
56 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
62 * e1000_write_mbx - Write a message to the mailbox
63 * @hw: pointer to the HW structure
64 * @msg: The message buffer
65 * @size: Length of buffer
66 * @mbx_id: id of mailbox to write
68 * returns SUCCESS if it successfully copied message into the buffer
70 s32 e1000_write_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
72 struct e1000_mbx_info *mbx = &hw->mbx;
73 s32 ret_val = E1000_SUCCESS;
75 DEBUGFUNC("e1000_write_mbx");
78 ret_val = -E1000_ERR_MBX;
80 else if (mbx->ops.write)
81 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
87 * e1000_check_for_msg - checks to see if someone sent us mail
88 * @hw: pointer to the HW structure
89 * @mbx_id: id of mailbox to check
91 * returns SUCCESS if the Status bit was found or else ERR_MBX
93 s32 e1000_check_for_msg(struct e1000_hw *hw, u16 mbx_id)
95 struct e1000_mbx_info *mbx = &hw->mbx;
96 s32 ret_val = -E1000_ERR_MBX;
98 DEBUGFUNC("e1000_check_for_msg");
100 if (mbx->ops.check_for_msg)
101 ret_val = mbx->ops.check_for_msg(hw, mbx_id);
107 * e1000_check_for_ack - checks to see if someone sent us ACK
108 * @hw: pointer to the HW structure
109 * @mbx_id: id of mailbox to check
111 * returns SUCCESS if the Status bit was found or else ERR_MBX
113 s32 e1000_check_for_ack(struct e1000_hw *hw, u16 mbx_id)
115 struct e1000_mbx_info *mbx = &hw->mbx;
116 s32 ret_val = -E1000_ERR_MBX;
118 DEBUGFUNC("e1000_check_for_ack");
120 if (mbx->ops.check_for_ack)
121 ret_val = mbx->ops.check_for_ack(hw, mbx_id);
127 * e1000_check_for_rst - checks to see if other side has reset
128 * @hw: pointer to the HW structure
129 * @mbx_id: id of mailbox to check
131 * returns SUCCESS if the Status bit was found or else ERR_MBX
133 s32 e1000_check_for_rst(struct e1000_hw *hw, u16 mbx_id)
135 struct e1000_mbx_info *mbx = &hw->mbx;
136 s32 ret_val = -E1000_ERR_MBX;
138 DEBUGFUNC("e1000_check_for_rst");
140 if (mbx->ops.check_for_rst)
141 ret_val = mbx->ops.check_for_rst(hw, mbx_id);
147 * e1000_poll_for_msg - Wait for message notification
148 * @hw: pointer to the HW structure
149 * @mbx_id: id of mailbox to write
151 * returns SUCCESS if it successfully received a message notification
153 STATIC s32 e1000_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
155 struct e1000_mbx_info *mbx = &hw->mbx;
156 int countdown = mbx->timeout;
158 DEBUGFUNC("e1000_poll_for_msg");
160 if (!countdown || !mbx->ops.check_for_msg)
163 while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
167 usec_delay(mbx->usec_delay);
170 /* if we failed, all future posted messages fail until reset */
174 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
178 * e1000_poll_for_ack - Wait for message acknowledgement
179 * @hw: pointer to the HW structure
180 * @mbx_id: id of mailbox to write
182 * returns SUCCESS if it successfully received a message acknowledgement
184 STATIC s32 e1000_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
186 struct e1000_mbx_info *mbx = &hw->mbx;
187 int countdown = mbx->timeout;
189 DEBUGFUNC("e1000_poll_for_ack");
191 if (!countdown || !mbx->ops.check_for_ack)
194 while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
198 usec_delay(mbx->usec_delay);
201 /* if we failed, all future posted messages fail until reset */
205 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
209 * e1000_read_posted_mbx - Wait for message notification and receive message
210 * @hw: pointer to the HW structure
211 * @msg: The message buffer
212 * @size: Length of buffer
213 * @mbx_id: id of mailbox to write
215 * returns SUCCESS if it successfully received a message notification and
216 * copied it into the receive buffer.
218 s32 e1000_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
220 struct e1000_mbx_info *mbx = &hw->mbx;
221 s32 ret_val = -E1000_ERR_MBX;
223 DEBUGFUNC("e1000_read_posted_mbx");
228 ret_val = e1000_poll_for_msg(hw, mbx_id);
230 /* if ack received read message, otherwise we timed out */
232 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
238 * e1000_write_posted_mbx - Write a message to the mailbox, wait for ack
239 * @hw: pointer to the HW structure
240 * @msg: The message buffer
241 * @size: Length of buffer
242 * @mbx_id: id of mailbox to write
244 * returns SUCCESS if it successfully copied message into the buffer and
245 * received an ack to that message within delay * timeout period
247 s32 e1000_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
249 struct e1000_mbx_info *mbx = &hw->mbx;
250 s32 ret_val = -E1000_ERR_MBX;
252 DEBUGFUNC("e1000_write_posted_mbx");
254 /* exit if either we can't write or there isn't a defined timeout */
255 if (!mbx->ops.write || !mbx->timeout)
259 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
261 /* if msg sent wait until we receive an ack */
263 ret_val = e1000_poll_for_ack(hw, mbx_id);
269 * e1000_init_mbx_ops_generic - Initialize mbx function pointers
270 * @hw: pointer to the HW structure
272 * Sets the function pointers to no-op functions
274 void e1000_init_mbx_ops_generic(struct e1000_hw *hw)
276 struct e1000_mbx_info *mbx = &hw->mbx;
277 mbx->ops.init_params = e1000_null_ops_generic;
278 mbx->ops.read = e1000_null_mbx_transact;
279 mbx->ops.write = e1000_null_mbx_transact;
280 mbx->ops.check_for_msg = e1000_null_mbx_check_for_flag;
281 mbx->ops.check_for_ack = e1000_null_mbx_check_for_flag;
282 mbx->ops.check_for_rst = e1000_null_mbx_check_for_flag;
283 mbx->ops.read_posted = e1000_read_posted_mbx;
284 mbx->ops.write_posted = e1000_write_posted_mbx;
288 * e1000_read_v2p_mailbox - read v2p mailbox
289 * @hw: pointer to the HW structure
291 * This function is used to read the v2p mailbox without losing the read to
294 STATIC u32 e1000_read_v2p_mailbox(struct e1000_hw *hw)
296 u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
298 v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
299 hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
305 * e1000_check_for_bit_vf - Determine if a status bit was set
306 * @hw: pointer to the HW structure
307 * @mask: bitmask for bits to be tested and cleared
309 * This function is used to check for the read to clear bits within
312 STATIC s32 e1000_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
314 u32 v2p_mailbox = e1000_read_v2p_mailbox(hw);
315 s32 ret_val = -E1000_ERR_MBX;
317 if (v2p_mailbox & mask)
318 ret_val = E1000_SUCCESS;
320 hw->dev_spec.vf.v2p_mailbox &= ~mask;
326 * e1000_check_for_msg_vf - checks to see if the PF has sent mail
327 * @hw: pointer to the HW structure
328 * @mbx_id: id of mailbox to check
330 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
332 STATIC s32 e1000_check_for_msg_vf(struct e1000_hw *hw,
333 u16 E1000_UNUSEDARG mbx_id)
335 s32 ret_val = -E1000_ERR_MBX;
337 UNREFERENCED_1PARAMETER(mbx_id);
338 DEBUGFUNC("e1000_check_for_msg_vf");
340 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
341 ret_val = E1000_SUCCESS;
342 hw->mbx.stats.reqs++;
349 * e1000_check_for_ack_vf - checks to see if the PF has ACK'd
350 * @hw: pointer to the HW structure
351 * @mbx_id: id of mailbox to check
353 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
355 STATIC s32 e1000_check_for_ack_vf(struct e1000_hw *hw,
356 u16 E1000_UNUSEDARG mbx_id)
358 s32 ret_val = -E1000_ERR_MBX;
360 UNREFERENCED_1PARAMETER(mbx_id);
361 DEBUGFUNC("e1000_check_for_ack_vf");
363 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
364 ret_val = E1000_SUCCESS;
365 hw->mbx.stats.acks++;
372 * e1000_check_for_rst_vf - checks to see if the PF has reset
373 * @hw: pointer to the HW structure
374 * @mbx_id: id of mailbox to check
376 * returns true if the PF has set the reset done bit or else false
378 STATIC s32 e1000_check_for_rst_vf(struct e1000_hw *hw,
379 u16 E1000_UNUSEDARG mbx_id)
381 s32 ret_val = -E1000_ERR_MBX;
383 UNREFERENCED_1PARAMETER(mbx_id);
384 DEBUGFUNC("e1000_check_for_rst_vf");
386 if (!e1000_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
387 E1000_V2PMAILBOX_RSTI))) {
388 ret_val = E1000_SUCCESS;
389 hw->mbx.stats.rsts++;
396 * e1000_obtain_mbx_lock_vf - obtain mailbox lock
397 * @hw: pointer to the HW structure
399 * return SUCCESS if we obtained the mailbox lock
401 STATIC s32 e1000_obtain_mbx_lock_vf(struct e1000_hw *hw)
403 s32 ret_val = -E1000_ERR_MBX;
406 DEBUGFUNC("e1000_obtain_mbx_lock_vf");
409 /* Take ownership of the buffer */
410 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
412 /* reserve mailbox for vf use */
413 if (e1000_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU) {
414 ret_val = E1000_SUCCESS;
418 } while (count-- > 0);
424 * e1000_write_mbx_vf - Write a message to the mailbox
425 * @hw: pointer to the HW structure
426 * @msg: The message buffer
427 * @size: Length of buffer
428 * @mbx_id: id of mailbox to write
430 * returns SUCCESS if it successfully copied message into the buffer
432 STATIC s32 e1000_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
433 u16 E1000_UNUSEDARG mbx_id)
438 UNREFERENCED_1PARAMETER(mbx_id);
440 DEBUGFUNC("e1000_write_mbx_vf");
442 /* lock the mailbox to prevent pf/vf race condition */
443 ret_val = e1000_obtain_mbx_lock_vf(hw);
447 /* flush msg and acks as we are overwriting the message buffer */
448 e1000_check_for_msg_vf(hw, 0);
449 e1000_check_for_ack_vf(hw, 0);
451 /* copy the caller specified message to the mailbox memory buffer */
452 for (i = 0; i < size; i++)
453 E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(0), i, msg[i]);
456 hw->mbx.stats.msgs_tx++;
458 /* Drop VFU and interrupt the PF to tell it a message has been sent */
459 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
466 * e1000_read_mbx_vf - Reads a message from the inbox intended for vf
467 * @hw: pointer to the HW structure
468 * @msg: The message buffer
469 * @size: Length of buffer
470 * @mbx_id: id of mailbox to read
472 * returns SUCCESS if it successfully read message from buffer
474 STATIC s32 e1000_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
475 u16 E1000_UNUSEDARG mbx_id)
477 s32 ret_val = E1000_SUCCESS;
480 DEBUGFUNC("e1000_read_mbx_vf");
481 UNREFERENCED_1PARAMETER(mbx_id);
483 /* lock the mailbox to prevent pf/vf race condition */
484 ret_val = e1000_obtain_mbx_lock_vf(hw);
488 /* copy the message from the mailbox memory buffer */
489 for (i = 0; i < size; i++)
490 msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(0), i);
492 /* Acknowledge receipt and release mailbox, then we're done */
493 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
496 hw->mbx.stats.msgs_rx++;
503 * e1000_init_mbx_params_vf - set initial values for vf mailbox
504 * @hw: pointer to the HW structure
506 * Initializes the hw->mbx struct to correct values for vf mailbox
508 s32 e1000_init_mbx_params_vf(struct e1000_hw *hw)
510 struct e1000_mbx_info *mbx = &hw->mbx;
512 /* start mailbox as timed out and let the reset_hw call set the timeout
513 * value to begin communications */
515 mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
517 mbx->size = E1000_VFMAILBOX_SIZE;
519 mbx->ops.read = e1000_read_mbx_vf;
520 mbx->ops.write = e1000_write_mbx_vf;
521 mbx->ops.read_posted = e1000_read_posted_mbx;
522 mbx->ops.write_posted = e1000_write_posted_mbx;
523 mbx->ops.check_for_msg = e1000_check_for_msg_vf;
524 mbx->ops.check_for_ack = e1000_check_for_ack_vf;
525 mbx->ops.check_for_rst = e1000_check_for_rst_vf;
527 mbx->stats.msgs_tx = 0;
528 mbx->stats.msgs_rx = 0;
533 return E1000_SUCCESS;
536 STATIC s32 e1000_check_for_bit_pf(struct e1000_hw *hw, u32 mask)
538 u32 mbvficr = E1000_READ_REG(hw, E1000_MBVFICR);
539 s32 ret_val = -E1000_ERR_MBX;
541 if (mbvficr & mask) {
542 ret_val = E1000_SUCCESS;
543 E1000_WRITE_REG(hw, E1000_MBVFICR, mask);
550 * e1000_check_for_msg_pf - checks to see if the VF has sent mail
551 * @hw: pointer to the HW structure
552 * @vf_number: the VF index
554 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
556 STATIC s32 e1000_check_for_msg_pf(struct e1000_hw *hw, u16 vf_number)
558 s32 ret_val = -E1000_ERR_MBX;
560 DEBUGFUNC("e1000_check_for_msg_pf");
562 if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFREQ_VF1 << vf_number)) {
563 ret_val = E1000_SUCCESS;
564 hw->mbx.stats.reqs++;
571 * e1000_check_for_ack_pf - checks to see if the VF has ACKed
572 * @hw: pointer to the HW structure
573 * @vf_number: the VF index
575 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
577 STATIC s32 e1000_check_for_ack_pf(struct e1000_hw *hw, u16 vf_number)
579 s32 ret_val = -E1000_ERR_MBX;
581 DEBUGFUNC("e1000_check_for_ack_pf");
583 if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFACK_VF1 << vf_number)) {
584 ret_val = E1000_SUCCESS;
585 hw->mbx.stats.acks++;
592 * e1000_check_for_rst_pf - checks to see if the VF has reset
593 * @hw: pointer to the HW structure
594 * @vf_number: the VF index
596 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
598 STATIC s32 e1000_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
600 u32 vflre = E1000_READ_REG(hw, E1000_VFLRE);
601 s32 ret_val = -E1000_ERR_MBX;
603 DEBUGFUNC("e1000_check_for_rst_pf");
605 if (vflre & (1 << vf_number)) {
606 ret_val = E1000_SUCCESS;
607 E1000_WRITE_REG(hw, E1000_VFLRE, (1 << vf_number));
608 hw->mbx.stats.rsts++;
615 * e1000_obtain_mbx_lock_pf - obtain mailbox lock
616 * @hw: pointer to the HW structure
617 * @vf_number: the VF index
619 * return SUCCESS if we obtained the mailbox lock
621 STATIC s32 e1000_obtain_mbx_lock_pf(struct e1000_hw *hw, u16 vf_number)
623 s32 ret_val = -E1000_ERR_MBX;
627 DEBUGFUNC("e1000_obtain_mbx_lock_pf");
630 /* Take ownership of the buffer */
631 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number),
632 E1000_P2VMAILBOX_PFU);
634 /* reserve mailbox for pf use */
635 p2v_mailbox = E1000_READ_REG(hw, E1000_P2VMAILBOX(vf_number));
636 if (p2v_mailbox & E1000_P2VMAILBOX_PFU) {
637 ret_val = E1000_SUCCESS;
641 } while (count-- > 0);
648 * e1000_write_mbx_pf - Places a message in the mailbox
649 * @hw: pointer to the HW structure
650 * @msg: The message buffer
651 * @size: Length of buffer
652 * @vf_number: the VF index
654 * returns SUCCESS if it successfully copied message into the buffer
656 STATIC s32 e1000_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
662 DEBUGFUNC("e1000_write_mbx_pf");
664 /* lock the mailbox to prevent pf/vf race condition */
665 ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
669 /* flush msg and acks as we are overwriting the message buffer */
670 e1000_check_for_msg_pf(hw, vf_number);
671 e1000_check_for_ack_pf(hw, vf_number);
673 /* copy the caller specified message to the mailbox memory buffer */
674 for (i = 0; i < size; i++)
675 E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i, msg[i]);
677 /* Interrupt VF to tell it a message has been sent and release buffer*/
678 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_STS);
681 hw->mbx.stats.msgs_tx++;
689 * e1000_read_mbx_pf - Read a message from the mailbox
690 * @hw: pointer to the HW structure
691 * @msg: The message buffer
692 * @size: Length of buffer
693 * @vf_number: the VF index
695 * This function copies a message from the mailbox buffer to the caller's
696 * memory buffer. The presumption is that the caller knows that there was
697 * a message due to a VF request so no polling for message is needed.
699 STATIC s32 e1000_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
705 DEBUGFUNC("e1000_read_mbx_pf");
707 /* lock the mailbox to prevent pf/vf race condition */
708 ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
712 /* copy the message to the mailbox memory buffer */
713 for (i = 0; i < size; i++)
714 msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i);
716 /* Acknowledge the message and release buffer */
717 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_ACK);
720 hw->mbx.stats.msgs_rx++;
727 * e1000_init_mbx_params_pf - set initial values for pf mailbox
728 * @hw: pointer to the HW structure
730 * Initializes the hw->mbx struct to correct values for pf mailbox
732 s32 e1000_init_mbx_params_pf(struct e1000_hw *hw)
734 struct e1000_mbx_info *mbx = &hw->mbx;
736 switch (hw->mac.type) {
743 mbx->size = E1000_VFMAILBOX_SIZE;
745 mbx->ops.read = e1000_read_mbx_pf;
746 mbx->ops.write = e1000_write_mbx_pf;
747 mbx->ops.read_posted = e1000_read_posted_mbx;
748 mbx->ops.write_posted = e1000_write_posted_mbx;
749 mbx->ops.check_for_msg = e1000_check_for_msg_pf;
750 mbx->ops.check_for_ack = e1000_check_for_ack_pf;
751 mbx->ops.check_for_rst = e1000_check_for_rst_pf;
753 mbx->stats.msgs_tx = 0;
754 mbx->stats.msgs_rx = 0;
759 return E1000_SUCCESS;