1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
8 * e1000_null_mbx_check_for_flag - No-op function, return 0
9 * @hw: pointer to the HW structure
10 * @mbx_id: id of mailbox to read
12 STATIC s32 e1000_null_mbx_check_for_flag(struct e1000_hw E1000_UNUSEDARG *hw,
13 u16 E1000_UNUSEDARG mbx_id)
15 DEBUGFUNC("e1000_null_mbx_check_flag");
16 UNREFERENCED_2PARAMETER(hw, mbx_id);
22 * e1000_null_mbx_transact - No-op function, return 0
23 * @hw: pointer to the HW structure
24 * @msg: The message buffer
25 * @size: Length of buffer
26 * @mbx_id: id of mailbox to read
28 STATIC s32 e1000_null_mbx_transact(struct e1000_hw E1000_UNUSEDARG *hw,
29 u32 E1000_UNUSEDARG *msg,
30 u16 E1000_UNUSEDARG size,
31 u16 E1000_UNUSEDARG mbx_id)
33 DEBUGFUNC("e1000_null_mbx_rw_msg");
34 UNREFERENCED_4PARAMETER(hw, msg, size, mbx_id);
40 * e1000_read_mbx - Reads a message from the mailbox
41 * @hw: pointer to the HW structure
42 * @msg: The message buffer
43 * @size: Length of buffer
44 * @mbx_id: id of mailbox to read
46 * returns SUCCESS if it successfully read message from buffer
48 s32 e1000_read_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
50 struct e1000_mbx_info *mbx = &hw->mbx;
51 s32 ret_val = -E1000_ERR_MBX;
53 DEBUGFUNC("e1000_read_mbx");
55 /* limit read to size of mailbox */
60 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
66 * e1000_write_mbx - Write a message to the mailbox
67 * @hw: pointer to the HW structure
68 * @msg: The message buffer
69 * @size: Length of buffer
70 * @mbx_id: id of mailbox to write
72 * returns SUCCESS if it successfully copied message into the buffer
74 s32 e1000_write_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
76 struct e1000_mbx_info *mbx = &hw->mbx;
77 s32 ret_val = E1000_SUCCESS;
79 DEBUGFUNC("e1000_write_mbx");
82 ret_val = -E1000_ERR_MBX;
84 else if (mbx->ops.write)
85 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
91 * e1000_check_for_msg - checks to see if someone sent us mail
92 * @hw: pointer to the HW structure
93 * @mbx_id: id of mailbox to check
95 * returns SUCCESS if the Status bit was found or else ERR_MBX
97 s32 e1000_check_for_msg(struct e1000_hw *hw, u16 mbx_id)
99 struct e1000_mbx_info *mbx = &hw->mbx;
100 s32 ret_val = -E1000_ERR_MBX;
102 DEBUGFUNC("e1000_check_for_msg");
104 if (mbx->ops.check_for_msg)
105 ret_val = mbx->ops.check_for_msg(hw, mbx_id);
111 * e1000_check_for_ack - checks to see if someone sent us ACK
112 * @hw: pointer to the HW structure
113 * @mbx_id: id of mailbox to check
115 * returns SUCCESS if the Status bit was found or else ERR_MBX
117 s32 e1000_check_for_ack(struct e1000_hw *hw, u16 mbx_id)
119 struct e1000_mbx_info *mbx = &hw->mbx;
120 s32 ret_val = -E1000_ERR_MBX;
122 DEBUGFUNC("e1000_check_for_ack");
124 if (mbx->ops.check_for_ack)
125 ret_val = mbx->ops.check_for_ack(hw, mbx_id);
131 * e1000_check_for_rst - checks to see if other side has reset
132 * @hw: pointer to the HW structure
133 * @mbx_id: id of mailbox to check
135 * returns SUCCESS if the Status bit was found or else ERR_MBX
137 s32 e1000_check_for_rst(struct e1000_hw *hw, u16 mbx_id)
139 struct e1000_mbx_info *mbx = &hw->mbx;
140 s32 ret_val = -E1000_ERR_MBX;
142 DEBUGFUNC("e1000_check_for_rst");
144 if (mbx->ops.check_for_rst)
145 ret_val = mbx->ops.check_for_rst(hw, mbx_id);
151 * e1000_poll_for_msg - Wait for message notification
152 * @hw: pointer to the HW structure
153 * @mbx_id: id of mailbox to write
155 * returns SUCCESS if it successfully received a message notification
157 STATIC s32 e1000_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
159 struct e1000_mbx_info *mbx = &hw->mbx;
160 int countdown = mbx->timeout;
162 DEBUGFUNC("e1000_poll_for_msg");
164 if (!countdown || !mbx->ops.check_for_msg)
167 while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
171 usec_delay(mbx->usec_delay);
174 /* if we failed, all future posted messages fail until reset */
178 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
182 * e1000_poll_for_ack - Wait for message acknowledgement
183 * @hw: pointer to the HW structure
184 * @mbx_id: id of mailbox to write
186 * returns SUCCESS if it successfully received a message acknowledgement
188 STATIC s32 e1000_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
190 struct e1000_mbx_info *mbx = &hw->mbx;
191 int countdown = mbx->timeout;
193 DEBUGFUNC("e1000_poll_for_ack");
195 if (!countdown || !mbx->ops.check_for_ack)
198 while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
202 usec_delay(mbx->usec_delay);
205 /* if we failed, all future posted messages fail until reset */
209 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
213 * e1000_read_posted_mbx - Wait for message notification and receive message
214 * @hw: pointer to the HW structure
215 * @msg: The message buffer
216 * @size: Length of buffer
217 * @mbx_id: id of mailbox to write
219 * returns SUCCESS if it successfully received a message notification and
220 * copied it into the receive buffer.
222 s32 e1000_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
224 struct e1000_mbx_info *mbx = &hw->mbx;
225 s32 ret_val = -E1000_ERR_MBX;
227 DEBUGFUNC("e1000_read_posted_mbx");
232 ret_val = e1000_poll_for_msg(hw, mbx_id);
234 /* if ack received read message, otherwise we timed out */
236 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
242 * e1000_write_posted_mbx - Write a message to the mailbox, wait for ack
243 * @hw: pointer to the HW structure
244 * @msg: The message buffer
245 * @size: Length of buffer
246 * @mbx_id: id of mailbox to write
248 * returns SUCCESS if it successfully copied message into the buffer and
249 * received an ack to that message within delay * timeout period
251 s32 e1000_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
253 struct e1000_mbx_info *mbx = &hw->mbx;
254 s32 ret_val = -E1000_ERR_MBX;
256 DEBUGFUNC("e1000_write_posted_mbx");
258 /* exit if either we can't write or there isn't a defined timeout */
259 if (!mbx->ops.write || !mbx->timeout)
263 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
265 /* if msg sent wait until we receive an ack */
267 ret_val = e1000_poll_for_ack(hw, mbx_id);
273 * e1000_init_mbx_ops_generic - Initialize mbx function pointers
274 * @hw: pointer to the HW structure
276 * Sets the function pointers to no-op functions
278 void e1000_init_mbx_ops_generic(struct e1000_hw *hw)
280 struct e1000_mbx_info *mbx = &hw->mbx;
281 mbx->ops.init_params = e1000_null_ops_generic;
282 mbx->ops.read = e1000_null_mbx_transact;
283 mbx->ops.write = e1000_null_mbx_transact;
284 mbx->ops.check_for_msg = e1000_null_mbx_check_for_flag;
285 mbx->ops.check_for_ack = e1000_null_mbx_check_for_flag;
286 mbx->ops.check_for_rst = e1000_null_mbx_check_for_flag;
287 mbx->ops.read_posted = e1000_read_posted_mbx;
288 mbx->ops.write_posted = e1000_write_posted_mbx;
292 * e1000_read_v2p_mailbox - read v2p mailbox
293 * @hw: pointer to the HW structure
295 * This function is used to read the v2p mailbox without losing the read to
298 STATIC u32 e1000_read_v2p_mailbox(struct e1000_hw *hw)
300 u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
302 v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
303 hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
309 * e1000_check_for_bit_vf - Determine if a status bit was set
310 * @hw: pointer to the HW structure
311 * @mask: bitmask for bits to be tested and cleared
313 * This function is used to check for the read to clear bits within
316 STATIC s32 e1000_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
318 u32 v2p_mailbox = e1000_read_v2p_mailbox(hw);
319 s32 ret_val = -E1000_ERR_MBX;
321 if (v2p_mailbox & mask)
322 ret_val = E1000_SUCCESS;
324 hw->dev_spec.vf.v2p_mailbox &= ~mask;
330 * e1000_check_for_msg_vf - checks to see if the PF has sent mail
331 * @hw: pointer to the HW structure
332 * @mbx_id: id of mailbox to check
334 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
336 STATIC s32 e1000_check_for_msg_vf(struct e1000_hw *hw,
337 u16 E1000_UNUSEDARG mbx_id)
339 s32 ret_val = -E1000_ERR_MBX;
341 UNREFERENCED_1PARAMETER(mbx_id);
342 DEBUGFUNC("e1000_check_for_msg_vf");
344 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
345 ret_val = E1000_SUCCESS;
346 hw->mbx.stats.reqs++;
353 * e1000_check_for_ack_vf - checks to see if the PF has ACK'd
354 * @hw: pointer to the HW structure
355 * @mbx_id: id of mailbox to check
357 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
359 STATIC s32 e1000_check_for_ack_vf(struct e1000_hw *hw,
360 u16 E1000_UNUSEDARG mbx_id)
362 s32 ret_val = -E1000_ERR_MBX;
364 UNREFERENCED_1PARAMETER(mbx_id);
365 DEBUGFUNC("e1000_check_for_ack_vf");
367 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
368 ret_val = E1000_SUCCESS;
369 hw->mbx.stats.acks++;
376 * e1000_check_for_rst_vf - checks to see if the PF has reset
377 * @hw: pointer to the HW structure
378 * @mbx_id: id of mailbox to check
380 * returns true if the PF has set the reset done bit or else false
382 STATIC s32 e1000_check_for_rst_vf(struct e1000_hw *hw,
383 u16 E1000_UNUSEDARG mbx_id)
385 s32 ret_val = -E1000_ERR_MBX;
387 UNREFERENCED_1PARAMETER(mbx_id);
388 DEBUGFUNC("e1000_check_for_rst_vf");
390 if (!e1000_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
391 E1000_V2PMAILBOX_RSTI))) {
392 ret_val = E1000_SUCCESS;
393 hw->mbx.stats.rsts++;
400 * e1000_obtain_mbx_lock_vf - obtain mailbox lock
401 * @hw: pointer to the HW structure
403 * return SUCCESS if we obtained the mailbox lock
405 STATIC s32 e1000_obtain_mbx_lock_vf(struct e1000_hw *hw)
407 s32 ret_val = -E1000_ERR_MBX;
410 DEBUGFUNC("e1000_obtain_mbx_lock_vf");
413 /* Take ownership of the buffer */
414 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
416 /* reserve mailbox for vf use */
417 if (e1000_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU) {
418 ret_val = E1000_SUCCESS;
422 } while (count-- > 0);
428 * e1000_write_mbx_vf - Write a message to the mailbox
429 * @hw: pointer to the HW structure
430 * @msg: The message buffer
431 * @size: Length of buffer
432 * @mbx_id: id of mailbox to write
434 * returns SUCCESS if it successfully copied message into the buffer
436 STATIC s32 e1000_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
437 u16 E1000_UNUSEDARG mbx_id)
442 UNREFERENCED_1PARAMETER(mbx_id);
444 DEBUGFUNC("e1000_write_mbx_vf");
446 /* lock the mailbox to prevent pf/vf race condition */
447 ret_val = e1000_obtain_mbx_lock_vf(hw);
451 /* flush msg and acks as we are overwriting the message buffer */
452 e1000_check_for_msg_vf(hw, 0);
453 e1000_check_for_ack_vf(hw, 0);
455 /* copy the caller specified message to the mailbox memory buffer */
456 for (i = 0; i < size; i++)
457 E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(0), i, msg[i]);
460 hw->mbx.stats.msgs_tx++;
462 /* Drop VFU and interrupt the PF to tell it a message has been sent */
463 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
470 * e1000_read_mbx_vf - Reads a message from the inbox intended for vf
471 * @hw: pointer to the HW structure
472 * @msg: The message buffer
473 * @size: Length of buffer
474 * @mbx_id: id of mailbox to read
476 * returns SUCCESS if it successfully read message from buffer
478 STATIC s32 e1000_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
479 u16 E1000_UNUSEDARG mbx_id)
481 s32 ret_val = E1000_SUCCESS;
484 DEBUGFUNC("e1000_read_mbx_vf");
485 UNREFERENCED_1PARAMETER(mbx_id);
487 /* lock the mailbox to prevent pf/vf race condition */
488 ret_val = e1000_obtain_mbx_lock_vf(hw);
492 /* copy the message from the mailbox memory buffer */
493 for (i = 0; i < size; i++)
494 msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(0), i);
496 /* Acknowledge receipt and release mailbox, then we're done */
497 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
500 hw->mbx.stats.msgs_rx++;
507 * e1000_init_mbx_params_vf - set initial values for vf mailbox
508 * @hw: pointer to the HW structure
510 * Initializes the hw->mbx struct to correct values for vf mailbox
512 s32 e1000_init_mbx_params_vf(struct e1000_hw *hw)
514 struct e1000_mbx_info *mbx = &hw->mbx;
516 /* start mailbox as timed out and let the reset_hw call set the timeout
517 * value to begin communications */
519 mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
521 mbx->size = E1000_VFMAILBOX_SIZE;
523 mbx->ops.read = e1000_read_mbx_vf;
524 mbx->ops.write = e1000_write_mbx_vf;
525 mbx->ops.read_posted = e1000_read_posted_mbx;
526 mbx->ops.write_posted = e1000_write_posted_mbx;
527 mbx->ops.check_for_msg = e1000_check_for_msg_vf;
528 mbx->ops.check_for_ack = e1000_check_for_ack_vf;
529 mbx->ops.check_for_rst = e1000_check_for_rst_vf;
531 mbx->stats.msgs_tx = 0;
532 mbx->stats.msgs_rx = 0;
537 return E1000_SUCCESS;
540 STATIC s32 e1000_check_for_bit_pf(struct e1000_hw *hw, u32 mask)
542 u32 mbvficr = E1000_READ_REG(hw, E1000_MBVFICR);
543 s32 ret_val = -E1000_ERR_MBX;
545 if (mbvficr & mask) {
546 ret_val = E1000_SUCCESS;
547 E1000_WRITE_REG(hw, E1000_MBVFICR, mask);
554 * e1000_check_for_msg_pf - checks to see if the VF has sent mail
555 * @hw: pointer to the HW structure
556 * @vf_number: the VF index
558 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
560 STATIC s32 e1000_check_for_msg_pf(struct e1000_hw *hw, u16 vf_number)
562 s32 ret_val = -E1000_ERR_MBX;
564 DEBUGFUNC("e1000_check_for_msg_pf");
566 if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFREQ_VF1 << vf_number)) {
567 ret_val = E1000_SUCCESS;
568 hw->mbx.stats.reqs++;
575 * e1000_check_for_ack_pf - checks to see if the VF has ACKed
576 * @hw: pointer to the HW structure
577 * @vf_number: the VF index
579 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
581 STATIC s32 e1000_check_for_ack_pf(struct e1000_hw *hw, u16 vf_number)
583 s32 ret_val = -E1000_ERR_MBX;
585 DEBUGFUNC("e1000_check_for_ack_pf");
587 if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFACK_VF1 << vf_number)) {
588 ret_val = E1000_SUCCESS;
589 hw->mbx.stats.acks++;
596 * e1000_check_for_rst_pf - checks to see if the VF has reset
597 * @hw: pointer to the HW structure
598 * @vf_number: the VF index
600 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
602 STATIC s32 e1000_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
604 u32 vflre = E1000_READ_REG(hw, E1000_VFLRE);
605 s32 ret_val = -E1000_ERR_MBX;
607 DEBUGFUNC("e1000_check_for_rst_pf");
609 if (vflre & (1 << vf_number)) {
610 ret_val = E1000_SUCCESS;
611 E1000_WRITE_REG(hw, E1000_VFLRE, (1 << vf_number));
612 hw->mbx.stats.rsts++;
619 * e1000_obtain_mbx_lock_pf - obtain mailbox lock
620 * @hw: pointer to the HW structure
621 * @vf_number: the VF index
623 * return SUCCESS if we obtained the mailbox lock
625 STATIC s32 e1000_obtain_mbx_lock_pf(struct e1000_hw *hw, u16 vf_number)
627 s32 ret_val = -E1000_ERR_MBX;
631 DEBUGFUNC("e1000_obtain_mbx_lock_pf");
634 /* Take ownership of the buffer */
635 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number),
636 E1000_P2VMAILBOX_PFU);
638 /* reserve mailbox for pf use */
639 p2v_mailbox = E1000_READ_REG(hw, E1000_P2VMAILBOX(vf_number));
640 if (p2v_mailbox & E1000_P2VMAILBOX_PFU) {
641 ret_val = E1000_SUCCESS;
645 } while (count-- > 0);
652 * e1000_write_mbx_pf - Places a message in the mailbox
653 * @hw: pointer to the HW structure
654 * @msg: The message buffer
655 * @size: Length of buffer
656 * @vf_number: the VF index
658 * returns SUCCESS if it successfully copied message into the buffer
660 STATIC s32 e1000_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
666 DEBUGFUNC("e1000_write_mbx_pf");
668 /* lock the mailbox to prevent pf/vf race condition */
669 ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
673 /* flush msg and acks as we are overwriting the message buffer */
674 e1000_check_for_msg_pf(hw, vf_number);
675 e1000_check_for_ack_pf(hw, vf_number);
677 /* copy the caller specified message to the mailbox memory buffer */
678 for (i = 0; i < size; i++)
679 E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i, msg[i]);
681 /* Interrupt VF to tell it a message has been sent and release buffer*/
682 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_STS);
685 hw->mbx.stats.msgs_tx++;
693 * e1000_read_mbx_pf - Read a message from the mailbox
694 * @hw: pointer to the HW structure
695 * @msg: The message buffer
696 * @size: Length of buffer
697 * @vf_number: the VF index
699 * This function copies a message from the mailbox buffer to the caller's
700 * memory buffer. The presumption is that the caller knows that there was
701 * a message due to a VF request so no polling for message is needed.
703 STATIC s32 e1000_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
709 DEBUGFUNC("e1000_read_mbx_pf");
711 /* lock the mailbox to prevent pf/vf race condition */
712 ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
716 /* copy the message to the mailbox memory buffer */
717 for (i = 0; i < size; i++)
718 msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i);
720 /* Acknowledge the message and release buffer */
721 E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_ACK);
724 hw->mbx.stats.msgs_rx++;
731 * e1000_init_mbx_params_pf - set initial values for pf mailbox
732 * @hw: pointer to the HW structure
734 * Initializes the hw->mbx struct to correct values for pf mailbox
736 s32 e1000_init_mbx_params_pf(struct e1000_hw *hw)
738 struct e1000_mbx_info *mbx = &hw->mbx;
740 switch (hw->mac.type) {
747 mbx->size = E1000_VFMAILBOX_SIZE;
749 mbx->ops.read = e1000_read_mbx_pf;
750 mbx->ops.write = e1000_write_mbx_pf;
751 mbx->ops.read_posted = e1000_read_posted_mbx;
752 mbx->ops.write_posted = e1000_write_posted_mbx;
753 mbx->ops.check_for_msg = e1000_check_for_msg_pf;
754 mbx->ops.check_for_ack = e1000_check_for_ack_pf;
755 mbx->ops.check_for_rst = e1000_check_for_rst_pf;
757 mbx->stats.msgs_tx = 0;
758 mbx->stats.msgs_rx = 0;
764 return E1000_SUCCESS;