2 * Copyright (C) 2005 - 2010 ServerEngines
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@serverengines.com
14 * 209 N. Fair Oaks Ave
21 static void be_mcc_notify(struct be_adapter
*adapter
)
23 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
26 val
|= mccq
->id
& DB_MCCQ_RING_ID_MASK
;
27 val
|= 1 << DB_MCCQ_NUM_POSTED_SHIFT
;
30 iowrite32(val
, adapter
->db
+ DB_MCCQ_OFFSET
);
33 /* To check if valid bit is set, check the entire word as we don't know
34 * the endianness of the data (old entry is host endian while a new entry is
36 static inline bool be_mcc_compl_is_new(struct be_mcc_compl
*compl)
38 if (compl->flags
!= 0) {
39 compl->flags
= le32_to_cpu(compl->flags
);
40 BUG_ON((compl->flags
& CQE_FLAGS_VALID_MASK
) == 0);
47 /* Need to reset the entire word that houses the valid bit */
48 static inline void be_mcc_compl_use(struct be_mcc_compl
*compl)
53 static int be_mcc_compl_process(struct be_adapter
*adapter
,
54 struct be_mcc_compl
*compl)
56 u16 compl_status
, extd_status
;
58 /* Just swap the status to host endian; mcc tag is opaquely copied
60 be_dws_le_to_cpu(compl, 4);
62 compl_status
= (compl->status
>> CQE_STATUS_COMPL_SHIFT
) &
63 CQE_STATUS_COMPL_MASK
;
65 if ((compl->tag0
== OPCODE_COMMON_WRITE_FLASHROM
) &&
66 (compl->tag1
== CMD_SUBSYSTEM_COMMON
)) {
67 adapter
->flash_status
= compl_status
;
68 complete(&adapter
->flash_compl
);
71 if (compl_status
== MCC_STATUS_SUCCESS
) {
72 if (compl->tag0
== OPCODE_ETH_GET_STATISTICS
) {
73 struct be_cmd_resp_get_stats
*resp
=
74 adapter
->stats
.cmd
.va
;
75 be_dws_le_to_cpu(&resp
->hw_stats
,
76 sizeof(resp
->hw_stats
));
77 netdev_stats_update(adapter
);
78 adapter
->stats_ioctl_sent
= false;
80 } else if ((compl_status
!= MCC_STATUS_NOT_SUPPORTED
) &&
81 (compl->tag0
!= OPCODE_COMMON_NTWK_MAC_QUERY
)) {
82 extd_status
= (compl->status
>> CQE_STATUS_EXTD_SHIFT
) &
84 dev_warn(&adapter
->pdev
->dev
,
85 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
86 compl->tag0
, compl_status
, extd_status
);
91 /* Link state evt is a string of bytes; no need for endian swapping */
92 static void be_async_link_state_process(struct be_adapter
*adapter
,
93 struct be_async_event_link_state
*evt
)
95 be_link_status_update(adapter
,
96 evt
->port_link_status
== ASYNC_EVENT_LINK_UP
);
99 static inline bool is_link_state_evt(u32 trailer
)
101 return (((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
102 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
103 ASYNC_EVENT_CODE_LINK_STATE
);
106 static struct be_mcc_compl
*be_mcc_compl_get(struct be_adapter
*adapter
)
108 struct be_queue_info
*mcc_cq
= &adapter
->mcc_obj
.cq
;
109 struct be_mcc_compl
*compl = queue_tail_node(mcc_cq
);
111 if (be_mcc_compl_is_new(compl)) {
112 queue_tail_inc(mcc_cq
);
118 void be_async_mcc_enable(struct be_adapter
*adapter
)
120 spin_lock_bh(&adapter
->mcc_cq_lock
);
122 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, true, 0);
123 adapter
->mcc_obj
.rearm_cq
= true;
125 spin_unlock_bh(&adapter
->mcc_cq_lock
);
128 void be_async_mcc_disable(struct be_adapter
*adapter
)
130 adapter
->mcc_obj
.rearm_cq
= false;
133 int be_process_mcc(struct be_adapter
*adapter
, int *status
)
135 struct be_mcc_compl
*compl;
137 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
139 spin_lock_bh(&adapter
->mcc_cq_lock
);
140 while ((compl = be_mcc_compl_get(adapter
))) {
141 if (compl->flags
& CQE_FLAGS_ASYNC_MASK
) {
142 /* Interpret flags as an async trailer */
143 BUG_ON(!is_link_state_evt(compl->flags
));
145 /* Interpret compl as a async link evt */
146 be_async_link_state_process(adapter
,
147 (struct be_async_event_link_state
*) compl);
148 } else if (compl->flags
& CQE_FLAGS_COMPLETED_MASK
) {
149 *status
= be_mcc_compl_process(adapter
, compl);
150 atomic_dec(&mcc_obj
->q
.used
);
152 be_mcc_compl_use(compl);
156 spin_unlock_bh(&adapter
->mcc_cq_lock
);
160 /* Wait till no more pending mcc requests are present */
161 static int be_mcc_wait_compl(struct be_adapter
*adapter
)
163 #define mcc_timeout 120000 /* 12s timeout */
164 int i
, num
, status
= 0;
165 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
167 for (i
= 0; i
< mcc_timeout
; i
++) {
168 num
= be_process_mcc(adapter
, &status
);
170 be_cq_notify(adapter
, mcc_obj
->cq
.id
,
171 mcc_obj
->rearm_cq
, num
);
173 if (atomic_read(&mcc_obj
->q
.used
) == 0)
177 if (i
== mcc_timeout
) {
178 dev_err(&adapter
->pdev
->dev
, "mccq poll timed out\n");
184 /* Notify MCC requests and wait for completion */
185 static int be_mcc_notify_wait(struct be_adapter
*adapter
)
187 be_mcc_notify(adapter
);
188 return be_mcc_wait_compl(adapter
);
191 static int be_mbox_db_ready_wait(struct be_adapter
*adapter
, void __iomem
*db
)
197 ready
= ioread32(db
);
198 if (ready
== 0xffffffff) {
199 dev_err(&adapter
->pdev
->dev
,
200 "pci slot disconnected\n");
204 ready
&= MPU_MAILBOX_DB_RDY_MASK
;
209 dev_err(&adapter
->pdev
->dev
, "mbox poll timed out\n");
214 set_current_state(TASK_INTERRUPTIBLE
);
215 schedule_timeout(msecs_to_jiffies(1));
223 * Insert the mailbox address into the doorbell in two steps
224 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
226 static int be_mbox_notify_wait(struct be_adapter
*adapter
)
230 void __iomem
*db
= adapter
->db
+ MPU_MAILBOX_DB_OFFSET
;
231 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
232 struct be_mcc_mailbox
*mbox
= mbox_mem
->va
;
233 struct be_mcc_compl
*compl = &mbox
->compl;
235 /* wait for ready to be set */
236 status
= be_mbox_db_ready_wait(adapter
, db
);
240 val
|= MPU_MAILBOX_DB_HI_MASK
;
241 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
242 val
|= (upper_32_bits(mbox_mem
->dma
) >> 2) << 2;
245 /* wait for ready to be set */
246 status
= be_mbox_db_ready_wait(adapter
, db
);
251 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
252 val
|= (u32
)(mbox_mem
->dma
>> 4) << 2;
255 status
= be_mbox_db_ready_wait(adapter
, db
);
259 /* A cq entry has been made now */
260 if (be_mcc_compl_is_new(compl)) {
261 status
= be_mcc_compl_process(adapter
, &mbox
->compl);
262 be_mcc_compl_use(compl);
266 dev_err(&adapter
->pdev
->dev
, "invalid mailbox completion\n");
272 static int be_POST_stage_get(struct be_adapter
*adapter
, u16
*stage
)
274 u32 sem
= ioread32(adapter
->csr
+ MPU_EP_SEMAPHORE_OFFSET
);
276 *stage
= sem
& EP_SEMAPHORE_POST_STAGE_MASK
;
277 if ((sem
>> EP_SEMAPHORE_POST_ERR_SHIFT
) & EP_SEMAPHORE_POST_ERR_MASK
)
283 int be_cmd_POST(struct be_adapter
*adapter
)
286 int status
, timeout
= 0;
289 status
= be_POST_stage_get(adapter
, &stage
);
291 dev_err(&adapter
->pdev
->dev
, "POST error; stage=0x%x\n",
294 } else if (stage
!= POST_STAGE_ARMFW_RDY
) {
295 set_current_state(TASK_INTERRUPTIBLE
);
296 schedule_timeout(2 * HZ
);
301 } while (timeout
< 40);
303 dev_err(&adapter
->pdev
->dev
, "POST timeout; stage=0x%x\n", stage
);
307 static inline void *embedded_payload(struct be_mcc_wrb
*wrb
)
309 return wrb
->payload
.embedded_payload
;
312 static inline struct be_sge
*nonembedded_sgl(struct be_mcc_wrb
*wrb
)
314 return &wrb
->payload
.sgl
[0];
317 /* Don't touch the hdr after it's prepared */
318 static void be_wrb_hdr_prepare(struct be_mcc_wrb
*wrb
, int payload_len
,
319 bool embedded
, u8 sge_cnt
, u32 opcode
)
322 wrb
->embedded
|= MCC_WRB_EMBEDDED_MASK
;
324 wrb
->embedded
|= (sge_cnt
& MCC_WRB_SGE_CNT_MASK
) <<
325 MCC_WRB_SGE_CNT_SHIFT
;
326 wrb
->payload_length
= payload_len
;
328 be_dws_cpu_to_le(wrb
, 8);
331 /* Don't touch the hdr after it's prepared */
332 static void be_cmd_hdr_prepare(struct be_cmd_req_hdr
*req_hdr
,
333 u8 subsystem
, u8 opcode
, int cmd_len
)
335 req_hdr
->opcode
= opcode
;
336 req_hdr
->subsystem
= subsystem
;
337 req_hdr
->request_length
= cpu_to_le32(cmd_len
- sizeof(*req_hdr
));
338 req_hdr
->version
= 0;
341 static void be_cmd_page_addrs_prepare(struct phys_addr
*pages
, u32 max_pages
,
342 struct be_dma_mem
*mem
)
344 int i
, buf_pages
= min(PAGES_4K_SPANNED(mem
->va
, mem
->size
), max_pages
);
345 u64 dma
= (u64
)mem
->dma
;
347 for (i
= 0; i
< buf_pages
; i
++) {
348 pages
[i
].lo
= cpu_to_le32(dma
& 0xFFFFFFFF);
349 pages
[i
].hi
= cpu_to_le32(upper_32_bits(dma
));
354 /* Converts interrupt delay in microseconds to multiplier value */
355 static u32
eq_delay_to_mult(u32 usec_delay
)
357 #define MAX_INTR_RATE 651042
358 const u32 round
= 10;
364 u32 interrupt_rate
= 1000000 / usec_delay
;
365 /* Max delay, corresponding to the lowest interrupt rate */
366 if (interrupt_rate
== 0)
369 multiplier
= (MAX_INTR_RATE
- interrupt_rate
) * round
;
370 multiplier
/= interrupt_rate
;
371 /* Round the multiplier to the closest value.*/
372 multiplier
= (multiplier
+ round
/2) / round
;
373 multiplier
= min(multiplier
, (u32
)1023);
379 static inline struct be_mcc_wrb
*wrb_from_mbox(struct be_adapter
*adapter
)
381 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
382 struct be_mcc_wrb
*wrb
383 = &((struct be_mcc_mailbox
*)(mbox_mem
->va
))->wrb
;
384 memset(wrb
, 0, sizeof(*wrb
));
388 static struct be_mcc_wrb
*wrb_from_mccq(struct be_adapter
*adapter
)
390 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
391 struct be_mcc_wrb
*wrb
;
393 if (atomic_read(&mccq
->used
) >= mccq
->len
) {
394 dev_err(&adapter
->pdev
->dev
, "Out of MCCQ wrbs\n");
398 wrb
= queue_head_node(mccq
);
399 queue_head_inc(mccq
);
400 atomic_inc(&mccq
->used
);
401 memset(wrb
, 0, sizeof(*wrb
));
405 /* Tell fw we're about to start firing cmds by writing a
406 * special pattern across the wrb hdr; uses mbox
408 int be_cmd_fw_init(struct be_adapter
*adapter
)
413 spin_lock(&adapter
->mbox_lock
);
415 wrb
= (u8
*)wrb_from_mbox(adapter
);
425 status
= be_mbox_notify_wait(adapter
);
427 spin_unlock(&adapter
->mbox_lock
);
431 /* Tell fw we're done with firing cmds by writing a
432 * special pattern across the wrb hdr; uses mbox
434 int be_cmd_fw_clean(struct be_adapter
*adapter
)
439 if (adapter
->eeh_err
)
442 spin_lock(&adapter
->mbox_lock
);
444 wrb
= (u8
*)wrb_from_mbox(adapter
);
454 status
= be_mbox_notify_wait(adapter
);
456 spin_unlock(&adapter
->mbox_lock
);
459 int be_cmd_eq_create(struct be_adapter
*adapter
,
460 struct be_queue_info
*eq
, int eq_delay
)
462 struct be_mcc_wrb
*wrb
;
463 struct be_cmd_req_eq_create
*req
;
464 struct be_dma_mem
*q_mem
= &eq
->dma_mem
;
467 spin_lock(&adapter
->mbox_lock
);
469 wrb
= wrb_from_mbox(adapter
);
470 req
= embedded_payload(wrb
);
472 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_COMMON_EQ_CREATE
);
474 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
475 OPCODE_COMMON_EQ_CREATE
, sizeof(*req
));
477 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
479 AMAP_SET_BITS(struct amap_eq_context
, valid
, req
->context
, 1);
481 AMAP_SET_BITS(struct amap_eq_context
, size
, req
->context
, 0);
482 AMAP_SET_BITS(struct amap_eq_context
, count
, req
->context
,
483 __ilog2_u32(eq
->len
/256));
484 AMAP_SET_BITS(struct amap_eq_context
, delaymult
, req
->context
,
485 eq_delay_to_mult(eq_delay
));
486 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
488 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
490 status
= be_mbox_notify_wait(adapter
);
492 struct be_cmd_resp_eq_create
*resp
= embedded_payload(wrb
);
493 eq
->id
= le16_to_cpu(resp
->eq_id
);
497 spin_unlock(&adapter
->mbox_lock
);
502 int be_cmd_mac_addr_query(struct be_adapter
*adapter
, u8
*mac_addr
,
503 u8 type
, bool permanent
, u32 if_handle
)
505 struct be_mcc_wrb
*wrb
;
506 struct be_cmd_req_mac_query
*req
;
509 spin_lock(&adapter
->mbox_lock
);
511 wrb
= wrb_from_mbox(adapter
);
512 req
= embedded_payload(wrb
);
514 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
515 OPCODE_COMMON_NTWK_MAC_QUERY
);
517 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
518 OPCODE_COMMON_NTWK_MAC_QUERY
, sizeof(*req
));
524 req
->if_id
= cpu_to_le16((u16
) if_handle
);
528 status
= be_mbox_notify_wait(adapter
);
530 struct be_cmd_resp_mac_query
*resp
= embedded_payload(wrb
);
531 memcpy(mac_addr
, resp
->mac
.addr
, ETH_ALEN
);
534 spin_unlock(&adapter
->mbox_lock
);
538 /* Uses synchronous MCCQ */
539 int be_cmd_pmac_add(struct be_adapter
*adapter
, u8
*mac_addr
,
540 u32 if_id
, u32
*pmac_id
)
542 struct be_mcc_wrb
*wrb
;
543 struct be_cmd_req_pmac_add
*req
;
546 spin_lock_bh(&adapter
->mcc_lock
);
548 wrb
= wrb_from_mccq(adapter
);
553 req
= embedded_payload(wrb
);
555 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
556 OPCODE_COMMON_NTWK_PMAC_ADD
);
558 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
559 OPCODE_COMMON_NTWK_PMAC_ADD
, sizeof(*req
));
561 req
->if_id
= cpu_to_le32(if_id
);
562 memcpy(req
->mac_address
, mac_addr
, ETH_ALEN
);
564 status
= be_mcc_notify_wait(adapter
);
566 struct be_cmd_resp_pmac_add
*resp
= embedded_payload(wrb
);
567 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
571 spin_unlock_bh(&adapter
->mcc_lock
);
575 /* Uses synchronous MCCQ */
576 int be_cmd_pmac_del(struct be_adapter
*adapter
, u32 if_id
, u32 pmac_id
)
578 struct be_mcc_wrb
*wrb
;
579 struct be_cmd_req_pmac_del
*req
;
582 spin_lock_bh(&adapter
->mcc_lock
);
584 wrb
= wrb_from_mccq(adapter
);
589 req
= embedded_payload(wrb
);
591 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
592 OPCODE_COMMON_NTWK_PMAC_DEL
);
594 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
595 OPCODE_COMMON_NTWK_PMAC_DEL
, sizeof(*req
));
597 req
->if_id
= cpu_to_le32(if_id
);
598 req
->pmac_id
= cpu_to_le32(pmac_id
);
600 status
= be_mcc_notify_wait(adapter
);
603 spin_unlock_bh(&adapter
->mcc_lock
);
608 int be_cmd_cq_create(struct be_adapter
*adapter
,
609 struct be_queue_info
*cq
, struct be_queue_info
*eq
,
610 bool sol_evts
, bool no_delay
, int coalesce_wm
)
612 struct be_mcc_wrb
*wrb
;
613 struct be_cmd_req_cq_create
*req
;
614 struct be_dma_mem
*q_mem
= &cq
->dma_mem
;
618 spin_lock(&adapter
->mbox_lock
);
620 wrb
= wrb_from_mbox(adapter
);
621 req
= embedded_payload(wrb
);
622 ctxt
= &req
->context
;
624 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
625 OPCODE_COMMON_CQ_CREATE
);
627 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
628 OPCODE_COMMON_CQ_CREATE
, sizeof(*req
));
630 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
632 AMAP_SET_BITS(struct amap_cq_context
, coalescwm
, ctxt
, coalesce_wm
);
633 AMAP_SET_BITS(struct amap_cq_context
, nodelay
, ctxt
, no_delay
);
634 AMAP_SET_BITS(struct amap_cq_context
, count
, ctxt
,
635 __ilog2_u32(cq
->len
/256));
636 AMAP_SET_BITS(struct amap_cq_context
, valid
, ctxt
, 1);
637 AMAP_SET_BITS(struct amap_cq_context
, solevent
, ctxt
, sol_evts
);
638 AMAP_SET_BITS(struct amap_cq_context
, eventable
, ctxt
, 1);
639 AMAP_SET_BITS(struct amap_cq_context
, eqid
, ctxt
, eq
->id
);
640 AMAP_SET_BITS(struct amap_cq_context
, armed
, ctxt
, 1);
641 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
643 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
645 status
= be_mbox_notify_wait(adapter
);
647 struct be_cmd_resp_cq_create
*resp
= embedded_payload(wrb
);
648 cq
->id
= le16_to_cpu(resp
->cq_id
);
652 spin_unlock(&adapter
->mbox_lock
);
657 static u32
be_encoded_q_len(int q_len
)
659 u32 len_encoded
= fls(q_len
); /* log2(len) + 1 */
660 if (len_encoded
== 16)
665 int be_cmd_mccq_create(struct be_adapter
*adapter
,
666 struct be_queue_info
*mccq
,
667 struct be_queue_info
*cq
)
669 struct be_mcc_wrb
*wrb
;
670 struct be_cmd_req_mcc_create
*req
;
671 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
675 spin_lock(&adapter
->mbox_lock
);
677 wrb
= wrb_from_mbox(adapter
);
678 req
= embedded_payload(wrb
);
679 ctxt
= &req
->context
;
681 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
682 OPCODE_COMMON_MCC_CREATE
);
684 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
685 OPCODE_COMMON_MCC_CREATE
, sizeof(*req
));
687 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
689 AMAP_SET_BITS(struct amap_mcc_context
, valid
, ctxt
, 1);
690 AMAP_SET_BITS(struct amap_mcc_context
, ring_size
, ctxt
,
691 be_encoded_q_len(mccq
->len
));
692 AMAP_SET_BITS(struct amap_mcc_context
, cq_id
, ctxt
, cq
->id
);
694 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
696 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
698 status
= be_mbox_notify_wait(adapter
);
700 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
701 mccq
->id
= le16_to_cpu(resp
->id
);
702 mccq
->created
= true;
704 spin_unlock(&adapter
->mbox_lock
);
709 int be_cmd_txq_create(struct be_adapter
*adapter
,
710 struct be_queue_info
*txq
,
711 struct be_queue_info
*cq
)
713 struct be_mcc_wrb
*wrb
;
714 struct be_cmd_req_eth_tx_create
*req
;
715 struct be_dma_mem
*q_mem
= &txq
->dma_mem
;
719 spin_lock(&adapter
->mbox_lock
);
721 wrb
= wrb_from_mbox(adapter
);
722 req
= embedded_payload(wrb
);
723 ctxt
= &req
->context
;
725 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
726 OPCODE_ETH_TX_CREATE
);
728 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_TX_CREATE
,
731 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
732 req
->ulp_num
= BE_ULP1_NUM
;
733 req
->type
= BE_ETH_TX_RING_TYPE_STANDARD
;
735 AMAP_SET_BITS(struct amap_tx_context
, tx_ring_size
, ctxt
,
736 be_encoded_q_len(txq
->len
));
737 AMAP_SET_BITS(struct amap_tx_context
, ctx_valid
, ctxt
, 1);
738 AMAP_SET_BITS(struct amap_tx_context
, cq_id_send
, ctxt
, cq
->id
);
740 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
742 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
744 status
= be_mbox_notify_wait(adapter
);
746 struct be_cmd_resp_eth_tx_create
*resp
= embedded_payload(wrb
);
747 txq
->id
= le16_to_cpu(resp
->cid
);
751 spin_unlock(&adapter
->mbox_lock
);
757 int be_cmd_rxq_create(struct be_adapter
*adapter
,
758 struct be_queue_info
*rxq
, u16 cq_id
, u16 frag_size
,
759 u16 max_frame_size
, u32 if_id
, u32 rss
)
761 struct be_mcc_wrb
*wrb
;
762 struct be_cmd_req_eth_rx_create
*req
;
763 struct be_dma_mem
*q_mem
= &rxq
->dma_mem
;
766 spin_lock(&adapter
->mbox_lock
);
768 wrb
= wrb_from_mbox(adapter
);
769 req
= embedded_payload(wrb
);
771 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
772 OPCODE_ETH_RX_CREATE
);
774 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_RX_CREATE
,
777 req
->cq_id
= cpu_to_le16(cq_id
);
778 req
->frag_size
= fls(frag_size
) - 1;
780 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
781 req
->interface_id
= cpu_to_le32(if_id
);
782 req
->max_frame_size
= cpu_to_le16(max_frame_size
);
783 req
->rss_queue
= cpu_to_le32(rss
);
785 status
= be_mbox_notify_wait(adapter
);
787 struct be_cmd_resp_eth_rx_create
*resp
= embedded_payload(wrb
);
788 rxq
->id
= le16_to_cpu(resp
->id
);
792 spin_unlock(&adapter
->mbox_lock
);
797 /* Generic destroyer function for all types of queues
800 int be_cmd_q_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
,
803 struct be_mcc_wrb
*wrb
;
804 struct be_cmd_req_q_destroy
*req
;
805 u8 subsys
= 0, opcode
= 0;
808 if (adapter
->eeh_err
)
811 spin_lock(&adapter
->mbox_lock
);
813 wrb
= wrb_from_mbox(adapter
);
814 req
= embedded_payload(wrb
);
816 switch (queue_type
) {
818 subsys
= CMD_SUBSYSTEM_COMMON
;
819 opcode
= OPCODE_COMMON_EQ_DESTROY
;
822 subsys
= CMD_SUBSYSTEM_COMMON
;
823 opcode
= OPCODE_COMMON_CQ_DESTROY
;
826 subsys
= CMD_SUBSYSTEM_ETH
;
827 opcode
= OPCODE_ETH_TX_DESTROY
;
830 subsys
= CMD_SUBSYSTEM_ETH
;
831 opcode
= OPCODE_ETH_RX_DESTROY
;
834 subsys
= CMD_SUBSYSTEM_COMMON
;
835 opcode
= OPCODE_COMMON_MCC_DESTROY
;
841 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, opcode
);
843 be_cmd_hdr_prepare(&req
->hdr
, subsys
, opcode
, sizeof(*req
));
844 req
->id
= cpu_to_le16(q
->id
);
846 status
= be_mbox_notify_wait(adapter
);
848 spin_unlock(&adapter
->mbox_lock
);
853 /* Create an rx filtering policy configuration on an i/f
856 int be_cmd_if_create(struct be_adapter
*adapter
, u32 cap_flags
, u32 en_flags
,
857 u8
*mac
, bool pmac_invalid
, u32
*if_handle
, u32
*pmac_id
,
860 struct be_mcc_wrb
*wrb
;
861 struct be_cmd_req_if_create
*req
;
864 spin_lock(&adapter
->mbox_lock
);
866 wrb
= wrb_from_mbox(adapter
);
867 req
= embedded_payload(wrb
);
869 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
870 OPCODE_COMMON_NTWK_INTERFACE_CREATE
);
872 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
873 OPCODE_COMMON_NTWK_INTERFACE_CREATE
, sizeof(*req
));
875 req
->hdr
.domain
= domain
;
876 req
->capability_flags
= cpu_to_le32(cap_flags
);
877 req
->enable_flags
= cpu_to_le32(en_flags
);
878 req
->pmac_invalid
= pmac_invalid
;
880 memcpy(req
->mac_addr
, mac
, ETH_ALEN
);
882 status
= be_mbox_notify_wait(adapter
);
884 struct be_cmd_resp_if_create
*resp
= embedded_payload(wrb
);
885 *if_handle
= le32_to_cpu(resp
->interface_id
);
887 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
890 spin_unlock(&adapter
->mbox_lock
);
895 int be_cmd_if_destroy(struct be_adapter
*adapter
, u32 interface_id
)
897 struct be_mcc_wrb
*wrb
;
898 struct be_cmd_req_if_destroy
*req
;
901 if (adapter
->eeh_err
)
904 spin_lock(&adapter
->mbox_lock
);
906 wrb
= wrb_from_mbox(adapter
);
907 req
= embedded_payload(wrb
);
909 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
910 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
);
912 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
913 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
, sizeof(*req
));
915 req
->interface_id
= cpu_to_le32(interface_id
);
917 status
= be_mbox_notify_wait(adapter
);
919 spin_unlock(&adapter
->mbox_lock
);
924 /* Get stats is a non embedded command: the request is not embedded inside
925 * WRB but is a separate dma memory block
926 * Uses asynchronous MCC
928 int be_cmd_get_stats(struct be_adapter
*adapter
, struct be_dma_mem
*nonemb_cmd
)
930 struct be_mcc_wrb
*wrb
;
931 struct be_cmd_req_get_stats
*req
;
935 spin_lock_bh(&adapter
->mcc_lock
);
937 wrb
= wrb_from_mccq(adapter
);
942 req
= nonemb_cmd
->va
;
943 sge
= nonembedded_sgl(wrb
);
945 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
946 OPCODE_ETH_GET_STATISTICS
);
948 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
949 OPCODE_ETH_GET_STATISTICS
, sizeof(*req
));
950 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
951 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
952 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
954 be_mcc_notify(adapter
);
955 adapter
->stats_ioctl_sent
= true;
958 spin_unlock_bh(&adapter
->mcc_lock
);
962 /* Uses synchronous mcc */
963 int be_cmd_link_status_query(struct be_adapter
*adapter
,
964 bool *link_up
, u8
*mac_speed
, u16
*link_speed
)
966 struct be_mcc_wrb
*wrb
;
967 struct be_cmd_req_link_status
*req
;
970 spin_lock_bh(&adapter
->mcc_lock
);
972 wrb
= wrb_from_mccq(adapter
);
977 req
= embedded_payload(wrb
);
981 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
982 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
);
984 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
985 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
, sizeof(*req
));
987 status
= be_mcc_notify_wait(adapter
);
989 struct be_cmd_resp_link_status
*resp
= embedded_payload(wrb
);
990 if (resp
->mac_speed
!= PHY_LINK_SPEED_ZERO
) {
992 *link_speed
= le16_to_cpu(resp
->link_speed
);
993 *mac_speed
= resp
->mac_speed
;
998 spin_unlock_bh(&adapter
->mcc_lock
);
1003 int be_cmd_get_fw_ver(struct be_adapter
*adapter
, char *fw_ver
)
1005 struct be_mcc_wrb
*wrb
;
1006 struct be_cmd_req_get_fw_version
*req
;
1009 spin_lock(&adapter
->mbox_lock
);
1011 wrb
= wrb_from_mbox(adapter
);
1012 req
= embedded_payload(wrb
);
1014 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1015 OPCODE_COMMON_GET_FW_VERSION
);
1017 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1018 OPCODE_COMMON_GET_FW_VERSION
, sizeof(*req
));
1020 status
= be_mbox_notify_wait(adapter
);
1022 struct be_cmd_resp_get_fw_version
*resp
= embedded_payload(wrb
);
1023 strncpy(fw_ver
, resp
->firmware_version_string
, FW_VER_LEN
);
1026 spin_unlock(&adapter
->mbox_lock
);
1030 /* set the EQ delay interval of an EQ to specified value
1033 int be_cmd_modify_eqd(struct be_adapter
*adapter
, u32 eq_id
, u32 eqd
)
1035 struct be_mcc_wrb
*wrb
;
1036 struct be_cmd_req_modify_eq_delay
*req
;
1039 spin_lock_bh(&adapter
->mcc_lock
);
1041 wrb
= wrb_from_mccq(adapter
);
1046 req
= embedded_payload(wrb
);
1048 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1049 OPCODE_COMMON_MODIFY_EQ_DELAY
);
1051 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1052 OPCODE_COMMON_MODIFY_EQ_DELAY
, sizeof(*req
));
1054 req
->num_eq
= cpu_to_le32(1);
1055 req
->delay
[0].eq_id
= cpu_to_le32(eq_id
);
1056 req
->delay
[0].phase
= 0;
1057 req
->delay
[0].delay_multiplier
= cpu_to_le32(eqd
);
1059 be_mcc_notify(adapter
);
1062 spin_unlock_bh(&adapter
->mcc_lock
);
1066 /* Uses sycnhronous mcc */
1067 int be_cmd_vlan_config(struct be_adapter
*adapter
, u32 if_id
, u16
*vtag_array
,
1068 u32 num
, bool untagged
, bool promiscuous
)
1070 struct be_mcc_wrb
*wrb
;
1071 struct be_cmd_req_vlan_config
*req
;
1074 spin_lock_bh(&adapter
->mcc_lock
);
1076 wrb
= wrb_from_mccq(adapter
);
1081 req
= embedded_payload(wrb
);
1083 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1084 OPCODE_COMMON_NTWK_VLAN_CONFIG
);
1086 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1087 OPCODE_COMMON_NTWK_VLAN_CONFIG
, sizeof(*req
));
1089 req
->interface_id
= if_id
;
1090 req
->promiscuous
= promiscuous
;
1091 req
->untagged
= untagged
;
1092 req
->num_vlan
= num
;
1094 memcpy(req
->normal_vlan
, vtag_array
,
1095 req
->num_vlan
* sizeof(vtag_array
[0]));
1098 status
= be_mcc_notify_wait(adapter
);
1101 spin_unlock_bh(&adapter
->mcc_lock
);
1105 /* Uses MCC for this command as it may be called in BH context
1106 * Uses synchronous mcc
1108 int be_cmd_promiscuous_config(struct be_adapter
*adapter
, u8 port_num
, bool en
)
1110 struct be_mcc_wrb
*wrb
;
1111 struct be_cmd_req_promiscuous_config
*req
;
1114 spin_lock_bh(&adapter
->mcc_lock
);
1116 wrb
= wrb_from_mccq(adapter
);
1121 req
= embedded_payload(wrb
);
1123 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_ETH_PROMISCUOUS
);
1125 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1126 OPCODE_ETH_PROMISCUOUS
, sizeof(*req
));
1128 /* In FW versions X.102.149/X.101.487 and later,
1129 * the port setting associated only with the
1130 * issuing pci function will take effect
1133 req
->port1_promiscuous
= en
;
1135 req
->port0_promiscuous
= en
;
1137 status
= be_mcc_notify_wait(adapter
);
1140 spin_unlock_bh(&adapter
->mcc_lock
);
1145 * Uses MCC for this command as it may be called in BH context
1146 * (mc == NULL) => multicast promiscous
1148 int be_cmd_multicast_set(struct be_adapter
*adapter
, u32 if_id
,
1149 struct net_device
*netdev
, struct be_dma_mem
*mem
)
1151 struct be_mcc_wrb
*wrb
;
1152 struct be_cmd_req_mcast_mac_config
*req
= mem
->va
;
1156 spin_lock_bh(&adapter
->mcc_lock
);
1158 wrb
= wrb_from_mccq(adapter
);
1163 sge
= nonembedded_sgl(wrb
);
1164 memset(req
, 0, sizeof(*req
));
1166 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1167 OPCODE_COMMON_NTWK_MULTICAST_SET
);
1168 sge
->pa_hi
= cpu_to_le32(upper_32_bits(mem
->dma
));
1169 sge
->pa_lo
= cpu_to_le32(mem
->dma
& 0xFFFFFFFF);
1170 sge
->len
= cpu_to_le32(mem
->size
);
1172 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1173 OPCODE_COMMON_NTWK_MULTICAST_SET
, sizeof(*req
));
1175 req
->interface_id
= if_id
;
1178 struct netdev_hw_addr
*ha
;
1180 req
->num_mac
= cpu_to_le16(netdev_mc_count(netdev
));
1183 netdev_for_each_mc_addr(ha
, netdev
)
1184 memcpy(req
->mac
[i
].byte
, ha
->addr
, ETH_ALEN
);
1186 req
->promiscuous
= 1;
1189 status
= be_mcc_notify_wait(adapter
);
1192 spin_unlock_bh(&adapter
->mcc_lock
);
1196 /* Uses synchrounous mcc */
1197 int be_cmd_set_flow_control(struct be_adapter
*adapter
, u32 tx_fc
, u32 rx_fc
)
1199 struct be_mcc_wrb
*wrb
;
1200 struct be_cmd_req_set_flow_control
*req
;
1203 spin_lock_bh(&adapter
->mcc_lock
);
1205 wrb
= wrb_from_mccq(adapter
);
1210 req
= embedded_payload(wrb
);
1212 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1213 OPCODE_COMMON_SET_FLOW_CONTROL
);
1215 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1216 OPCODE_COMMON_SET_FLOW_CONTROL
, sizeof(*req
));
1218 req
->tx_flow_control
= cpu_to_le16((u16
)tx_fc
);
1219 req
->rx_flow_control
= cpu_to_le16((u16
)rx_fc
);
1221 status
= be_mcc_notify_wait(adapter
);
1224 spin_unlock_bh(&adapter
->mcc_lock
);
1229 int be_cmd_get_flow_control(struct be_adapter
*adapter
, u32
*tx_fc
, u32
*rx_fc
)
1231 struct be_mcc_wrb
*wrb
;
1232 struct be_cmd_req_get_flow_control
*req
;
1235 spin_lock_bh(&adapter
->mcc_lock
);
1237 wrb
= wrb_from_mccq(adapter
);
1242 req
= embedded_payload(wrb
);
1244 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1245 OPCODE_COMMON_GET_FLOW_CONTROL
);
1247 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1248 OPCODE_COMMON_GET_FLOW_CONTROL
, sizeof(*req
));
1250 status
= be_mcc_notify_wait(adapter
);
1252 struct be_cmd_resp_get_flow_control
*resp
=
1253 embedded_payload(wrb
);
1254 *tx_fc
= le16_to_cpu(resp
->tx_flow_control
);
1255 *rx_fc
= le16_to_cpu(resp
->rx_flow_control
);
1259 spin_unlock_bh(&adapter
->mcc_lock
);
1264 int be_cmd_query_fw_cfg(struct be_adapter
*adapter
, u32
*port_num
, u32
*mode
)
1266 struct be_mcc_wrb
*wrb
;
1267 struct be_cmd_req_query_fw_cfg
*req
;
1270 spin_lock(&adapter
->mbox_lock
);
1272 wrb
= wrb_from_mbox(adapter
);
1273 req
= embedded_payload(wrb
);
1275 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1276 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
);
1278 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1279 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
, sizeof(*req
));
1281 status
= be_mbox_notify_wait(adapter
);
1283 struct be_cmd_resp_query_fw_cfg
*resp
= embedded_payload(wrb
);
1284 *port_num
= le32_to_cpu(resp
->phys_port
);
1285 *mode
= le32_to_cpu(resp
->function_mode
);
1288 spin_unlock(&adapter
->mbox_lock
);
1293 int be_cmd_reset_function(struct be_adapter
*adapter
)
1295 struct be_mcc_wrb
*wrb
;
1296 struct be_cmd_req_hdr
*req
;
1299 spin_lock(&adapter
->mbox_lock
);
1301 wrb
= wrb_from_mbox(adapter
);
1302 req
= embedded_payload(wrb
);
1304 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1305 OPCODE_COMMON_FUNCTION_RESET
);
1307 be_cmd_hdr_prepare(req
, CMD_SUBSYSTEM_COMMON
,
1308 OPCODE_COMMON_FUNCTION_RESET
, sizeof(*req
));
1310 status
= be_mbox_notify_wait(adapter
);
1312 spin_unlock(&adapter
->mbox_lock
);
1317 int be_cmd_set_beacon_state(struct be_adapter
*adapter
, u8 port_num
,
1318 u8 bcn
, u8 sts
, u8 state
)
1320 struct be_mcc_wrb
*wrb
;
1321 struct be_cmd_req_enable_disable_beacon
*req
;
1324 spin_lock_bh(&adapter
->mcc_lock
);
1326 wrb
= wrb_from_mccq(adapter
);
1331 req
= embedded_payload(wrb
);
1333 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1334 OPCODE_COMMON_ENABLE_DISABLE_BEACON
);
1336 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1337 OPCODE_COMMON_ENABLE_DISABLE_BEACON
, sizeof(*req
));
1339 req
->port_num
= port_num
;
1340 req
->beacon_state
= state
;
1341 req
->beacon_duration
= bcn
;
1342 req
->status_duration
= sts
;
1344 status
= be_mcc_notify_wait(adapter
);
1347 spin_unlock_bh(&adapter
->mcc_lock
);
1352 int be_cmd_get_beacon_state(struct be_adapter
*adapter
, u8 port_num
, u32
*state
)
1354 struct be_mcc_wrb
*wrb
;
1355 struct be_cmd_req_get_beacon_state
*req
;
1358 spin_lock_bh(&adapter
->mcc_lock
);
1360 wrb
= wrb_from_mccq(adapter
);
1365 req
= embedded_payload(wrb
);
1367 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1368 OPCODE_COMMON_GET_BEACON_STATE
);
1370 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1371 OPCODE_COMMON_GET_BEACON_STATE
, sizeof(*req
));
1373 req
->port_num
= port_num
;
1375 status
= be_mcc_notify_wait(adapter
);
1377 struct be_cmd_resp_get_beacon_state
*resp
=
1378 embedded_payload(wrb
);
1379 *state
= resp
->beacon_state
;
1383 spin_unlock_bh(&adapter
->mcc_lock
);
1388 int be_cmd_read_port_type(struct be_adapter
*adapter
, u32 port
,
1391 struct be_mcc_wrb
*wrb
;
1392 struct be_cmd_req_port_type
*req
;
1395 spin_lock_bh(&adapter
->mcc_lock
);
1397 wrb
= wrb_from_mccq(adapter
);
1402 req
= embedded_payload(wrb
);
1404 be_wrb_hdr_prepare(wrb
, sizeof(struct be_cmd_resp_port_type
), true, 0,
1405 OPCODE_COMMON_READ_TRANSRECV_DATA
);
1407 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1408 OPCODE_COMMON_READ_TRANSRECV_DATA
, sizeof(*req
));
1410 req
->port
= cpu_to_le32(port
);
1411 req
->page_num
= cpu_to_le32(TR_PAGE_A0
);
1412 status
= be_mcc_notify_wait(adapter
);
1414 struct be_cmd_resp_port_type
*resp
= embedded_payload(wrb
);
1415 *connector
= resp
->data
.connector
;
1419 spin_unlock_bh(&adapter
->mcc_lock
);
1423 int be_cmd_write_flashrom(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
1424 u32 flash_type
, u32 flash_opcode
, u32 buf_size
)
1426 struct be_mcc_wrb
*wrb
;
1427 struct be_cmd_write_flashrom
*req
;
1431 spin_lock_bh(&adapter
->mcc_lock
);
1432 adapter
->flash_status
= 0;
1434 wrb
= wrb_from_mccq(adapter
);
1440 sge
= nonembedded_sgl(wrb
);
1442 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1443 OPCODE_COMMON_WRITE_FLASHROM
);
1444 wrb
->tag1
= CMD_SUBSYSTEM_COMMON
;
1446 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1447 OPCODE_COMMON_WRITE_FLASHROM
, cmd
->size
);
1448 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1449 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1450 sge
->len
= cpu_to_le32(cmd
->size
);
1452 req
->params
.op_type
= cpu_to_le32(flash_type
);
1453 req
->params
.op_code
= cpu_to_le32(flash_opcode
);
1454 req
->params
.data_buf_size
= cpu_to_le32(buf_size
);
1456 be_mcc_notify(adapter
);
1457 spin_unlock_bh(&adapter
->mcc_lock
);
1459 if (!wait_for_completion_timeout(&adapter
->flash_compl
,
1460 msecs_to_jiffies(12000)))
1463 status
= adapter
->flash_status
;
1468 spin_unlock_bh(&adapter
->mcc_lock
);
1472 int be_cmd_get_flash_crc(struct be_adapter
*adapter
, u8
*flashed_crc
,
1475 struct be_mcc_wrb
*wrb
;
1476 struct be_cmd_write_flashrom
*req
;
1479 spin_lock_bh(&adapter
->mcc_lock
);
1481 wrb
= wrb_from_mccq(adapter
);
1486 req
= embedded_payload(wrb
);
1488 be_wrb_hdr_prepare(wrb
, sizeof(*req
)+4, true, 0,
1489 OPCODE_COMMON_READ_FLASHROM
);
1491 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1492 OPCODE_COMMON_READ_FLASHROM
, sizeof(*req
)+4);
1494 req
->params
.op_type
= cpu_to_le32(IMG_TYPE_REDBOOT
);
1495 req
->params
.op_code
= cpu_to_le32(FLASHROM_OPER_REPORT
);
1496 req
->params
.offset
= cpu_to_le32(offset
);
1497 req
->params
.data_buf_size
= cpu_to_le32(0x4);
1499 status
= be_mcc_notify_wait(adapter
);
1501 memcpy(flashed_crc
, req
->params
.data_buf
, 4);
1504 spin_unlock_bh(&adapter
->mcc_lock
);
1508 int be_cmd_enable_magic_wol(struct be_adapter
*adapter
, u8
*mac
,
1509 struct be_dma_mem
*nonemb_cmd
)
1511 struct be_mcc_wrb
*wrb
;
1512 struct be_cmd_req_acpi_wol_magic_config
*req
;
1516 spin_lock_bh(&adapter
->mcc_lock
);
1518 wrb
= wrb_from_mccq(adapter
);
1523 req
= nonemb_cmd
->va
;
1524 sge
= nonembedded_sgl(wrb
);
1526 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1527 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
);
1529 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1530 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
, sizeof(*req
));
1531 memcpy(req
->magic_mac
, mac
, ETH_ALEN
);
1533 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1534 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1535 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1537 status
= be_mcc_notify_wait(adapter
);
1540 spin_unlock_bh(&adapter
->mcc_lock
);
1544 int be_cmd_set_loopback(struct be_adapter
*adapter
, u8 port_num
,
1545 u8 loopback_type
, u8 enable
)
1547 struct be_mcc_wrb
*wrb
;
1548 struct be_cmd_req_set_lmode
*req
;
1551 spin_lock_bh(&adapter
->mcc_lock
);
1553 wrb
= wrb_from_mccq(adapter
);
1559 req
= embedded_payload(wrb
);
1561 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1562 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
);
1564 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1565 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
1568 req
->src_port
= port_num
;
1569 req
->dest_port
= port_num
;
1570 req
->loopback_type
= loopback_type
;
1571 req
->loopback_state
= enable
;
1573 status
= be_mcc_notify_wait(adapter
);
1575 spin_unlock_bh(&adapter
->mcc_lock
);
1579 int be_cmd_loopback_test(struct be_adapter
*adapter
, u32 port_num
,
1580 u32 loopback_type
, u32 pkt_size
, u32 num_pkts
, u64 pattern
)
1582 struct be_mcc_wrb
*wrb
;
1583 struct be_cmd_req_loopback_test
*req
;
1586 spin_lock_bh(&adapter
->mcc_lock
);
1588 wrb
= wrb_from_mccq(adapter
);
1594 req
= embedded_payload(wrb
);
1596 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1597 OPCODE_LOWLEVEL_LOOPBACK_TEST
);
1599 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1600 OPCODE_LOWLEVEL_LOOPBACK_TEST
, sizeof(*req
));
1601 req
->hdr
.timeout
= cpu_to_le32(4);
1603 req
->pattern
= cpu_to_le64(pattern
);
1604 req
->src_port
= cpu_to_le32(port_num
);
1605 req
->dest_port
= cpu_to_le32(port_num
);
1606 req
->pkt_size
= cpu_to_le32(pkt_size
);
1607 req
->num_pkts
= cpu_to_le32(num_pkts
);
1608 req
->loopback_type
= cpu_to_le32(loopback_type
);
1610 status
= be_mcc_notify_wait(adapter
);
1612 struct be_cmd_resp_loopback_test
*resp
= embedded_payload(wrb
);
1613 status
= le32_to_cpu(resp
->status
);
1617 spin_unlock_bh(&adapter
->mcc_lock
);
1621 int be_cmd_ddr_dma_test(struct be_adapter
*adapter
, u64 pattern
,
1622 u32 byte_cnt
, struct be_dma_mem
*cmd
)
1624 struct be_mcc_wrb
*wrb
;
1625 struct be_cmd_req_ddrdma_test
*req
;
1630 spin_lock_bh(&adapter
->mcc_lock
);
1632 wrb
= wrb_from_mccq(adapter
);
1638 sge
= nonembedded_sgl(wrb
);
1639 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1640 OPCODE_LOWLEVEL_HOST_DDR_DMA
);
1641 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1642 OPCODE_LOWLEVEL_HOST_DDR_DMA
, cmd
->size
);
1644 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1645 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1646 sge
->len
= cpu_to_le32(cmd
->size
);
1648 req
->pattern
= cpu_to_le64(pattern
);
1649 req
->byte_count
= cpu_to_le32(byte_cnt
);
1650 for (i
= 0; i
< byte_cnt
; i
++) {
1651 req
->snd_buff
[i
] = (u8
)(pattern
>> (j
*8));
1657 status
= be_mcc_notify_wait(adapter
);
1660 struct be_cmd_resp_ddrdma_test
*resp
;
1662 if ((memcmp(resp
->rcv_buff
, req
->snd_buff
, byte_cnt
) != 0) ||
1669 spin_unlock_bh(&adapter
->mcc_lock
);
1673 int be_cmd_get_seeprom_data(struct be_adapter
*adapter
,
1674 struct be_dma_mem
*nonemb_cmd
)
1676 struct be_mcc_wrb
*wrb
;
1677 struct be_cmd_req_seeprom_read
*req
;
1681 spin_lock_bh(&adapter
->mcc_lock
);
1683 wrb
= wrb_from_mccq(adapter
);
1684 req
= nonemb_cmd
->va
;
1685 sge
= nonembedded_sgl(wrb
);
1687 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1688 OPCODE_COMMON_SEEPROM_READ
);
1690 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1691 OPCODE_COMMON_SEEPROM_READ
, sizeof(*req
));
1693 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1694 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1695 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1697 status
= be_mcc_notify_wait(adapter
);
1699 spin_unlock_bh(&adapter
->mcc_lock
);
1703 int be_cmd_get_phy_info(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
)
1705 struct be_mcc_wrb
*wrb
;
1706 struct be_cmd_req_get_phy_info
*req
;
1710 spin_lock_bh(&adapter
->mcc_lock
);
1712 wrb
= wrb_from_mccq(adapter
);
1719 sge
= nonembedded_sgl(wrb
);
1721 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1722 OPCODE_COMMON_GET_PHY_DETAILS
);
1724 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1725 OPCODE_COMMON_GET_PHY_DETAILS
,
1728 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1729 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1730 sge
->len
= cpu_to_le32(cmd
->size
);
1732 status
= be_mcc_notify_wait(adapter
);
1734 spin_unlock_bh(&adapter
->mcc_lock
);
1738 int be_cmd_set_qos(struct be_adapter
*adapter
, u32 bps
, u32 domain
)
1740 struct be_mcc_wrb
*wrb
;
1741 struct be_cmd_req_set_qos
*req
;
1744 spin_lock_bh(&adapter
->mcc_lock
);
1746 wrb
= wrb_from_mccq(adapter
);
1752 req
= embedded_payload(wrb
);
1754 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1755 OPCODE_COMMON_SET_QOS
);
1757 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1758 OPCODE_COMMON_SET_QOS
, sizeof(*req
));
1760 req
->hdr
.domain
= domain
;
1761 req
->valid_bits
= BE_QOS_BITS_NIC
;
1762 req
->max_bps_nic
= bps
;
1764 status
= be_mcc_notify_wait(adapter
);
1767 spin_unlock_bh(&adapter
->mcc_lock
);