2 * Copyright (C) 2005 - 2009 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
;
28 iowrite32(val
, adapter
->db
+ DB_MCCQ_OFFSET
);
31 /* To check if valid bit is set, check the entire word as we don't know
32 * the endianness of the data (old entry is host endian while a new entry is
34 static inline bool be_mcc_compl_is_new(struct be_mcc_compl
*compl)
36 if (compl->flags
!= 0) {
37 compl->flags
= le32_to_cpu(compl->flags
);
38 BUG_ON((compl->flags
& CQE_FLAGS_VALID_MASK
) == 0);
45 /* Need to reset the entire word that houses the valid bit */
46 static inline void be_mcc_compl_use(struct be_mcc_compl
*compl)
51 static int be_mcc_compl_process(struct be_adapter
*adapter
,
52 struct be_mcc_compl
*compl)
54 u16 compl_status
, extd_status
;
56 /* Just swap the status to host endian; mcc tag is opaquely copied
58 be_dws_le_to_cpu(compl, 4);
60 compl_status
= (compl->status
>> CQE_STATUS_COMPL_SHIFT
) &
61 CQE_STATUS_COMPL_MASK
;
62 if (compl_status
== MCC_STATUS_SUCCESS
) {
63 if (compl->tag0
== OPCODE_ETH_GET_STATISTICS
) {
64 struct be_cmd_resp_get_stats
*resp
=
65 adapter
->stats
.cmd
.va
;
66 be_dws_le_to_cpu(&resp
->hw_stats
,
67 sizeof(resp
->hw_stats
));
68 netdev_stats_update(adapter
);
70 } else if (compl_status
!= MCC_STATUS_NOT_SUPPORTED
) {
71 extd_status
= (compl->status
>> CQE_STATUS_EXTD_SHIFT
) &
73 dev_warn(&adapter
->pdev
->dev
,
74 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
75 compl->tag0
, compl_status
, extd_status
);
80 /* Link state evt is a string of bytes; no need for endian swapping */
81 static void be_async_link_state_process(struct be_adapter
*adapter
,
82 struct be_async_event_link_state
*evt
)
84 be_link_status_update(adapter
,
85 evt
->port_link_status
== ASYNC_EVENT_LINK_UP
);
88 static inline bool is_link_state_evt(u32 trailer
)
90 return (((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
91 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
92 ASYNC_EVENT_CODE_LINK_STATE
);
95 static struct be_mcc_compl
*be_mcc_compl_get(struct be_adapter
*adapter
)
97 struct be_queue_info
*mcc_cq
= &adapter
->mcc_obj
.cq
;
98 struct be_mcc_compl
*compl = queue_tail_node(mcc_cq
);
100 if (be_mcc_compl_is_new(compl)) {
101 queue_tail_inc(mcc_cq
);
107 int be_process_mcc(struct be_adapter
*adapter
)
109 struct be_mcc_compl
*compl;
110 int num
= 0, status
= 0;
112 spin_lock_bh(&adapter
->mcc_cq_lock
);
113 while ((compl = be_mcc_compl_get(adapter
))) {
114 if (compl->flags
& CQE_FLAGS_ASYNC_MASK
) {
115 /* Interpret flags as an async trailer */
116 BUG_ON(!is_link_state_evt(compl->flags
));
118 /* Interpret compl as a async link evt */
119 be_async_link_state_process(adapter
,
120 (struct be_async_event_link_state
*) compl);
121 } else if (compl->flags
& CQE_FLAGS_COMPLETED_MASK
) {
122 status
= be_mcc_compl_process(adapter
, compl);
123 atomic_dec(&adapter
->mcc_obj
.q
.used
);
125 be_mcc_compl_use(compl);
130 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, true, num
);
132 spin_unlock_bh(&adapter
->mcc_cq_lock
);
136 /* Wait till no more pending mcc requests are present */
137 static int be_mcc_wait_compl(struct be_adapter
*adapter
)
139 #define mcc_timeout 120000 /* 12s timeout */
141 for (i
= 0; i
< mcc_timeout
; i
++) {
142 status
= be_process_mcc(adapter
);
146 if (atomic_read(&adapter
->mcc_obj
.q
.used
) == 0)
150 if (i
== mcc_timeout
) {
151 dev_err(&adapter
->pdev
->dev
, "mccq poll timed out\n");
157 /* Notify MCC requests and wait for completion */
158 static int be_mcc_notify_wait(struct be_adapter
*adapter
)
160 be_mcc_notify(adapter
);
161 return be_mcc_wait_compl(adapter
);
164 static int be_mbox_db_ready_wait(struct be_adapter
*adapter
, void __iomem
*db
)
166 int cnt
= 0, wait
= 5;
170 ready
= ioread32(db
) & MPU_MAILBOX_DB_RDY_MASK
;
175 dev_err(&adapter
->pdev
->dev
, "mbox poll timed out\n");
189 * Insert the mailbox address into the doorbell in two steps
190 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
192 static int be_mbox_notify_wait(struct be_adapter
*adapter
)
196 void __iomem
*db
= adapter
->db
+ MPU_MAILBOX_DB_OFFSET
;
197 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
198 struct be_mcc_mailbox
*mbox
= mbox_mem
->va
;
199 struct be_mcc_compl
*compl = &mbox
->compl;
201 val
|= MPU_MAILBOX_DB_HI_MASK
;
202 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
203 val
|= (upper_32_bits(mbox_mem
->dma
) >> 2) << 2;
206 /* wait for ready to be set */
207 status
= be_mbox_db_ready_wait(adapter
, db
);
212 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
213 val
|= (u32
)(mbox_mem
->dma
>> 4) << 2;
216 status
= be_mbox_db_ready_wait(adapter
, db
);
220 /* A cq entry has been made now */
221 if (be_mcc_compl_is_new(compl)) {
222 status
= be_mcc_compl_process(adapter
, &mbox
->compl);
223 be_mcc_compl_use(compl);
227 dev_err(&adapter
->pdev
->dev
, "invalid mailbox completion\n");
233 static int be_POST_stage_get(struct be_adapter
*adapter
, u16
*stage
)
235 u32 sem
= ioread32(adapter
->csr
+ MPU_EP_SEMAPHORE_OFFSET
);
237 *stage
= sem
& EP_SEMAPHORE_POST_STAGE_MASK
;
238 if ((sem
>> EP_SEMAPHORE_POST_ERR_SHIFT
) & EP_SEMAPHORE_POST_ERR_MASK
)
244 int be_cmd_POST(struct be_adapter
*adapter
)
247 int status
, timeout
= 0;
250 status
= be_POST_stage_get(adapter
, &stage
);
252 dev_err(&adapter
->pdev
->dev
, "POST error; stage=0x%x\n",
255 } else if (stage
!= POST_STAGE_ARMFW_RDY
) {
256 set_current_state(TASK_INTERRUPTIBLE
);
257 schedule_timeout(2 * HZ
);
262 } while (timeout
< 20);
264 dev_err(&adapter
->pdev
->dev
, "POST timeout; stage=0x%x\n", stage
);
268 static inline void *embedded_payload(struct be_mcc_wrb
*wrb
)
270 return wrb
->payload
.embedded_payload
;
273 static inline struct be_sge
*nonembedded_sgl(struct be_mcc_wrb
*wrb
)
275 return &wrb
->payload
.sgl
[0];
278 /* Don't touch the hdr after it's prepared */
279 static void be_wrb_hdr_prepare(struct be_mcc_wrb
*wrb
, int payload_len
,
280 bool embedded
, u8 sge_cnt
, u32 opcode
)
283 wrb
->embedded
|= MCC_WRB_EMBEDDED_MASK
;
285 wrb
->embedded
|= (sge_cnt
& MCC_WRB_SGE_CNT_MASK
) <<
286 MCC_WRB_SGE_CNT_SHIFT
;
287 wrb
->payload_length
= payload_len
;
289 be_dws_cpu_to_le(wrb
, 8);
292 /* Don't touch the hdr after it's prepared */
293 static void be_cmd_hdr_prepare(struct be_cmd_req_hdr
*req_hdr
,
294 u8 subsystem
, u8 opcode
, int cmd_len
)
296 req_hdr
->opcode
= opcode
;
297 req_hdr
->subsystem
= subsystem
;
298 req_hdr
->request_length
= cpu_to_le32(cmd_len
- sizeof(*req_hdr
));
301 static void be_cmd_page_addrs_prepare(struct phys_addr
*pages
, u32 max_pages
,
302 struct be_dma_mem
*mem
)
304 int i
, buf_pages
= min(PAGES_4K_SPANNED(mem
->va
, mem
->size
), max_pages
);
305 u64 dma
= (u64
)mem
->dma
;
307 for (i
= 0; i
< buf_pages
; i
++) {
308 pages
[i
].lo
= cpu_to_le32(dma
& 0xFFFFFFFF);
309 pages
[i
].hi
= cpu_to_le32(upper_32_bits(dma
));
314 /* Converts interrupt delay in microseconds to multiplier value */
315 static u32
eq_delay_to_mult(u32 usec_delay
)
317 #define MAX_INTR_RATE 651042
318 const u32 round
= 10;
324 u32 interrupt_rate
= 1000000 / usec_delay
;
325 /* Max delay, corresponding to the lowest interrupt rate */
326 if (interrupt_rate
== 0)
329 multiplier
= (MAX_INTR_RATE
- interrupt_rate
) * round
;
330 multiplier
/= interrupt_rate
;
331 /* Round the multiplier to the closest value.*/
332 multiplier
= (multiplier
+ round
/2) / round
;
333 multiplier
= min(multiplier
, (u32
)1023);
339 static inline struct be_mcc_wrb
*wrb_from_mbox(struct be_adapter
*adapter
)
341 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
342 struct be_mcc_wrb
*wrb
343 = &((struct be_mcc_mailbox
*)(mbox_mem
->va
))->wrb
;
344 memset(wrb
, 0, sizeof(*wrb
));
348 static struct be_mcc_wrb
*wrb_from_mccq(struct be_adapter
*adapter
)
350 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
351 struct be_mcc_wrb
*wrb
;
353 if (atomic_read(&mccq
->used
) >= mccq
->len
) {
354 dev_err(&adapter
->pdev
->dev
, "Out of MCCQ wrbs\n");
358 wrb
= queue_head_node(mccq
);
359 queue_head_inc(mccq
);
360 atomic_inc(&mccq
->used
);
361 memset(wrb
, 0, sizeof(*wrb
));
365 /* Tell fw we're about to start firing cmds by writing a
366 * special pattern across the wrb hdr; uses mbox
368 int be_cmd_fw_init(struct be_adapter
*adapter
)
373 spin_lock(&adapter
->mbox_lock
);
375 wrb
= (u8
*)wrb_from_mbox(adapter
);
385 status
= be_mbox_notify_wait(adapter
);
387 spin_unlock(&adapter
->mbox_lock
);
391 /* Tell fw we're done with firing cmds by writing a
392 * special pattern across the wrb hdr; uses mbox
394 int be_cmd_fw_clean(struct be_adapter
*adapter
)
399 spin_lock(&adapter
->mbox_lock
);
401 wrb
= (u8
*)wrb_from_mbox(adapter
);
411 status
= be_mbox_notify_wait(adapter
);
413 spin_unlock(&adapter
->mbox_lock
);
416 int be_cmd_eq_create(struct be_adapter
*adapter
,
417 struct be_queue_info
*eq
, int eq_delay
)
419 struct be_mcc_wrb
*wrb
;
420 struct be_cmd_req_eq_create
*req
;
421 struct be_dma_mem
*q_mem
= &eq
->dma_mem
;
424 spin_lock(&adapter
->mbox_lock
);
426 wrb
= wrb_from_mbox(adapter
);
427 req
= embedded_payload(wrb
);
429 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_COMMON_EQ_CREATE
);
431 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
432 OPCODE_COMMON_EQ_CREATE
, sizeof(*req
));
434 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
436 AMAP_SET_BITS(struct amap_eq_context
, func
, req
->context
,
437 be_pci_func(adapter
));
438 AMAP_SET_BITS(struct amap_eq_context
, valid
, req
->context
, 1);
440 AMAP_SET_BITS(struct amap_eq_context
, size
, req
->context
, 0);
441 AMAP_SET_BITS(struct amap_eq_context
, count
, req
->context
,
442 __ilog2_u32(eq
->len
/256));
443 AMAP_SET_BITS(struct amap_eq_context
, delaymult
, req
->context
,
444 eq_delay_to_mult(eq_delay
));
445 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
447 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
449 status
= be_mbox_notify_wait(adapter
);
451 struct be_cmd_resp_eq_create
*resp
= embedded_payload(wrb
);
452 eq
->id
= le16_to_cpu(resp
->eq_id
);
456 spin_unlock(&adapter
->mbox_lock
);
461 int be_cmd_mac_addr_query(struct be_adapter
*adapter
, u8
*mac_addr
,
462 u8 type
, bool permanent
, u32 if_handle
)
464 struct be_mcc_wrb
*wrb
;
465 struct be_cmd_req_mac_query
*req
;
468 spin_lock(&adapter
->mbox_lock
);
470 wrb
= wrb_from_mbox(adapter
);
471 req
= embedded_payload(wrb
);
473 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
474 OPCODE_COMMON_NTWK_MAC_QUERY
);
476 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
477 OPCODE_COMMON_NTWK_MAC_QUERY
, sizeof(*req
));
483 req
->if_id
= cpu_to_le16((u16
) if_handle
);
487 status
= be_mbox_notify_wait(adapter
);
489 struct be_cmd_resp_mac_query
*resp
= embedded_payload(wrb
);
490 memcpy(mac_addr
, resp
->mac
.addr
, ETH_ALEN
);
493 spin_unlock(&adapter
->mbox_lock
);
497 /* Uses synchronous MCCQ */
498 int be_cmd_pmac_add(struct be_adapter
*adapter
, u8
*mac_addr
,
499 u32 if_id
, u32
*pmac_id
)
501 struct be_mcc_wrb
*wrb
;
502 struct be_cmd_req_pmac_add
*req
;
505 spin_lock_bh(&adapter
->mcc_lock
);
507 wrb
= wrb_from_mccq(adapter
);
512 req
= embedded_payload(wrb
);
514 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
515 OPCODE_COMMON_NTWK_PMAC_ADD
);
517 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
518 OPCODE_COMMON_NTWK_PMAC_ADD
, sizeof(*req
));
520 req
->if_id
= cpu_to_le32(if_id
);
521 memcpy(req
->mac_address
, mac_addr
, ETH_ALEN
);
523 status
= be_mcc_notify_wait(adapter
);
525 struct be_cmd_resp_pmac_add
*resp
= embedded_payload(wrb
);
526 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
530 spin_unlock_bh(&adapter
->mcc_lock
);
534 /* Uses synchronous MCCQ */
535 int be_cmd_pmac_del(struct be_adapter
*adapter
, u32 if_id
, u32 pmac_id
)
537 struct be_mcc_wrb
*wrb
;
538 struct be_cmd_req_pmac_del
*req
;
541 spin_lock_bh(&adapter
->mcc_lock
);
543 wrb
= wrb_from_mccq(adapter
);
548 req
= embedded_payload(wrb
);
550 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
551 OPCODE_COMMON_NTWK_PMAC_DEL
);
553 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
554 OPCODE_COMMON_NTWK_PMAC_DEL
, sizeof(*req
));
556 req
->if_id
= cpu_to_le32(if_id
);
557 req
->pmac_id
= cpu_to_le32(pmac_id
);
559 status
= be_mcc_notify_wait(adapter
);
562 spin_unlock_bh(&adapter
->mcc_lock
);
567 int be_cmd_cq_create(struct be_adapter
*adapter
,
568 struct be_queue_info
*cq
, struct be_queue_info
*eq
,
569 bool sol_evts
, bool no_delay
, int coalesce_wm
)
571 struct be_mcc_wrb
*wrb
;
572 struct be_cmd_req_cq_create
*req
;
573 struct be_dma_mem
*q_mem
= &cq
->dma_mem
;
577 spin_lock(&adapter
->mbox_lock
);
579 wrb
= wrb_from_mbox(adapter
);
580 req
= embedded_payload(wrb
);
581 ctxt
= &req
->context
;
583 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
584 OPCODE_COMMON_CQ_CREATE
);
586 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
587 OPCODE_COMMON_CQ_CREATE
, sizeof(*req
));
589 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
591 AMAP_SET_BITS(struct amap_cq_context
, coalescwm
, ctxt
, coalesce_wm
);
592 AMAP_SET_BITS(struct amap_cq_context
, nodelay
, ctxt
, no_delay
);
593 AMAP_SET_BITS(struct amap_cq_context
, count
, ctxt
,
594 __ilog2_u32(cq
->len
/256));
595 AMAP_SET_BITS(struct amap_cq_context
, valid
, ctxt
, 1);
596 AMAP_SET_BITS(struct amap_cq_context
, solevent
, ctxt
, sol_evts
);
597 AMAP_SET_BITS(struct amap_cq_context
, eventable
, ctxt
, 1);
598 AMAP_SET_BITS(struct amap_cq_context
, eqid
, ctxt
, eq
->id
);
599 AMAP_SET_BITS(struct amap_cq_context
, armed
, ctxt
, 1);
600 AMAP_SET_BITS(struct amap_cq_context
, func
, ctxt
, be_pci_func(adapter
));
601 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
603 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
605 status
= be_mbox_notify_wait(adapter
);
607 struct be_cmd_resp_cq_create
*resp
= embedded_payload(wrb
);
608 cq
->id
= le16_to_cpu(resp
->cq_id
);
612 spin_unlock(&adapter
->mbox_lock
);
617 static u32
be_encoded_q_len(int q_len
)
619 u32 len_encoded
= fls(q_len
); /* log2(len) + 1 */
620 if (len_encoded
== 16)
625 int be_cmd_mccq_create(struct be_adapter
*adapter
,
626 struct be_queue_info
*mccq
,
627 struct be_queue_info
*cq
)
629 struct be_mcc_wrb
*wrb
;
630 struct be_cmd_req_mcc_create
*req
;
631 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
635 spin_lock(&adapter
->mbox_lock
);
637 wrb
= wrb_from_mbox(adapter
);
638 req
= embedded_payload(wrb
);
639 ctxt
= &req
->context
;
641 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
642 OPCODE_COMMON_MCC_CREATE
);
644 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
645 OPCODE_COMMON_MCC_CREATE
, sizeof(*req
));
647 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
649 AMAP_SET_BITS(struct amap_mcc_context
, fid
, ctxt
, be_pci_func(adapter
));
650 AMAP_SET_BITS(struct amap_mcc_context
, valid
, ctxt
, 1);
651 AMAP_SET_BITS(struct amap_mcc_context
, ring_size
, ctxt
,
652 be_encoded_q_len(mccq
->len
));
653 AMAP_SET_BITS(struct amap_mcc_context
, cq_id
, ctxt
, cq
->id
);
655 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
657 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
659 status
= be_mbox_notify_wait(adapter
);
661 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
662 mccq
->id
= le16_to_cpu(resp
->id
);
663 mccq
->created
= true;
665 spin_unlock(&adapter
->mbox_lock
);
670 int be_cmd_txq_create(struct be_adapter
*adapter
,
671 struct be_queue_info
*txq
,
672 struct be_queue_info
*cq
)
674 struct be_mcc_wrb
*wrb
;
675 struct be_cmd_req_eth_tx_create
*req
;
676 struct be_dma_mem
*q_mem
= &txq
->dma_mem
;
680 spin_lock(&adapter
->mbox_lock
);
682 wrb
= wrb_from_mbox(adapter
);
683 req
= embedded_payload(wrb
);
684 ctxt
= &req
->context
;
686 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
687 OPCODE_ETH_TX_CREATE
);
689 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_TX_CREATE
,
692 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
693 req
->ulp_num
= BE_ULP1_NUM
;
694 req
->type
= BE_ETH_TX_RING_TYPE_STANDARD
;
696 AMAP_SET_BITS(struct amap_tx_context
, tx_ring_size
, ctxt
,
697 be_encoded_q_len(txq
->len
));
698 AMAP_SET_BITS(struct amap_tx_context
, pci_func_id
, ctxt
,
699 be_pci_func(adapter
));
700 AMAP_SET_BITS(struct amap_tx_context
, ctx_valid
, ctxt
, 1);
701 AMAP_SET_BITS(struct amap_tx_context
, cq_id_send
, ctxt
, cq
->id
);
703 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
705 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
707 status
= be_mbox_notify_wait(adapter
);
709 struct be_cmd_resp_eth_tx_create
*resp
= embedded_payload(wrb
);
710 txq
->id
= le16_to_cpu(resp
->cid
);
714 spin_unlock(&adapter
->mbox_lock
);
720 int be_cmd_rxq_create(struct be_adapter
*adapter
,
721 struct be_queue_info
*rxq
, u16 cq_id
, u16 frag_size
,
722 u16 max_frame_size
, u32 if_id
, u32 rss
)
724 struct be_mcc_wrb
*wrb
;
725 struct be_cmd_req_eth_rx_create
*req
;
726 struct be_dma_mem
*q_mem
= &rxq
->dma_mem
;
729 spin_lock(&adapter
->mbox_lock
);
731 wrb
= wrb_from_mbox(adapter
);
732 req
= embedded_payload(wrb
);
734 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
735 OPCODE_ETH_RX_CREATE
);
737 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_RX_CREATE
,
740 req
->cq_id
= cpu_to_le16(cq_id
);
741 req
->frag_size
= fls(frag_size
) - 1;
743 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
744 req
->interface_id
= cpu_to_le32(if_id
);
745 req
->max_frame_size
= cpu_to_le16(max_frame_size
);
746 req
->rss_queue
= cpu_to_le32(rss
);
748 status
= be_mbox_notify_wait(adapter
);
750 struct be_cmd_resp_eth_rx_create
*resp
= embedded_payload(wrb
);
751 rxq
->id
= le16_to_cpu(resp
->id
);
755 spin_unlock(&adapter
->mbox_lock
);
760 /* Generic destroyer function for all types of queues
763 int be_cmd_q_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
,
766 struct be_mcc_wrb
*wrb
;
767 struct be_cmd_req_q_destroy
*req
;
768 u8 subsys
= 0, opcode
= 0;
771 spin_lock(&adapter
->mbox_lock
);
773 wrb
= wrb_from_mbox(adapter
);
774 req
= embedded_payload(wrb
);
776 switch (queue_type
) {
778 subsys
= CMD_SUBSYSTEM_COMMON
;
779 opcode
= OPCODE_COMMON_EQ_DESTROY
;
782 subsys
= CMD_SUBSYSTEM_COMMON
;
783 opcode
= OPCODE_COMMON_CQ_DESTROY
;
786 subsys
= CMD_SUBSYSTEM_ETH
;
787 opcode
= OPCODE_ETH_TX_DESTROY
;
790 subsys
= CMD_SUBSYSTEM_ETH
;
791 opcode
= OPCODE_ETH_RX_DESTROY
;
794 subsys
= CMD_SUBSYSTEM_COMMON
;
795 opcode
= OPCODE_COMMON_MCC_DESTROY
;
801 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, opcode
);
803 be_cmd_hdr_prepare(&req
->hdr
, subsys
, opcode
, sizeof(*req
));
804 req
->id
= cpu_to_le16(q
->id
);
806 status
= be_mbox_notify_wait(adapter
);
808 spin_unlock(&adapter
->mbox_lock
);
813 /* Create an rx filtering policy configuration on an i/f
816 int be_cmd_if_create(struct be_adapter
*adapter
, u32 cap_flags
, u32 en_flags
,
817 u8
*mac
, bool pmac_invalid
, u32
*if_handle
, u32
*pmac_id
)
819 struct be_mcc_wrb
*wrb
;
820 struct be_cmd_req_if_create
*req
;
823 spin_lock(&adapter
->mbox_lock
);
825 wrb
= wrb_from_mbox(adapter
);
826 req
= embedded_payload(wrb
);
828 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
829 OPCODE_COMMON_NTWK_INTERFACE_CREATE
);
831 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
832 OPCODE_COMMON_NTWK_INTERFACE_CREATE
, sizeof(*req
));
834 req
->capability_flags
= cpu_to_le32(cap_flags
);
835 req
->enable_flags
= cpu_to_le32(en_flags
);
836 req
->pmac_invalid
= pmac_invalid
;
838 memcpy(req
->mac_addr
, mac
, ETH_ALEN
);
840 status
= be_mbox_notify_wait(adapter
);
842 struct be_cmd_resp_if_create
*resp
= embedded_payload(wrb
);
843 *if_handle
= le32_to_cpu(resp
->interface_id
);
845 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
848 spin_unlock(&adapter
->mbox_lock
);
853 int be_cmd_if_destroy(struct be_adapter
*adapter
, u32 interface_id
)
855 struct be_mcc_wrb
*wrb
;
856 struct be_cmd_req_if_destroy
*req
;
859 spin_lock(&adapter
->mbox_lock
);
861 wrb
= wrb_from_mbox(adapter
);
862 req
= embedded_payload(wrb
);
864 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
865 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
);
867 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
868 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
, sizeof(*req
));
870 req
->interface_id
= cpu_to_le32(interface_id
);
872 status
= be_mbox_notify_wait(adapter
);
874 spin_unlock(&adapter
->mbox_lock
);
879 /* Get stats is a non embedded command: the request is not embedded inside
880 * WRB but is a separate dma memory block
881 * Uses asynchronous MCC
883 int be_cmd_get_stats(struct be_adapter
*adapter
, struct be_dma_mem
*nonemb_cmd
)
885 struct be_mcc_wrb
*wrb
;
886 struct be_cmd_req_get_stats
*req
;
890 spin_lock_bh(&adapter
->mcc_lock
);
892 wrb
= wrb_from_mccq(adapter
);
897 req
= nonemb_cmd
->va
;
898 sge
= nonembedded_sgl(wrb
);
900 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
901 OPCODE_ETH_GET_STATISTICS
);
903 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
904 OPCODE_ETH_GET_STATISTICS
, sizeof(*req
));
905 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
906 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
907 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
909 be_mcc_notify(adapter
);
912 spin_unlock_bh(&adapter
->mcc_lock
);
916 /* Uses synchronous mcc */
917 int be_cmd_link_status_query(struct be_adapter
*adapter
,
918 bool *link_up
, u8
*mac_speed
, u16
*link_speed
)
920 struct be_mcc_wrb
*wrb
;
921 struct be_cmd_req_link_status
*req
;
924 spin_lock_bh(&adapter
->mcc_lock
);
926 wrb
= wrb_from_mccq(adapter
);
931 req
= embedded_payload(wrb
);
935 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
936 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
);
938 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
939 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
, sizeof(*req
));
941 status
= be_mcc_notify_wait(adapter
);
943 struct be_cmd_resp_link_status
*resp
= embedded_payload(wrb
);
944 if (resp
->mac_speed
!= PHY_LINK_SPEED_ZERO
) {
946 *link_speed
= le16_to_cpu(resp
->link_speed
);
947 *mac_speed
= resp
->mac_speed
;
952 spin_unlock_bh(&adapter
->mcc_lock
);
957 int be_cmd_get_fw_ver(struct be_adapter
*adapter
, char *fw_ver
)
959 struct be_mcc_wrb
*wrb
;
960 struct be_cmd_req_get_fw_version
*req
;
963 spin_lock(&adapter
->mbox_lock
);
965 wrb
= wrb_from_mbox(adapter
);
966 req
= embedded_payload(wrb
);
968 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
969 OPCODE_COMMON_GET_FW_VERSION
);
971 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
972 OPCODE_COMMON_GET_FW_VERSION
, sizeof(*req
));
974 status
= be_mbox_notify_wait(adapter
);
976 struct be_cmd_resp_get_fw_version
*resp
= embedded_payload(wrb
);
977 strncpy(fw_ver
, resp
->firmware_version_string
, FW_VER_LEN
);
980 spin_unlock(&adapter
->mbox_lock
);
984 /* set the EQ delay interval of an EQ to specified value
987 int be_cmd_modify_eqd(struct be_adapter
*adapter
, u32 eq_id
, u32 eqd
)
989 struct be_mcc_wrb
*wrb
;
990 struct be_cmd_req_modify_eq_delay
*req
;
993 spin_lock_bh(&adapter
->mcc_lock
);
995 wrb
= wrb_from_mccq(adapter
);
1000 req
= embedded_payload(wrb
);
1002 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1003 OPCODE_COMMON_MODIFY_EQ_DELAY
);
1005 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1006 OPCODE_COMMON_MODIFY_EQ_DELAY
, sizeof(*req
));
1008 req
->num_eq
= cpu_to_le32(1);
1009 req
->delay
[0].eq_id
= cpu_to_le32(eq_id
);
1010 req
->delay
[0].phase
= 0;
1011 req
->delay
[0].delay_multiplier
= cpu_to_le32(eqd
);
1013 be_mcc_notify(adapter
);
1016 spin_unlock_bh(&adapter
->mcc_lock
);
1020 /* Uses sycnhronous mcc */
1021 int be_cmd_vlan_config(struct be_adapter
*adapter
, u32 if_id
, u16
*vtag_array
,
1022 u32 num
, bool untagged
, bool promiscuous
)
1024 struct be_mcc_wrb
*wrb
;
1025 struct be_cmd_req_vlan_config
*req
;
1028 spin_lock_bh(&adapter
->mcc_lock
);
1030 wrb
= wrb_from_mccq(adapter
);
1035 req
= embedded_payload(wrb
);
1037 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1038 OPCODE_COMMON_NTWK_VLAN_CONFIG
);
1040 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1041 OPCODE_COMMON_NTWK_VLAN_CONFIG
, sizeof(*req
));
1043 req
->interface_id
= if_id
;
1044 req
->promiscuous
= promiscuous
;
1045 req
->untagged
= untagged
;
1046 req
->num_vlan
= num
;
1048 memcpy(req
->normal_vlan
, vtag_array
,
1049 req
->num_vlan
* sizeof(vtag_array
[0]));
1052 status
= be_mcc_notify_wait(adapter
);
1055 spin_unlock_bh(&adapter
->mcc_lock
);
1059 /* Uses MCC for this command as it may be called in BH context
1060 * Uses synchronous mcc
1062 int be_cmd_promiscuous_config(struct be_adapter
*adapter
, u8 port_num
, bool en
)
1064 struct be_mcc_wrb
*wrb
;
1065 struct be_cmd_req_promiscuous_config
*req
;
1068 spin_lock_bh(&adapter
->mcc_lock
);
1070 wrb
= wrb_from_mccq(adapter
);
1075 req
= embedded_payload(wrb
);
1077 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_ETH_PROMISCUOUS
);
1079 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1080 OPCODE_ETH_PROMISCUOUS
, sizeof(*req
));
1083 req
->port1_promiscuous
= en
;
1085 req
->port0_promiscuous
= en
;
1087 status
= be_mcc_notify_wait(adapter
);
1090 spin_unlock_bh(&adapter
->mcc_lock
);
1095 * Uses MCC for this command as it may be called in BH context
1096 * (mc == NULL) => multicast promiscous
1098 int be_cmd_multicast_set(struct be_adapter
*adapter
, u32 if_id
,
1099 struct dev_mc_list
*mc_list
, u32 mc_count
,
1100 struct be_dma_mem
*mem
)
1102 struct be_mcc_wrb
*wrb
;
1103 struct be_cmd_req_mcast_mac_config
*req
= mem
->va
;
1107 spin_lock_bh(&adapter
->mcc_lock
);
1109 wrb
= wrb_from_mccq(adapter
);
1114 sge
= nonembedded_sgl(wrb
);
1115 memset(req
, 0, sizeof(*req
));
1117 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1118 OPCODE_COMMON_NTWK_MULTICAST_SET
);
1119 sge
->pa_hi
= cpu_to_le32(upper_32_bits(mem
->dma
));
1120 sge
->pa_lo
= cpu_to_le32(mem
->dma
& 0xFFFFFFFF);
1121 sge
->len
= cpu_to_le32(mem
->size
);
1123 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1124 OPCODE_COMMON_NTWK_MULTICAST_SET
, sizeof(*req
));
1126 req
->interface_id
= if_id
;
1129 struct dev_mc_list
*mc
;
1131 req
->num_mac
= cpu_to_le16(mc_count
);
1133 for (mc
= mc_list
, i
= 0; mc
; mc
= mc
->next
, i
++)
1134 memcpy(req
->mac
[i
].byte
, mc
->dmi_addr
, ETH_ALEN
);
1136 req
->promiscuous
= 1;
1139 status
= be_mcc_notify_wait(adapter
);
1142 spin_unlock_bh(&adapter
->mcc_lock
);
1146 /* Uses synchrounous mcc */
1147 int be_cmd_set_flow_control(struct be_adapter
*adapter
, u32 tx_fc
, u32 rx_fc
)
1149 struct be_mcc_wrb
*wrb
;
1150 struct be_cmd_req_set_flow_control
*req
;
1153 spin_lock_bh(&adapter
->mcc_lock
);
1155 wrb
= wrb_from_mccq(adapter
);
1160 req
= embedded_payload(wrb
);
1162 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1163 OPCODE_COMMON_SET_FLOW_CONTROL
);
1165 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1166 OPCODE_COMMON_SET_FLOW_CONTROL
, sizeof(*req
));
1168 req
->tx_flow_control
= cpu_to_le16((u16
)tx_fc
);
1169 req
->rx_flow_control
= cpu_to_le16((u16
)rx_fc
);
1171 status
= be_mcc_notify_wait(adapter
);
1174 spin_unlock_bh(&adapter
->mcc_lock
);
1179 int be_cmd_get_flow_control(struct be_adapter
*adapter
, u32
*tx_fc
, u32
*rx_fc
)
1181 struct be_mcc_wrb
*wrb
;
1182 struct be_cmd_req_get_flow_control
*req
;
1185 spin_lock_bh(&adapter
->mcc_lock
);
1187 wrb
= wrb_from_mccq(adapter
);
1192 req
= embedded_payload(wrb
);
1194 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1195 OPCODE_COMMON_GET_FLOW_CONTROL
);
1197 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1198 OPCODE_COMMON_GET_FLOW_CONTROL
, sizeof(*req
));
1200 status
= be_mcc_notify_wait(adapter
);
1202 struct be_cmd_resp_get_flow_control
*resp
=
1203 embedded_payload(wrb
);
1204 *tx_fc
= le16_to_cpu(resp
->tx_flow_control
);
1205 *rx_fc
= le16_to_cpu(resp
->rx_flow_control
);
1209 spin_unlock_bh(&adapter
->mcc_lock
);
1214 int be_cmd_query_fw_cfg(struct be_adapter
*adapter
, u32
*port_num
, u32
*cap
)
1216 struct be_mcc_wrb
*wrb
;
1217 struct be_cmd_req_query_fw_cfg
*req
;
1220 spin_lock(&adapter
->mbox_lock
);
1222 wrb
= wrb_from_mbox(adapter
);
1223 req
= embedded_payload(wrb
);
1225 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1226 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
);
1228 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1229 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
, sizeof(*req
));
1231 status
= be_mbox_notify_wait(adapter
);
1233 struct be_cmd_resp_query_fw_cfg
*resp
= embedded_payload(wrb
);
1234 *port_num
= le32_to_cpu(resp
->phys_port
);
1235 *cap
= le32_to_cpu(resp
->function_cap
);
1238 spin_unlock(&adapter
->mbox_lock
);
1243 int be_cmd_reset_function(struct be_adapter
*adapter
)
1245 struct be_mcc_wrb
*wrb
;
1246 struct be_cmd_req_hdr
*req
;
1249 spin_lock(&adapter
->mbox_lock
);
1251 wrb
= wrb_from_mbox(adapter
);
1252 req
= embedded_payload(wrb
);
1254 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1255 OPCODE_COMMON_FUNCTION_RESET
);
1257 be_cmd_hdr_prepare(req
, CMD_SUBSYSTEM_COMMON
,
1258 OPCODE_COMMON_FUNCTION_RESET
, sizeof(*req
));
1260 status
= be_mbox_notify_wait(adapter
);
1262 spin_unlock(&adapter
->mbox_lock
);
1267 int be_cmd_set_beacon_state(struct be_adapter
*adapter
, u8 port_num
,
1268 u8 bcn
, u8 sts
, u8 state
)
1270 struct be_mcc_wrb
*wrb
;
1271 struct be_cmd_req_enable_disable_beacon
*req
;
1274 spin_lock_bh(&adapter
->mcc_lock
);
1276 wrb
= wrb_from_mccq(adapter
);
1281 req
= embedded_payload(wrb
);
1283 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1284 OPCODE_COMMON_ENABLE_DISABLE_BEACON
);
1286 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1287 OPCODE_COMMON_ENABLE_DISABLE_BEACON
, sizeof(*req
));
1289 req
->port_num
= port_num
;
1290 req
->beacon_state
= state
;
1291 req
->beacon_duration
= bcn
;
1292 req
->status_duration
= sts
;
1294 status
= be_mcc_notify_wait(adapter
);
1297 spin_unlock_bh(&adapter
->mcc_lock
);
1302 int be_cmd_get_beacon_state(struct be_adapter
*adapter
, u8 port_num
, u32
*state
)
1304 struct be_mcc_wrb
*wrb
;
1305 struct be_cmd_req_get_beacon_state
*req
;
1308 spin_lock_bh(&adapter
->mcc_lock
);
1310 wrb
= wrb_from_mccq(adapter
);
1315 req
= embedded_payload(wrb
);
1317 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1318 OPCODE_COMMON_GET_BEACON_STATE
);
1320 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1321 OPCODE_COMMON_GET_BEACON_STATE
, sizeof(*req
));
1323 req
->port_num
= port_num
;
1325 status
= be_mcc_notify_wait(adapter
);
1327 struct be_cmd_resp_get_beacon_state
*resp
=
1328 embedded_payload(wrb
);
1329 *state
= resp
->beacon_state
;
1333 spin_unlock_bh(&adapter
->mcc_lock
);
1338 int be_cmd_read_port_type(struct be_adapter
*adapter
, u32 port
,
1341 struct be_mcc_wrb
*wrb
;
1342 struct be_cmd_req_port_type
*req
;
1345 spin_lock_bh(&adapter
->mcc_lock
);
1347 wrb
= wrb_from_mccq(adapter
);
1352 req
= embedded_payload(wrb
);
1354 be_wrb_hdr_prepare(wrb
, sizeof(struct be_cmd_resp_port_type
), true, 0,
1355 OPCODE_COMMON_READ_TRANSRECV_DATA
);
1357 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1358 OPCODE_COMMON_READ_TRANSRECV_DATA
, sizeof(*req
));
1360 req
->port
= cpu_to_le32(port
);
1361 req
->page_num
= cpu_to_le32(TR_PAGE_A0
);
1362 status
= be_mcc_notify_wait(adapter
);
1364 struct be_cmd_resp_port_type
*resp
= embedded_payload(wrb
);
1365 *connector
= resp
->data
.connector
;
1369 spin_unlock_bh(&adapter
->mcc_lock
);
1373 int be_cmd_write_flashrom(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
1374 u32 flash_type
, u32 flash_opcode
, u32 buf_size
)
1376 struct be_mcc_wrb
*wrb
;
1377 struct be_cmd_write_flashrom
*req
= cmd
->va
;
1381 spin_lock_bh(&adapter
->mcc_lock
);
1383 wrb
= wrb_from_mccq(adapter
);
1389 sge
= nonembedded_sgl(wrb
);
1391 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1392 OPCODE_COMMON_WRITE_FLASHROM
);
1394 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1395 OPCODE_COMMON_WRITE_FLASHROM
, cmd
->size
);
1396 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1397 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1398 sge
->len
= cpu_to_le32(cmd
->size
);
1400 req
->params
.op_type
= cpu_to_le32(flash_type
);
1401 req
->params
.op_code
= cpu_to_le32(flash_opcode
);
1402 req
->params
.data_buf_size
= cpu_to_le32(buf_size
);
1404 status
= be_mcc_notify_wait(adapter
);
1407 spin_unlock_bh(&adapter
->mcc_lock
);
1411 int be_cmd_get_flash_crc(struct be_adapter
*adapter
, u8
*flashed_crc
)
1413 struct be_mcc_wrb
*wrb
;
1414 struct be_cmd_write_flashrom
*req
;
1417 spin_lock_bh(&adapter
->mcc_lock
);
1419 wrb
= wrb_from_mccq(adapter
);
1424 req
= embedded_payload(wrb
);
1426 be_wrb_hdr_prepare(wrb
, sizeof(*req
)+4, true, 0,
1427 OPCODE_COMMON_READ_FLASHROM
);
1429 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1430 OPCODE_COMMON_READ_FLASHROM
, sizeof(*req
)+4);
1432 req
->params
.op_type
= cpu_to_le32(FLASHROM_TYPE_REDBOOT
);
1433 req
->params
.op_code
= cpu_to_le32(FLASHROM_OPER_REPORT
);
1434 req
->params
.offset
= 0x3FFFC;
1435 req
->params
.data_buf_size
= 0x4;
1437 status
= be_mcc_notify_wait(adapter
);
1439 memcpy(flashed_crc
, req
->params
.data_buf
, 4);
1442 spin_unlock_bh(&adapter
->mcc_lock
);
1446 extern int be_cmd_enable_magic_wol(struct be_adapter
*adapter
, u8
*mac
,
1447 struct be_dma_mem
*nonemb_cmd
)
1449 struct be_mcc_wrb
*wrb
;
1450 struct be_cmd_req_acpi_wol_magic_config
*req
;
1454 spin_lock_bh(&adapter
->mcc_lock
);
1456 wrb
= wrb_from_mccq(adapter
);
1461 req
= nonemb_cmd
->va
;
1462 sge
= nonembedded_sgl(wrb
);
1464 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1465 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
);
1467 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1468 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
, sizeof(*req
));
1469 memcpy(req
->magic_mac
, mac
, ETH_ALEN
);
1471 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1472 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1473 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1475 status
= be_mcc_notify_wait(adapter
);
1478 spin_unlock_bh(&adapter
->mcc_lock
);
1482 int be_cmd_set_loopback(struct be_adapter
*adapter
, u8 port_num
,
1483 u8 loopback_type
, u8 enable
)
1485 struct be_mcc_wrb
*wrb
;
1486 struct be_cmd_req_set_lmode
*req
;
1489 spin_lock_bh(&adapter
->mcc_lock
);
1491 wrb
= wrb_from_mccq(adapter
);
1497 req
= embedded_payload(wrb
);
1499 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1500 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
);
1502 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1503 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
1506 req
->src_port
= port_num
;
1507 req
->dest_port
= port_num
;
1508 req
->loopback_type
= loopback_type
;
1509 req
->loopback_state
= enable
;
1511 status
= be_mcc_notify_wait(adapter
);
1513 spin_unlock_bh(&adapter
->mcc_lock
);
1517 int be_cmd_loopback_test(struct be_adapter
*adapter
, u32 port_num
,
1518 u32 loopback_type
, u32 pkt_size
, u32 num_pkts
, u64 pattern
)
1520 struct be_mcc_wrb
*wrb
;
1521 struct be_cmd_req_loopback_test
*req
;
1524 spin_lock_bh(&adapter
->mcc_lock
);
1526 wrb
= wrb_from_mccq(adapter
);
1532 req
= embedded_payload(wrb
);
1534 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1535 OPCODE_LOWLEVEL_LOOPBACK_TEST
);
1537 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1538 OPCODE_LOWLEVEL_LOOPBACK_TEST
, sizeof(*req
));
1539 req
->hdr
.timeout
= 4;
1541 req
->pattern
= cpu_to_le64(pattern
);
1542 req
->src_port
= cpu_to_le32(port_num
);
1543 req
->dest_port
= cpu_to_le32(port_num
);
1544 req
->pkt_size
= cpu_to_le32(pkt_size
);
1545 req
->num_pkts
= cpu_to_le32(num_pkts
);
1546 req
->loopback_type
= cpu_to_le32(loopback_type
);
1548 status
= be_mcc_notify_wait(adapter
);
1550 struct be_cmd_resp_loopback_test
*resp
= embedded_payload(wrb
);
1551 status
= le32_to_cpu(resp
->status
);
1555 spin_unlock_bh(&adapter
->mcc_lock
);
1559 int be_cmd_ddr_dma_test(struct be_adapter
*adapter
, u64 pattern
,
1560 u32 byte_cnt
, struct be_dma_mem
*cmd
)
1562 struct be_mcc_wrb
*wrb
;
1563 struct be_cmd_req_ddrdma_test
*req
;
1568 spin_lock_bh(&adapter
->mcc_lock
);
1570 wrb
= wrb_from_mccq(adapter
);
1576 sge
= nonembedded_sgl(wrb
);
1577 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1578 OPCODE_LOWLEVEL_HOST_DDR_DMA
);
1579 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1580 OPCODE_LOWLEVEL_HOST_DDR_DMA
, cmd
->size
);
1582 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1583 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1584 sge
->len
= cpu_to_le32(cmd
->size
);
1586 req
->pattern
= cpu_to_le64(pattern
);
1587 req
->byte_count
= cpu_to_le32(byte_cnt
);
1588 for (i
= 0; i
< byte_cnt
; i
++) {
1589 req
->snd_buff
[i
] = (u8
)(pattern
>> (j
*8));
1595 status
= be_mcc_notify_wait(adapter
);
1598 struct be_cmd_resp_ddrdma_test
*resp
;
1600 if ((memcmp(resp
->rcv_buff
, req
->snd_buff
, byte_cnt
) != 0) ||
1607 spin_unlock_bh(&adapter
->mcc_lock
);