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 /* Grp5 CoS Priority evt */
100 static void be_async_grp5_cos_priority_process(struct be_adapter
*adapter
,
101 struct be_async_event_grp5_cos_priority
*evt
)
104 adapter
->vlan_prio_bmap
= evt
->available_priority_bmap
;
105 adapter
->recommended_prio
=
106 evt
->reco_default_priority
<< VLAN_PRIO_SHIFT
;
110 /* Grp5 QOS Speed evt */
111 static void be_async_grp5_qos_speed_process(struct be_adapter
*adapter
,
112 struct be_async_event_grp5_qos_link_speed
*evt
)
114 if (evt
->physical_port
== adapter
->port_num
) {
115 /* qos_link_speed is in units of 10 Mbps */
116 adapter
->link_speed
= evt
->qos_link_speed
* 10;
120 static void be_async_grp5_evt_process(struct be_adapter
*adapter
,
121 u32 trailer
, struct be_mcc_compl
*evt
)
125 event_type
= (trailer
>> ASYNC_TRAILER_EVENT_TYPE_SHIFT
) &
126 ASYNC_TRAILER_EVENT_TYPE_MASK
;
128 switch (event_type
) {
129 case ASYNC_EVENT_COS_PRIORITY
:
130 be_async_grp5_cos_priority_process(adapter
,
131 (struct be_async_event_grp5_cos_priority
*)evt
);
133 case ASYNC_EVENT_QOS_SPEED
:
134 be_async_grp5_qos_speed_process(adapter
,
135 (struct be_async_event_grp5_qos_link_speed
*)evt
);
138 dev_warn(&adapter
->pdev
->dev
, "Unknown grp5 event!\n");
143 static inline bool is_link_state_evt(u32 trailer
)
145 return ((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
146 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
147 ASYNC_EVENT_CODE_LINK_STATE
;
150 static inline bool is_grp5_evt(u32 trailer
)
152 return (((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
153 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
154 ASYNC_EVENT_CODE_GRP_5
);
157 static struct be_mcc_compl
*be_mcc_compl_get(struct be_adapter
*adapter
)
159 struct be_queue_info
*mcc_cq
= &adapter
->mcc_obj
.cq
;
160 struct be_mcc_compl
*compl = queue_tail_node(mcc_cq
);
162 if (be_mcc_compl_is_new(compl)) {
163 queue_tail_inc(mcc_cq
);
169 void be_async_mcc_enable(struct be_adapter
*adapter
)
171 spin_lock_bh(&adapter
->mcc_cq_lock
);
173 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, true, 0);
174 adapter
->mcc_obj
.rearm_cq
= true;
176 spin_unlock_bh(&adapter
->mcc_cq_lock
);
179 void be_async_mcc_disable(struct be_adapter
*adapter
)
181 adapter
->mcc_obj
.rearm_cq
= false;
184 int be_process_mcc(struct be_adapter
*adapter
, int *status
)
186 struct be_mcc_compl
*compl;
188 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
190 spin_lock_bh(&adapter
->mcc_cq_lock
);
191 while ((compl = be_mcc_compl_get(adapter
))) {
192 if (compl->flags
& CQE_FLAGS_ASYNC_MASK
) {
193 /* Interpret flags as an async trailer */
194 if (is_link_state_evt(compl->flags
))
195 be_async_link_state_process(adapter
,
196 (struct be_async_event_link_state
*) compl);
197 else if (is_grp5_evt(compl->flags
))
198 be_async_grp5_evt_process(adapter
,
199 compl->flags
, compl);
200 } else if (compl->flags
& CQE_FLAGS_COMPLETED_MASK
) {
201 *status
= be_mcc_compl_process(adapter
, compl);
202 atomic_dec(&mcc_obj
->q
.used
);
204 be_mcc_compl_use(compl);
208 spin_unlock_bh(&adapter
->mcc_cq_lock
);
212 /* Wait till no more pending mcc requests are present */
213 static int be_mcc_wait_compl(struct be_adapter
*adapter
)
215 #define mcc_timeout 120000 /* 12s timeout */
216 int i
, num
, status
= 0;
217 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
219 for (i
= 0; i
< mcc_timeout
; i
++) {
220 num
= be_process_mcc(adapter
, &status
);
222 be_cq_notify(adapter
, mcc_obj
->cq
.id
,
223 mcc_obj
->rearm_cq
, num
);
225 if (atomic_read(&mcc_obj
->q
.used
) == 0)
229 if (i
== mcc_timeout
) {
230 dev_err(&adapter
->pdev
->dev
, "mccq poll timed out\n");
236 /* Notify MCC requests and wait for completion */
237 static int be_mcc_notify_wait(struct be_adapter
*adapter
)
239 be_mcc_notify(adapter
);
240 return be_mcc_wait_compl(adapter
);
243 static int be_mbox_db_ready_wait(struct be_adapter
*adapter
, void __iomem
*db
)
249 ready
= ioread32(db
);
250 if (ready
== 0xffffffff) {
251 dev_err(&adapter
->pdev
->dev
,
252 "pci slot disconnected\n");
256 ready
&= MPU_MAILBOX_DB_RDY_MASK
;
261 dev_err(&adapter
->pdev
->dev
, "mbox poll timed out\n");
262 be_detect_dump_ue(adapter
);
266 set_current_state(TASK_INTERRUPTIBLE
);
267 schedule_timeout(msecs_to_jiffies(1));
275 * Insert the mailbox address into the doorbell in two steps
276 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
278 static int be_mbox_notify_wait(struct be_adapter
*adapter
)
282 void __iomem
*db
= adapter
->db
+ MPU_MAILBOX_DB_OFFSET
;
283 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
284 struct be_mcc_mailbox
*mbox
= mbox_mem
->va
;
285 struct be_mcc_compl
*compl = &mbox
->compl;
287 /* wait for ready to be set */
288 status
= be_mbox_db_ready_wait(adapter
, db
);
292 val
|= MPU_MAILBOX_DB_HI_MASK
;
293 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
294 val
|= (upper_32_bits(mbox_mem
->dma
) >> 2) << 2;
297 /* wait for ready to be set */
298 status
= be_mbox_db_ready_wait(adapter
, db
);
303 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
304 val
|= (u32
)(mbox_mem
->dma
>> 4) << 2;
307 status
= be_mbox_db_ready_wait(adapter
, db
);
311 /* A cq entry has been made now */
312 if (be_mcc_compl_is_new(compl)) {
313 status
= be_mcc_compl_process(adapter
, &mbox
->compl);
314 be_mcc_compl_use(compl);
318 dev_err(&adapter
->pdev
->dev
, "invalid mailbox completion\n");
324 static int be_POST_stage_get(struct be_adapter
*adapter
, u16
*stage
)
328 if (lancer_chip(adapter
))
329 sem
= ioread32(adapter
->db
+ MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET
);
331 sem
= ioread32(adapter
->csr
+ MPU_EP_SEMAPHORE_OFFSET
);
333 *stage
= sem
& EP_SEMAPHORE_POST_STAGE_MASK
;
334 if ((sem
>> EP_SEMAPHORE_POST_ERR_SHIFT
) & EP_SEMAPHORE_POST_ERR_MASK
)
340 int be_cmd_POST(struct be_adapter
*adapter
)
343 int status
, timeout
= 0;
346 status
= be_POST_stage_get(adapter
, &stage
);
348 dev_err(&adapter
->pdev
->dev
, "POST error; stage=0x%x\n",
351 } else if (stage
!= POST_STAGE_ARMFW_RDY
) {
352 set_current_state(TASK_INTERRUPTIBLE
);
353 schedule_timeout(2 * HZ
);
358 } while (timeout
< 40);
360 dev_err(&adapter
->pdev
->dev
, "POST timeout; stage=0x%x\n", stage
);
364 static inline void *embedded_payload(struct be_mcc_wrb
*wrb
)
366 return wrb
->payload
.embedded_payload
;
369 static inline struct be_sge
*nonembedded_sgl(struct be_mcc_wrb
*wrb
)
371 return &wrb
->payload
.sgl
[0];
374 /* Don't touch the hdr after it's prepared */
375 static void be_wrb_hdr_prepare(struct be_mcc_wrb
*wrb
, int payload_len
,
376 bool embedded
, u8 sge_cnt
, u32 opcode
)
379 wrb
->embedded
|= MCC_WRB_EMBEDDED_MASK
;
381 wrb
->embedded
|= (sge_cnt
& MCC_WRB_SGE_CNT_MASK
) <<
382 MCC_WRB_SGE_CNT_SHIFT
;
383 wrb
->payload_length
= payload_len
;
385 be_dws_cpu_to_le(wrb
, 8);
388 /* Don't touch the hdr after it's prepared */
389 static void be_cmd_hdr_prepare(struct be_cmd_req_hdr
*req_hdr
,
390 u8 subsystem
, u8 opcode
, int cmd_len
)
392 req_hdr
->opcode
= opcode
;
393 req_hdr
->subsystem
= subsystem
;
394 req_hdr
->request_length
= cpu_to_le32(cmd_len
- sizeof(*req_hdr
));
395 req_hdr
->version
= 0;
398 static void be_cmd_page_addrs_prepare(struct phys_addr
*pages
, u32 max_pages
,
399 struct be_dma_mem
*mem
)
401 int i
, buf_pages
= min(PAGES_4K_SPANNED(mem
->va
, mem
->size
), max_pages
);
402 u64 dma
= (u64
)mem
->dma
;
404 for (i
= 0; i
< buf_pages
; i
++) {
405 pages
[i
].lo
= cpu_to_le32(dma
& 0xFFFFFFFF);
406 pages
[i
].hi
= cpu_to_le32(upper_32_bits(dma
));
411 /* Converts interrupt delay in microseconds to multiplier value */
412 static u32
eq_delay_to_mult(u32 usec_delay
)
414 #define MAX_INTR_RATE 651042
415 const u32 round
= 10;
421 u32 interrupt_rate
= 1000000 / usec_delay
;
422 /* Max delay, corresponding to the lowest interrupt rate */
423 if (interrupt_rate
== 0)
426 multiplier
= (MAX_INTR_RATE
- interrupt_rate
) * round
;
427 multiplier
/= interrupt_rate
;
428 /* Round the multiplier to the closest value.*/
429 multiplier
= (multiplier
+ round
/2) / round
;
430 multiplier
= min(multiplier
, (u32
)1023);
436 static inline struct be_mcc_wrb
*wrb_from_mbox(struct be_adapter
*adapter
)
438 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
439 struct be_mcc_wrb
*wrb
440 = &((struct be_mcc_mailbox
*)(mbox_mem
->va
))->wrb
;
441 memset(wrb
, 0, sizeof(*wrb
));
445 static struct be_mcc_wrb
*wrb_from_mccq(struct be_adapter
*adapter
)
447 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
448 struct be_mcc_wrb
*wrb
;
450 if (atomic_read(&mccq
->used
) >= mccq
->len
) {
451 dev_err(&adapter
->pdev
->dev
, "Out of MCCQ wrbs\n");
455 wrb
= queue_head_node(mccq
);
456 queue_head_inc(mccq
);
457 atomic_inc(&mccq
->used
);
458 memset(wrb
, 0, sizeof(*wrb
));
462 /* Tell fw we're about to start firing cmds by writing a
463 * special pattern across the wrb hdr; uses mbox
465 int be_cmd_fw_init(struct be_adapter
*adapter
)
470 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
473 wrb
= (u8
*)wrb_from_mbox(adapter
);
483 status
= be_mbox_notify_wait(adapter
);
485 mutex_unlock(&adapter
->mbox_lock
);
489 /* Tell fw we're done with firing cmds by writing a
490 * special pattern across the wrb hdr; uses mbox
492 int be_cmd_fw_clean(struct be_adapter
*adapter
)
497 if (adapter
->eeh_err
)
500 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
503 wrb
= (u8
*)wrb_from_mbox(adapter
);
513 status
= be_mbox_notify_wait(adapter
);
515 mutex_unlock(&adapter
->mbox_lock
);
518 int be_cmd_eq_create(struct be_adapter
*adapter
,
519 struct be_queue_info
*eq
, int eq_delay
)
521 struct be_mcc_wrb
*wrb
;
522 struct be_cmd_req_eq_create
*req
;
523 struct be_dma_mem
*q_mem
= &eq
->dma_mem
;
526 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
529 wrb
= wrb_from_mbox(adapter
);
530 req
= embedded_payload(wrb
);
532 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_COMMON_EQ_CREATE
);
534 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
535 OPCODE_COMMON_EQ_CREATE
, sizeof(*req
));
537 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
539 AMAP_SET_BITS(struct amap_eq_context
, valid
, req
->context
, 1);
541 AMAP_SET_BITS(struct amap_eq_context
, size
, req
->context
, 0);
542 AMAP_SET_BITS(struct amap_eq_context
, count
, req
->context
,
543 __ilog2_u32(eq
->len
/256));
544 AMAP_SET_BITS(struct amap_eq_context
, delaymult
, req
->context
,
545 eq_delay_to_mult(eq_delay
));
546 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
548 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
550 status
= be_mbox_notify_wait(adapter
);
552 struct be_cmd_resp_eq_create
*resp
= embedded_payload(wrb
);
553 eq
->id
= le16_to_cpu(resp
->eq_id
);
557 mutex_unlock(&adapter
->mbox_lock
);
562 int be_cmd_mac_addr_query(struct be_adapter
*adapter
, u8
*mac_addr
,
563 u8 type
, bool permanent
, u32 if_handle
)
565 struct be_mcc_wrb
*wrb
;
566 struct be_cmd_req_mac_query
*req
;
569 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
572 wrb
= wrb_from_mbox(adapter
);
573 req
= embedded_payload(wrb
);
575 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
576 OPCODE_COMMON_NTWK_MAC_QUERY
);
578 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
579 OPCODE_COMMON_NTWK_MAC_QUERY
, sizeof(*req
));
585 req
->if_id
= cpu_to_le16((u16
) if_handle
);
589 status
= be_mbox_notify_wait(adapter
);
591 struct be_cmd_resp_mac_query
*resp
= embedded_payload(wrb
);
592 memcpy(mac_addr
, resp
->mac
.addr
, ETH_ALEN
);
595 mutex_unlock(&adapter
->mbox_lock
);
599 /* Uses synchronous MCCQ */
600 int be_cmd_pmac_add(struct be_adapter
*adapter
, u8
*mac_addr
,
601 u32 if_id
, u32
*pmac_id
)
603 struct be_mcc_wrb
*wrb
;
604 struct be_cmd_req_pmac_add
*req
;
607 spin_lock_bh(&adapter
->mcc_lock
);
609 wrb
= wrb_from_mccq(adapter
);
614 req
= embedded_payload(wrb
);
616 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
617 OPCODE_COMMON_NTWK_PMAC_ADD
);
619 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
620 OPCODE_COMMON_NTWK_PMAC_ADD
, sizeof(*req
));
622 req
->if_id
= cpu_to_le32(if_id
);
623 memcpy(req
->mac_address
, mac_addr
, ETH_ALEN
);
625 status
= be_mcc_notify_wait(adapter
);
627 struct be_cmd_resp_pmac_add
*resp
= embedded_payload(wrb
);
628 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
632 spin_unlock_bh(&adapter
->mcc_lock
);
636 /* Uses synchronous MCCQ */
637 int be_cmd_pmac_del(struct be_adapter
*adapter
, u32 if_id
, u32 pmac_id
)
639 struct be_mcc_wrb
*wrb
;
640 struct be_cmd_req_pmac_del
*req
;
643 spin_lock_bh(&adapter
->mcc_lock
);
645 wrb
= wrb_from_mccq(adapter
);
650 req
= embedded_payload(wrb
);
652 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
653 OPCODE_COMMON_NTWK_PMAC_DEL
);
655 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
656 OPCODE_COMMON_NTWK_PMAC_DEL
, sizeof(*req
));
658 req
->if_id
= cpu_to_le32(if_id
);
659 req
->pmac_id
= cpu_to_le32(pmac_id
);
661 status
= be_mcc_notify_wait(adapter
);
664 spin_unlock_bh(&adapter
->mcc_lock
);
669 int be_cmd_cq_create(struct be_adapter
*adapter
,
670 struct be_queue_info
*cq
, struct be_queue_info
*eq
,
671 bool sol_evts
, bool no_delay
, int coalesce_wm
)
673 struct be_mcc_wrb
*wrb
;
674 struct be_cmd_req_cq_create
*req
;
675 struct be_dma_mem
*q_mem
= &cq
->dma_mem
;
679 if (mutex_lock_interruptible(&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_COMMON_CQ_CREATE
);
689 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
690 OPCODE_COMMON_CQ_CREATE
, sizeof(*req
));
692 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
693 if (lancer_chip(adapter
)) {
694 req
->hdr
.version
= 1;
695 req
->page_size
= 1; /* 1 for 4K */
696 AMAP_SET_BITS(struct amap_cq_context_lancer
, coalescwm
, ctxt
,
698 AMAP_SET_BITS(struct amap_cq_context_lancer
, nodelay
, ctxt
,
700 AMAP_SET_BITS(struct amap_cq_context_lancer
, count
, ctxt
,
701 __ilog2_u32(cq
->len
/256));
702 AMAP_SET_BITS(struct amap_cq_context_lancer
, valid
, ctxt
, 1);
703 AMAP_SET_BITS(struct amap_cq_context_lancer
, eventable
,
705 AMAP_SET_BITS(struct amap_cq_context_lancer
, eqid
,
707 AMAP_SET_BITS(struct amap_cq_context_lancer
, armed
, ctxt
, 1);
709 AMAP_SET_BITS(struct amap_cq_context_be
, coalescwm
, ctxt
,
711 AMAP_SET_BITS(struct amap_cq_context_be
, nodelay
,
713 AMAP_SET_BITS(struct amap_cq_context_be
, count
, ctxt
,
714 __ilog2_u32(cq
->len
/256));
715 AMAP_SET_BITS(struct amap_cq_context_be
, valid
, ctxt
, 1);
716 AMAP_SET_BITS(struct amap_cq_context_be
, solevent
,
718 AMAP_SET_BITS(struct amap_cq_context_be
, eventable
, ctxt
, 1);
719 AMAP_SET_BITS(struct amap_cq_context_be
, eqid
, ctxt
, eq
->id
);
720 AMAP_SET_BITS(struct amap_cq_context_be
, armed
, ctxt
, 1);
723 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
725 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
727 status
= be_mbox_notify_wait(adapter
);
729 struct be_cmd_resp_cq_create
*resp
= embedded_payload(wrb
);
730 cq
->id
= le16_to_cpu(resp
->cq_id
);
734 mutex_unlock(&adapter
->mbox_lock
);
739 static u32
be_encoded_q_len(int q_len
)
741 u32 len_encoded
= fls(q_len
); /* log2(len) + 1 */
742 if (len_encoded
== 16)
747 int be_cmd_mccq_create(struct be_adapter
*adapter
,
748 struct be_queue_info
*mccq
,
749 struct be_queue_info
*cq
)
751 struct be_mcc_wrb
*wrb
;
752 struct be_cmd_req_mcc_create
*req
;
753 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
757 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
760 wrb
= wrb_from_mbox(adapter
);
761 req
= embedded_payload(wrb
);
762 ctxt
= &req
->context
;
764 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
765 OPCODE_COMMON_MCC_CREATE_EXT
);
767 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
768 OPCODE_COMMON_MCC_CREATE_EXT
, sizeof(*req
));
770 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
771 if (lancer_chip(adapter
)) {
772 req
->hdr
.version
= 1;
773 req
->cq_id
= cpu_to_le16(cq
->id
);
775 AMAP_SET_BITS(struct amap_mcc_context_lancer
, ring_size
, ctxt
,
776 be_encoded_q_len(mccq
->len
));
777 AMAP_SET_BITS(struct amap_mcc_context_lancer
, valid
, ctxt
, 1);
778 AMAP_SET_BITS(struct amap_mcc_context_lancer
, async_cq_id
,
780 AMAP_SET_BITS(struct amap_mcc_context_lancer
, async_cq_valid
,
784 AMAP_SET_BITS(struct amap_mcc_context_be
, valid
, ctxt
, 1);
785 AMAP_SET_BITS(struct amap_mcc_context_be
, ring_size
, ctxt
,
786 be_encoded_q_len(mccq
->len
));
787 AMAP_SET_BITS(struct amap_mcc_context_be
, cq_id
, ctxt
, cq
->id
);
790 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
791 req
->async_event_bitmap
[0] = cpu_to_le32(0x00000022);
792 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
794 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
796 status
= be_mbox_notify_wait(adapter
);
798 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
799 mccq
->id
= le16_to_cpu(resp
->id
);
800 mccq
->created
= true;
802 mutex_unlock(&adapter
->mbox_lock
);
807 int be_cmd_txq_create(struct be_adapter
*adapter
,
808 struct be_queue_info
*txq
,
809 struct be_queue_info
*cq
)
811 struct be_mcc_wrb
*wrb
;
812 struct be_cmd_req_eth_tx_create
*req
;
813 struct be_dma_mem
*q_mem
= &txq
->dma_mem
;
817 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
820 wrb
= wrb_from_mbox(adapter
);
821 req
= embedded_payload(wrb
);
822 ctxt
= &req
->context
;
824 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
825 OPCODE_ETH_TX_CREATE
);
827 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_TX_CREATE
,
830 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
831 req
->ulp_num
= BE_ULP1_NUM
;
832 req
->type
= BE_ETH_TX_RING_TYPE_STANDARD
;
834 AMAP_SET_BITS(struct amap_tx_context
, tx_ring_size
, ctxt
,
835 be_encoded_q_len(txq
->len
));
836 AMAP_SET_BITS(struct amap_tx_context
, ctx_valid
, ctxt
, 1);
837 AMAP_SET_BITS(struct amap_tx_context
, cq_id_send
, ctxt
, cq
->id
);
839 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
841 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
843 status
= be_mbox_notify_wait(adapter
);
845 struct be_cmd_resp_eth_tx_create
*resp
= embedded_payload(wrb
);
846 txq
->id
= le16_to_cpu(resp
->cid
);
850 mutex_unlock(&adapter
->mbox_lock
);
856 int be_cmd_rxq_create(struct be_adapter
*adapter
,
857 struct be_queue_info
*rxq
, u16 cq_id
, u16 frag_size
,
858 u16 max_frame_size
, u32 if_id
, u32 rss
, u8
*rss_id
)
860 struct be_mcc_wrb
*wrb
;
861 struct be_cmd_req_eth_rx_create
*req
;
862 struct be_dma_mem
*q_mem
= &rxq
->dma_mem
;
865 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
868 wrb
= wrb_from_mbox(adapter
);
869 req
= embedded_payload(wrb
);
871 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
872 OPCODE_ETH_RX_CREATE
);
874 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_RX_CREATE
,
877 req
->cq_id
= cpu_to_le16(cq_id
);
878 req
->frag_size
= fls(frag_size
) - 1;
880 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
881 req
->interface_id
= cpu_to_le32(if_id
);
882 req
->max_frame_size
= cpu_to_le16(max_frame_size
);
883 req
->rss_queue
= cpu_to_le32(rss
);
885 status
= be_mbox_notify_wait(adapter
);
887 struct be_cmd_resp_eth_rx_create
*resp
= embedded_payload(wrb
);
888 rxq
->id
= le16_to_cpu(resp
->id
);
890 *rss_id
= resp
->rss_id
;
893 mutex_unlock(&adapter
->mbox_lock
);
898 /* Generic destroyer function for all types of queues
901 int be_cmd_q_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
,
904 struct be_mcc_wrb
*wrb
;
905 struct be_cmd_req_q_destroy
*req
;
906 u8 subsys
= 0, opcode
= 0;
909 if (adapter
->eeh_err
)
912 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
915 wrb
= wrb_from_mbox(adapter
);
916 req
= embedded_payload(wrb
);
918 switch (queue_type
) {
920 subsys
= CMD_SUBSYSTEM_COMMON
;
921 opcode
= OPCODE_COMMON_EQ_DESTROY
;
924 subsys
= CMD_SUBSYSTEM_COMMON
;
925 opcode
= OPCODE_COMMON_CQ_DESTROY
;
928 subsys
= CMD_SUBSYSTEM_ETH
;
929 opcode
= OPCODE_ETH_TX_DESTROY
;
932 subsys
= CMD_SUBSYSTEM_ETH
;
933 opcode
= OPCODE_ETH_RX_DESTROY
;
936 subsys
= CMD_SUBSYSTEM_COMMON
;
937 opcode
= OPCODE_COMMON_MCC_DESTROY
;
943 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, opcode
);
945 be_cmd_hdr_prepare(&req
->hdr
, subsys
, opcode
, sizeof(*req
));
946 req
->id
= cpu_to_le16(q
->id
);
948 status
= be_mbox_notify_wait(adapter
);
950 mutex_unlock(&adapter
->mbox_lock
);
955 /* Create an rx filtering policy configuration on an i/f
958 int be_cmd_if_create(struct be_adapter
*adapter
, u32 cap_flags
, u32 en_flags
,
959 u8
*mac
, bool pmac_invalid
, u32
*if_handle
, u32
*pmac_id
,
962 struct be_mcc_wrb
*wrb
;
963 struct be_cmd_req_if_create
*req
;
966 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
969 wrb
= wrb_from_mbox(adapter
);
970 req
= embedded_payload(wrb
);
972 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
973 OPCODE_COMMON_NTWK_INTERFACE_CREATE
);
975 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
976 OPCODE_COMMON_NTWK_INTERFACE_CREATE
, sizeof(*req
));
978 req
->hdr
.domain
= domain
;
979 req
->capability_flags
= cpu_to_le32(cap_flags
);
980 req
->enable_flags
= cpu_to_le32(en_flags
);
981 req
->pmac_invalid
= pmac_invalid
;
983 memcpy(req
->mac_addr
, mac
, ETH_ALEN
);
985 status
= be_mbox_notify_wait(adapter
);
987 struct be_cmd_resp_if_create
*resp
= embedded_payload(wrb
);
988 *if_handle
= le32_to_cpu(resp
->interface_id
);
990 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
993 mutex_unlock(&adapter
->mbox_lock
);
998 int be_cmd_if_destroy(struct be_adapter
*adapter
, u32 interface_id
)
1000 struct be_mcc_wrb
*wrb
;
1001 struct be_cmd_req_if_destroy
*req
;
1004 if (adapter
->eeh_err
)
1007 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1010 wrb
= wrb_from_mbox(adapter
);
1011 req
= embedded_payload(wrb
);
1013 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1014 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
);
1016 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1017 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
, sizeof(*req
));
1019 req
->interface_id
= cpu_to_le32(interface_id
);
1021 status
= be_mbox_notify_wait(adapter
);
1023 mutex_unlock(&adapter
->mbox_lock
);
1028 /* Get stats is a non embedded command: the request is not embedded inside
1029 * WRB but is a separate dma memory block
1030 * Uses asynchronous MCC
1032 int be_cmd_get_stats(struct be_adapter
*adapter
, struct be_dma_mem
*nonemb_cmd
)
1034 struct be_mcc_wrb
*wrb
;
1035 struct be_cmd_req_get_stats
*req
;
1039 spin_lock_bh(&adapter
->mcc_lock
);
1041 wrb
= wrb_from_mccq(adapter
);
1046 req
= nonemb_cmd
->va
;
1047 sge
= nonembedded_sgl(wrb
);
1049 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1050 OPCODE_ETH_GET_STATISTICS
);
1052 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1053 OPCODE_ETH_GET_STATISTICS
, sizeof(*req
));
1054 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1055 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1056 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1058 be_mcc_notify(adapter
);
1059 adapter
->stats_ioctl_sent
= true;
1062 spin_unlock_bh(&adapter
->mcc_lock
);
1066 /* Uses synchronous mcc */
1067 int be_cmd_link_status_query(struct be_adapter
*adapter
,
1068 bool *link_up
, u8
*mac_speed
, u16
*link_speed
)
1070 struct be_mcc_wrb
*wrb
;
1071 struct be_cmd_req_link_status
*req
;
1074 spin_lock_bh(&adapter
->mcc_lock
);
1076 wrb
= wrb_from_mccq(adapter
);
1081 req
= embedded_payload(wrb
);
1085 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1086 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
);
1088 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1089 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
, sizeof(*req
));
1091 status
= be_mcc_notify_wait(adapter
);
1093 struct be_cmd_resp_link_status
*resp
= embedded_payload(wrb
);
1094 if (resp
->mac_speed
!= PHY_LINK_SPEED_ZERO
) {
1096 *link_speed
= le16_to_cpu(resp
->link_speed
);
1097 *mac_speed
= resp
->mac_speed
;
1102 spin_unlock_bh(&adapter
->mcc_lock
);
1107 int be_cmd_get_fw_ver(struct be_adapter
*adapter
, char *fw_ver
)
1109 struct be_mcc_wrb
*wrb
;
1110 struct be_cmd_req_get_fw_version
*req
;
1113 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1116 wrb
= wrb_from_mbox(adapter
);
1117 req
= embedded_payload(wrb
);
1119 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1120 OPCODE_COMMON_GET_FW_VERSION
);
1122 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1123 OPCODE_COMMON_GET_FW_VERSION
, sizeof(*req
));
1125 status
= be_mbox_notify_wait(adapter
);
1127 struct be_cmd_resp_get_fw_version
*resp
= embedded_payload(wrb
);
1128 strncpy(fw_ver
, resp
->firmware_version_string
, FW_VER_LEN
);
1131 mutex_unlock(&adapter
->mbox_lock
);
1135 /* set the EQ delay interval of an EQ to specified value
1138 int be_cmd_modify_eqd(struct be_adapter
*adapter
, u32 eq_id
, u32 eqd
)
1140 struct be_mcc_wrb
*wrb
;
1141 struct be_cmd_req_modify_eq_delay
*req
;
1144 spin_lock_bh(&adapter
->mcc_lock
);
1146 wrb
= wrb_from_mccq(adapter
);
1151 req
= embedded_payload(wrb
);
1153 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1154 OPCODE_COMMON_MODIFY_EQ_DELAY
);
1156 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1157 OPCODE_COMMON_MODIFY_EQ_DELAY
, sizeof(*req
));
1159 req
->num_eq
= cpu_to_le32(1);
1160 req
->delay
[0].eq_id
= cpu_to_le32(eq_id
);
1161 req
->delay
[0].phase
= 0;
1162 req
->delay
[0].delay_multiplier
= cpu_to_le32(eqd
);
1164 be_mcc_notify(adapter
);
1167 spin_unlock_bh(&adapter
->mcc_lock
);
1171 /* Uses sycnhronous mcc */
1172 int be_cmd_vlan_config(struct be_adapter
*adapter
, u32 if_id
, u16
*vtag_array
,
1173 u32 num
, bool untagged
, bool promiscuous
)
1175 struct be_mcc_wrb
*wrb
;
1176 struct be_cmd_req_vlan_config
*req
;
1179 spin_lock_bh(&adapter
->mcc_lock
);
1181 wrb
= wrb_from_mccq(adapter
);
1186 req
= embedded_payload(wrb
);
1188 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1189 OPCODE_COMMON_NTWK_VLAN_CONFIG
);
1191 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1192 OPCODE_COMMON_NTWK_VLAN_CONFIG
, sizeof(*req
));
1194 req
->interface_id
= if_id
;
1195 req
->promiscuous
= promiscuous
;
1196 req
->untagged
= untagged
;
1197 req
->num_vlan
= num
;
1199 memcpy(req
->normal_vlan
, vtag_array
,
1200 req
->num_vlan
* sizeof(vtag_array
[0]));
1203 status
= be_mcc_notify_wait(adapter
);
1206 spin_unlock_bh(&adapter
->mcc_lock
);
1210 /* Uses MCC for this command as it may be called in BH context
1211 * Uses synchronous mcc
1213 int be_cmd_promiscuous_config(struct be_adapter
*adapter
, u8 port_num
, bool en
)
1215 struct be_mcc_wrb
*wrb
;
1216 struct be_cmd_req_promiscuous_config
*req
;
1219 spin_lock_bh(&adapter
->mcc_lock
);
1221 wrb
= wrb_from_mccq(adapter
);
1226 req
= embedded_payload(wrb
);
1228 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_ETH_PROMISCUOUS
);
1230 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1231 OPCODE_ETH_PROMISCUOUS
, sizeof(*req
));
1233 /* In FW versions X.102.149/X.101.487 and later,
1234 * the port setting associated only with the
1235 * issuing pci function will take effect
1238 req
->port1_promiscuous
= en
;
1240 req
->port0_promiscuous
= en
;
1242 status
= be_mcc_notify_wait(adapter
);
1245 spin_unlock_bh(&adapter
->mcc_lock
);
1250 * Uses MCC for this command as it may be called in BH context
1251 * (mc == NULL) => multicast promiscous
1253 int be_cmd_multicast_set(struct be_adapter
*adapter
, u32 if_id
,
1254 struct net_device
*netdev
, struct be_dma_mem
*mem
)
1256 struct be_mcc_wrb
*wrb
;
1257 struct be_cmd_req_mcast_mac_config
*req
= mem
->va
;
1261 spin_lock_bh(&adapter
->mcc_lock
);
1263 wrb
= wrb_from_mccq(adapter
);
1268 sge
= nonembedded_sgl(wrb
);
1269 memset(req
, 0, sizeof(*req
));
1271 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1272 OPCODE_COMMON_NTWK_MULTICAST_SET
);
1273 sge
->pa_hi
= cpu_to_le32(upper_32_bits(mem
->dma
));
1274 sge
->pa_lo
= cpu_to_le32(mem
->dma
& 0xFFFFFFFF);
1275 sge
->len
= cpu_to_le32(mem
->size
);
1277 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1278 OPCODE_COMMON_NTWK_MULTICAST_SET
, sizeof(*req
));
1280 req
->interface_id
= if_id
;
1283 struct netdev_hw_addr
*ha
;
1285 req
->num_mac
= cpu_to_le16(netdev_mc_count(netdev
));
1288 netdev_for_each_mc_addr(ha
, netdev
)
1289 memcpy(req
->mac
[i
++].byte
, ha
->addr
, ETH_ALEN
);
1291 req
->promiscuous
= 1;
1294 status
= be_mcc_notify_wait(adapter
);
1297 spin_unlock_bh(&adapter
->mcc_lock
);
1301 /* Uses synchrounous mcc */
1302 int be_cmd_set_flow_control(struct be_adapter
*adapter
, u32 tx_fc
, u32 rx_fc
)
1304 struct be_mcc_wrb
*wrb
;
1305 struct be_cmd_req_set_flow_control
*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_SET_FLOW_CONTROL
);
1320 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1321 OPCODE_COMMON_SET_FLOW_CONTROL
, sizeof(*req
));
1323 req
->tx_flow_control
= cpu_to_le16((u16
)tx_fc
);
1324 req
->rx_flow_control
= cpu_to_le16((u16
)rx_fc
);
1326 status
= be_mcc_notify_wait(adapter
);
1329 spin_unlock_bh(&adapter
->mcc_lock
);
1334 int be_cmd_get_flow_control(struct be_adapter
*adapter
, u32
*tx_fc
, u32
*rx_fc
)
1336 struct be_mcc_wrb
*wrb
;
1337 struct be_cmd_req_get_flow_control
*req
;
1340 spin_lock_bh(&adapter
->mcc_lock
);
1342 wrb
= wrb_from_mccq(adapter
);
1347 req
= embedded_payload(wrb
);
1349 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1350 OPCODE_COMMON_GET_FLOW_CONTROL
);
1352 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1353 OPCODE_COMMON_GET_FLOW_CONTROL
, sizeof(*req
));
1355 status
= be_mcc_notify_wait(adapter
);
1357 struct be_cmd_resp_get_flow_control
*resp
=
1358 embedded_payload(wrb
);
1359 *tx_fc
= le16_to_cpu(resp
->tx_flow_control
);
1360 *rx_fc
= le16_to_cpu(resp
->rx_flow_control
);
1364 spin_unlock_bh(&adapter
->mcc_lock
);
1369 int be_cmd_query_fw_cfg(struct be_adapter
*adapter
, u32
*port_num
,
1370 u32
*mode
, u32
*caps
)
1372 struct be_mcc_wrb
*wrb
;
1373 struct be_cmd_req_query_fw_cfg
*req
;
1376 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1379 wrb
= wrb_from_mbox(adapter
);
1380 req
= embedded_payload(wrb
);
1382 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1383 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
);
1385 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1386 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
, sizeof(*req
));
1388 status
= be_mbox_notify_wait(adapter
);
1390 struct be_cmd_resp_query_fw_cfg
*resp
= embedded_payload(wrb
);
1391 *port_num
= le32_to_cpu(resp
->phys_port
);
1392 *mode
= le32_to_cpu(resp
->function_mode
);
1393 *caps
= le32_to_cpu(resp
->function_caps
);
1396 mutex_unlock(&adapter
->mbox_lock
);
1401 int be_cmd_reset_function(struct be_adapter
*adapter
)
1403 struct be_mcc_wrb
*wrb
;
1404 struct be_cmd_req_hdr
*req
;
1407 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1410 wrb
= wrb_from_mbox(adapter
);
1411 req
= embedded_payload(wrb
);
1413 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1414 OPCODE_COMMON_FUNCTION_RESET
);
1416 be_cmd_hdr_prepare(req
, CMD_SUBSYSTEM_COMMON
,
1417 OPCODE_COMMON_FUNCTION_RESET
, sizeof(*req
));
1419 status
= be_mbox_notify_wait(adapter
);
1421 mutex_unlock(&adapter
->mbox_lock
);
1425 int be_cmd_rss_config(struct be_adapter
*adapter
, u8
*rsstable
, u16 table_size
)
1427 struct be_mcc_wrb
*wrb
;
1428 struct be_cmd_req_rss_config
*req
;
1432 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1435 wrb
= wrb_from_mbox(adapter
);
1436 req
= embedded_payload(wrb
);
1438 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1439 OPCODE_ETH_RSS_CONFIG
);
1441 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1442 OPCODE_ETH_RSS_CONFIG
, sizeof(*req
));
1444 req
->if_id
= cpu_to_le32(adapter
->if_handle
);
1445 req
->enable_rss
= cpu_to_le16(RSS_ENABLE_TCP_IPV4
| RSS_ENABLE_IPV4
);
1446 req
->cpu_table_size_log2
= cpu_to_le16(fls(table_size
) - 1);
1447 memcpy(req
->cpu_table
, rsstable
, table_size
);
1448 memcpy(req
->hash
, myhash
, sizeof(myhash
));
1449 be_dws_cpu_to_le(req
->hash
, sizeof(req
->hash
));
1451 status
= be_mbox_notify_wait(adapter
);
1453 mutex_unlock(&adapter
->mbox_lock
);
1458 int be_cmd_set_beacon_state(struct be_adapter
*adapter
, u8 port_num
,
1459 u8 bcn
, u8 sts
, u8 state
)
1461 struct be_mcc_wrb
*wrb
;
1462 struct be_cmd_req_enable_disable_beacon
*req
;
1465 spin_lock_bh(&adapter
->mcc_lock
);
1467 wrb
= wrb_from_mccq(adapter
);
1472 req
= embedded_payload(wrb
);
1474 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1475 OPCODE_COMMON_ENABLE_DISABLE_BEACON
);
1477 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1478 OPCODE_COMMON_ENABLE_DISABLE_BEACON
, sizeof(*req
));
1480 req
->port_num
= port_num
;
1481 req
->beacon_state
= state
;
1482 req
->beacon_duration
= bcn
;
1483 req
->status_duration
= sts
;
1485 status
= be_mcc_notify_wait(adapter
);
1488 spin_unlock_bh(&adapter
->mcc_lock
);
1493 int be_cmd_get_beacon_state(struct be_adapter
*adapter
, u8 port_num
, u32
*state
)
1495 struct be_mcc_wrb
*wrb
;
1496 struct be_cmd_req_get_beacon_state
*req
;
1499 spin_lock_bh(&adapter
->mcc_lock
);
1501 wrb
= wrb_from_mccq(adapter
);
1506 req
= embedded_payload(wrb
);
1508 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1509 OPCODE_COMMON_GET_BEACON_STATE
);
1511 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1512 OPCODE_COMMON_GET_BEACON_STATE
, sizeof(*req
));
1514 req
->port_num
= port_num
;
1516 status
= be_mcc_notify_wait(adapter
);
1518 struct be_cmd_resp_get_beacon_state
*resp
=
1519 embedded_payload(wrb
);
1520 *state
= resp
->beacon_state
;
1524 spin_unlock_bh(&adapter
->mcc_lock
);
1528 int be_cmd_write_flashrom(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
1529 u32 flash_type
, u32 flash_opcode
, u32 buf_size
)
1531 struct be_mcc_wrb
*wrb
;
1532 struct be_cmd_write_flashrom
*req
;
1536 spin_lock_bh(&adapter
->mcc_lock
);
1537 adapter
->flash_status
= 0;
1539 wrb
= wrb_from_mccq(adapter
);
1545 sge
= nonembedded_sgl(wrb
);
1547 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1548 OPCODE_COMMON_WRITE_FLASHROM
);
1549 wrb
->tag1
= CMD_SUBSYSTEM_COMMON
;
1551 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1552 OPCODE_COMMON_WRITE_FLASHROM
, cmd
->size
);
1553 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1554 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1555 sge
->len
= cpu_to_le32(cmd
->size
);
1557 req
->params
.op_type
= cpu_to_le32(flash_type
);
1558 req
->params
.op_code
= cpu_to_le32(flash_opcode
);
1559 req
->params
.data_buf_size
= cpu_to_le32(buf_size
);
1561 be_mcc_notify(adapter
);
1562 spin_unlock_bh(&adapter
->mcc_lock
);
1564 if (!wait_for_completion_timeout(&adapter
->flash_compl
,
1565 msecs_to_jiffies(12000)))
1568 status
= adapter
->flash_status
;
1573 spin_unlock_bh(&adapter
->mcc_lock
);
1577 int be_cmd_get_flash_crc(struct be_adapter
*adapter
, u8
*flashed_crc
,
1580 struct be_mcc_wrb
*wrb
;
1581 struct be_cmd_write_flashrom
*req
;
1584 spin_lock_bh(&adapter
->mcc_lock
);
1586 wrb
= wrb_from_mccq(adapter
);
1591 req
= embedded_payload(wrb
);
1593 be_wrb_hdr_prepare(wrb
, sizeof(*req
)+4, true, 0,
1594 OPCODE_COMMON_READ_FLASHROM
);
1596 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1597 OPCODE_COMMON_READ_FLASHROM
, sizeof(*req
)+4);
1599 req
->params
.op_type
= cpu_to_le32(IMG_TYPE_REDBOOT
);
1600 req
->params
.op_code
= cpu_to_le32(FLASHROM_OPER_REPORT
);
1601 req
->params
.offset
= cpu_to_le32(offset
);
1602 req
->params
.data_buf_size
= cpu_to_le32(0x4);
1604 status
= be_mcc_notify_wait(adapter
);
1606 memcpy(flashed_crc
, req
->params
.data_buf
, 4);
1609 spin_unlock_bh(&adapter
->mcc_lock
);
1613 int be_cmd_enable_magic_wol(struct be_adapter
*adapter
, u8
*mac
,
1614 struct be_dma_mem
*nonemb_cmd
)
1616 struct be_mcc_wrb
*wrb
;
1617 struct be_cmd_req_acpi_wol_magic_config
*req
;
1621 spin_lock_bh(&adapter
->mcc_lock
);
1623 wrb
= wrb_from_mccq(adapter
);
1628 req
= nonemb_cmd
->va
;
1629 sge
= nonembedded_sgl(wrb
);
1631 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1632 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
);
1634 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1635 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
, sizeof(*req
));
1636 memcpy(req
->magic_mac
, mac
, ETH_ALEN
);
1638 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1639 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1640 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1642 status
= be_mcc_notify_wait(adapter
);
1645 spin_unlock_bh(&adapter
->mcc_lock
);
1649 int be_cmd_set_loopback(struct be_adapter
*adapter
, u8 port_num
,
1650 u8 loopback_type
, u8 enable
)
1652 struct be_mcc_wrb
*wrb
;
1653 struct be_cmd_req_set_lmode
*req
;
1656 spin_lock_bh(&adapter
->mcc_lock
);
1658 wrb
= wrb_from_mccq(adapter
);
1664 req
= embedded_payload(wrb
);
1666 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1667 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
);
1669 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1670 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
1673 req
->src_port
= port_num
;
1674 req
->dest_port
= port_num
;
1675 req
->loopback_type
= loopback_type
;
1676 req
->loopback_state
= enable
;
1678 status
= be_mcc_notify_wait(adapter
);
1680 spin_unlock_bh(&adapter
->mcc_lock
);
1684 int be_cmd_loopback_test(struct be_adapter
*adapter
, u32 port_num
,
1685 u32 loopback_type
, u32 pkt_size
, u32 num_pkts
, u64 pattern
)
1687 struct be_mcc_wrb
*wrb
;
1688 struct be_cmd_req_loopback_test
*req
;
1691 spin_lock_bh(&adapter
->mcc_lock
);
1693 wrb
= wrb_from_mccq(adapter
);
1699 req
= embedded_payload(wrb
);
1701 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1702 OPCODE_LOWLEVEL_LOOPBACK_TEST
);
1704 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1705 OPCODE_LOWLEVEL_LOOPBACK_TEST
, sizeof(*req
));
1706 req
->hdr
.timeout
= cpu_to_le32(4);
1708 req
->pattern
= cpu_to_le64(pattern
);
1709 req
->src_port
= cpu_to_le32(port_num
);
1710 req
->dest_port
= cpu_to_le32(port_num
);
1711 req
->pkt_size
= cpu_to_le32(pkt_size
);
1712 req
->num_pkts
= cpu_to_le32(num_pkts
);
1713 req
->loopback_type
= cpu_to_le32(loopback_type
);
1715 status
= be_mcc_notify_wait(adapter
);
1717 struct be_cmd_resp_loopback_test
*resp
= embedded_payload(wrb
);
1718 status
= le32_to_cpu(resp
->status
);
1722 spin_unlock_bh(&adapter
->mcc_lock
);
1726 int be_cmd_ddr_dma_test(struct be_adapter
*adapter
, u64 pattern
,
1727 u32 byte_cnt
, struct be_dma_mem
*cmd
)
1729 struct be_mcc_wrb
*wrb
;
1730 struct be_cmd_req_ddrdma_test
*req
;
1735 spin_lock_bh(&adapter
->mcc_lock
);
1737 wrb
= wrb_from_mccq(adapter
);
1743 sge
= nonembedded_sgl(wrb
);
1744 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
1745 OPCODE_LOWLEVEL_HOST_DDR_DMA
);
1746 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
1747 OPCODE_LOWLEVEL_HOST_DDR_DMA
, cmd
->size
);
1749 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1750 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1751 sge
->len
= cpu_to_le32(cmd
->size
);
1753 req
->pattern
= cpu_to_le64(pattern
);
1754 req
->byte_count
= cpu_to_le32(byte_cnt
);
1755 for (i
= 0; i
< byte_cnt
; i
++) {
1756 req
->snd_buff
[i
] = (u8
)(pattern
>> (j
*8));
1762 status
= be_mcc_notify_wait(adapter
);
1765 struct be_cmd_resp_ddrdma_test
*resp
;
1767 if ((memcmp(resp
->rcv_buff
, req
->snd_buff
, byte_cnt
) != 0) ||
1774 spin_unlock_bh(&adapter
->mcc_lock
);
1778 int be_cmd_get_seeprom_data(struct be_adapter
*adapter
,
1779 struct be_dma_mem
*nonemb_cmd
)
1781 struct be_mcc_wrb
*wrb
;
1782 struct be_cmd_req_seeprom_read
*req
;
1786 spin_lock_bh(&adapter
->mcc_lock
);
1788 wrb
= wrb_from_mccq(adapter
);
1789 req
= nonemb_cmd
->va
;
1790 sge
= nonembedded_sgl(wrb
);
1792 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1793 OPCODE_COMMON_SEEPROM_READ
);
1795 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1796 OPCODE_COMMON_SEEPROM_READ
, sizeof(*req
));
1798 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1799 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1800 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1802 status
= be_mcc_notify_wait(adapter
);
1804 spin_unlock_bh(&adapter
->mcc_lock
);
1808 int be_cmd_get_phy_info(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
)
1810 struct be_mcc_wrb
*wrb
;
1811 struct be_cmd_req_get_phy_info
*req
;
1815 spin_lock_bh(&adapter
->mcc_lock
);
1817 wrb
= wrb_from_mccq(adapter
);
1824 sge
= nonembedded_sgl(wrb
);
1826 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1827 OPCODE_COMMON_GET_PHY_DETAILS
);
1829 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1830 OPCODE_COMMON_GET_PHY_DETAILS
,
1833 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
1834 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
1835 sge
->len
= cpu_to_le32(cmd
->size
);
1837 status
= be_mcc_notify_wait(adapter
);
1839 spin_unlock_bh(&adapter
->mcc_lock
);
1843 int be_cmd_set_qos(struct be_adapter
*adapter
, u32 bps
, u32 domain
)
1845 struct be_mcc_wrb
*wrb
;
1846 struct be_cmd_req_set_qos
*req
;
1849 spin_lock_bh(&adapter
->mcc_lock
);
1851 wrb
= wrb_from_mccq(adapter
);
1857 req
= embedded_payload(wrb
);
1859 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1860 OPCODE_COMMON_SET_QOS
);
1862 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1863 OPCODE_COMMON_SET_QOS
, sizeof(*req
));
1865 req
->hdr
.domain
= domain
;
1866 req
->valid_bits
= BE_QOS_BITS_NIC
;
1867 req
->max_bps_nic
= bps
;
1869 status
= be_mcc_notify_wait(adapter
);
1872 spin_unlock_bh(&adapter
->mcc_lock
);