2 * Copyright (C) 2005 - 2011 Emulex
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@emulex.com
15 * Costa Mesa, CA 92626
21 /* Must be a power of 2 or else MODULO will BUG_ON */
22 static int be_get_temp_freq
= 32;
24 static void be_mcc_notify(struct be_adapter
*adapter
)
26 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
29 if (adapter
->eeh_err
) {
30 dev_info(&adapter
->pdev
->dev
,
31 "Error in Card Detected! Cannot issue commands\n");
35 val
|= mccq
->id
& DB_MCCQ_RING_ID_MASK
;
36 val
|= 1 << DB_MCCQ_NUM_POSTED_SHIFT
;
39 iowrite32(val
, adapter
->db
+ DB_MCCQ_OFFSET
);
42 /* To check if valid bit is set, check the entire word as we don't know
43 * the endianness of the data (old entry is host endian while a new entry is
45 static inline bool be_mcc_compl_is_new(struct be_mcc_compl
*compl)
47 if (compl->flags
!= 0) {
48 compl->flags
= le32_to_cpu(compl->flags
);
49 BUG_ON((compl->flags
& CQE_FLAGS_VALID_MASK
) == 0);
56 /* Need to reset the entire word that houses the valid bit */
57 static inline void be_mcc_compl_use(struct be_mcc_compl
*compl)
62 static int be_mcc_compl_process(struct be_adapter
*adapter
,
63 struct be_mcc_compl
*compl)
65 u16 compl_status
, extd_status
;
67 /* Just swap the status to host endian; mcc tag is opaquely copied
69 be_dws_le_to_cpu(compl, 4);
71 compl_status
= (compl->status
>> CQE_STATUS_COMPL_SHIFT
) &
72 CQE_STATUS_COMPL_MASK
;
74 if (((compl->tag0
== OPCODE_COMMON_WRITE_FLASHROM
) ||
75 (compl->tag0
== OPCODE_COMMON_WRITE_OBJECT
)) &&
76 (compl->tag1
== CMD_SUBSYSTEM_COMMON
)) {
77 adapter
->flash_status
= compl_status
;
78 complete(&adapter
->flash_compl
);
81 if (compl_status
== MCC_STATUS_SUCCESS
) {
82 if (((compl->tag0
== OPCODE_ETH_GET_STATISTICS
) ||
83 (compl->tag0
== OPCODE_ETH_GET_PPORT_STATS
)) &&
84 (compl->tag1
== CMD_SUBSYSTEM_ETH
)) {
85 if (adapter
->generation
== BE_GEN3
) {
86 if (lancer_chip(adapter
)) {
87 struct lancer_cmd_resp_pport_stats
88 *resp
= adapter
->stats_cmd
.va
;
89 be_dws_le_to_cpu(&resp
->pport_stats
,
90 sizeof(resp
->pport_stats
));
92 struct be_cmd_resp_get_stats_v1
*resp
=
93 adapter
->stats_cmd
.va
;
95 be_dws_le_to_cpu(&resp
->hw_stats
,
96 sizeof(resp
->hw_stats
));
99 struct be_cmd_resp_get_stats_v0
*resp
=
100 adapter
->stats_cmd
.va
;
102 be_dws_le_to_cpu(&resp
->hw_stats
,
103 sizeof(resp
->hw_stats
));
105 be_parse_stats(adapter
);
106 netdev_stats_update(adapter
);
107 adapter
->stats_cmd_sent
= false;
110 if (compl_status
== MCC_STATUS_NOT_SUPPORTED
||
111 compl_status
== MCC_STATUS_ILLEGAL_REQUEST
)
114 if (compl_status
== MCC_STATUS_UNAUTHORIZED_REQUEST
) {
115 dev_warn(&adapter
->pdev
->dev
, "This domain(VM) is not "
116 "permitted to execute this cmd (opcode %d)\n",
119 extd_status
= (compl->status
>> CQE_STATUS_EXTD_SHIFT
) &
120 CQE_STATUS_EXTD_MASK
;
121 dev_err(&adapter
->pdev
->dev
, "Cmd (opcode %d) failed:"
122 "status %d, extd-status %d\n",
123 compl->tag0
, compl_status
, extd_status
);
130 /* Link state evt is a string of bytes; no need for endian swapping */
131 static void be_async_link_state_process(struct be_adapter
*adapter
,
132 struct be_async_event_link_state
*evt
)
134 be_link_status_update(adapter
,
135 evt
->port_link_status
== ASYNC_EVENT_LINK_UP
);
138 /* Grp5 CoS Priority evt */
139 static void be_async_grp5_cos_priority_process(struct be_adapter
*adapter
,
140 struct be_async_event_grp5_cos_priority
*evt
)
143 adapter
->vlan_prio_bmap
= evt
->available_priority_bmap
;
144 adapter
->recommended_prio
&= ~VLAN_PRIO_MASK
;
145 adapter
->recommended_prio
=
146 evt
->reco_default_priority
<< VLAN_PRIO_SHIFT
;
150 /* Grp5 QOS Speed evt */
151 static void be_async_grp5_qos_speed_process(struct be_adapter
*adapter
,
152 struct be_async_event_grp5_qos_link_speed
*evt
)
154 if (evt
->physical_port
== adapter
->port_num
) {
155 /* qos_link_speed is in units of 10 Mbps */
156 adapter
->link_speed
= evt
->qos_link_speed
* 10;
161 static void be_async_grp5_pvid_state_process(struct be_adapter
*adapter
,
162 struct be_async_event_grp5_pvid_state
*evt
)
165 adapter
->pvid
= le16_to_cpu(evt
->tag
);
170 static void be_async_grp5_evt_process(struct be_adapter
*adapter
,
171 u32 trailer
, struct be_mcc_compl
*evt
)
175 event_type
= (trailer
>> ASYNC_TRAILER_EVENT_TYPE_SHIFT
) &
176 ASYNC_TRAILER_EVENT_TYPE_MASK
;
178 switch (event_type
) {
179 case ASYNC_EVENT_COS_PRIORITY
:
180 be_async_grp5_cos_priority_process(adapter
,
181 (struct be_async_event_grp5_cos_priority
*)evt
);
183 case ASYNC_EVENT_QOS_SPEED
:
184 be_async_grp5_qos_speed_process(adapter
,
185 (struct be_async_event_grp5_qos_link_speed
*)evt
);
187 case ASYNC_EVENT_PVID_STATE
:
188 be_async_grp5_pvid_state_process(adapter
,
189 (struct be_async_event_grp5_pvid_state
*)evt
);
192 dev_warn(&adapter
->pdev
->dev
, "Unknown grp5 event!\n");
197 static inline bool is_link_state_evt(u32 trailer
)
199 return ((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
200 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
201 ASYNC_EVENT_CODE_LINK_STATE
;
204 static inline bool is_grp5_evt(u32 trailer
)
206 return (((trailer
>> ASYNC_TRAILER_EVENT_CODE_SHIFT
) &
207 ASYNC_TRAILER_EVENT_CODE_MASK
) ==
208 ASYNC_EVENT_CODE_GRP_5
);
211 static struct be_mcc_compl
*be_mcc_compl_get(struct be_adapter
*adapter
)
213 struct be_queue_info
*mcc_cq
= &adapter
->mcc_obj
.cq
;
214 struct be_mcc_compl
*compl = queue_tail_node(mcc_cq
);
216 if (be_mcc_compl_is_new(compl)) {
217 queue_tail_inc(mcc_cq
);
223 void be_async_mcc_enable(struct be_adapter
*adapter
)
225 spin_lock_bh(&adapter
->mcc_cq_lock
);
227 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, true, 0);
228 adapter
->mcc_obj
.rearm_cq
= true;
230 spin_unlock_bh(&adapter
->mcc_cq_lock
);
233 void be_async_mcc_disable(struct be_adapter
*adapter
)
235 adapter
->mcc_obj
.rearm_cq
= false;
238 int be_process_mcc(struct be_adapter
*adapter
, int *status
)
240 struct be_mcc_compl
*compl;
242 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
244 spin_lock_bh(&adapter
->mcc_cq_lock
);
245 while ((compl = be_mcc_compl_get(adapter
))) {
246 if (compl->flags
& CQE_FLAGS_ASYNC_MASK
) {
247 /* Interpret flags as an async trailer */
248 if (is_link_state_evt(compl->flags
))
249 be_async_link_state_process(adapter
,
250 (struct be_async_event_link_state
*) compl);
251 else if (is_grp5_evt(compl->flags
))
252 be_async_grp5_evt_process(adapter
,
253 compl->flags
, compl);
254 } else if (compl->flags
& CQE_FLAGS_COMPLETED_MASK
) {
255 *status
= be_mcc_compl_process(adapter
, compl);
256 atomic_dec(&mcc_obj
->q
.used
);
258 be_mcc_compl_use(compl);
262 spin_unlock_bh(&adapter
->mcc_cq_lock
);
266 /* Wait till no more pending mcc requests are present */
267 static int be_mcc_wait_compl(struct be_adapter
*adapter
)
269 #define mcc_timeout 120000 /* 12s timeout */
270 int i
, num
, status
= 0;
271 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
273 if (adapter
->eeh_err
)
276 for (i
= 0; i
< mcc_timeout
; i
++) {
277 num
= be_process_mcc(adapter
, &status
);
279 be_cq_notify(adapter
, mcc_obj
->cq
.id
,
280 mcc_obj
->rearm_cq
, num
);
282 if (atomic_read(&mcc_obj
->q
.used
) == 0)
286 if (i
== mcc_timeout
) {
287 dev_err(&adapter
->pdev
->dev
, "mccq poll timed out\n");
293 /* Notify MCC requests and wait for completion */
294 static int be_mcc_notify_wait(struct be_adapter
*adapter
)
296 be_mcc_notify(adapter
);
297 return be_mcc_wait_compl(adapter
);
300 static int be_mbox_db_ready_wait(struct be_adapter
*adapter
, void __iomem
*db
)
305 if (adapter
->eeh_err
) {
306 dev_err(&adapter
->pdev
->dev
,
307 "Error detected in card.Cannot issue commands\n");
312 ready
= ioread32(db
);
313 if (ready
== 0xffffffff) {
314 dev_err(&adapter
->pdev
->dev
,
315 "pci slot disconnected\n");
319 ready
&= MPU_MAILBOX_DB_RDY_MASK
;
324 dev_err(&adapter
->pdev
->dev
, "mbox poll timed out\n");
325 if (!lancer_chip(adapter
))
326 be_detect_dump_ue(adapter
);
338 * Insert the mailbox address into the doorbell in two steps
339 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
341 static int be_mbox_notify_wait(struct be_adapter
*adapter
)
345 void __iomem
*db
= adapter
->db
+ MPU_MAILBOX_DB_OFFSET
;
346 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
347 struct be_mcc_mailbox
*mbox
= mbox_mem
->va
;
348 struct be_mcc_compl
*compl = &mbox
->compl;
350 /* wait for ready to be set */
351 status
= be_mbox_db_ready_wait(adapter
, db
);
355 val
|= MPU_MAILBOX_DB_HI_MASK
;
356 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
357 val
|= (upper_32_bits(mbox_mem
->dma
) >> 2) << 2;
360 /* wait for ready to be set */
361 status
= be_mbox_db_ready_wait(adapter
, db
);
366 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
367 val
|= (u32
)(mbox_mem
->dma
>> 4) << 2;
370 status
= be_mbox_db_ready_wait(adapter
, db
);
374 /* A cq entry has been made now */
375 if (be_mcc_compl_is_new(compl)) {
376 status
= be_mcc_compl_process(adapter
, &mbox
->compl);
377 be_mcc_compl_use(compl);
381 dev_err(&adapter
->pdev
->dev
, "invalid mailbox completion\n");
387 static int be_POST_stage_get(struct be_adapter
*adapter
, u16
*stage
)
391 if (lancer_chip(adapter
))
392 sem
= ioread32(adapter
->db
+ MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET
);
394 sem
= ioread32(adapter
->csr
+ MPU_EP_SEMAPHORE_OFFSET
);
396 *stage
= sem
& EP_SEMAPHORE_POST_STAGE_MASK
;
397 if ((sem
>> EP_SEMAPHORE_POST_ERR_SHIFT
) & EP_SEMAPHORE_POST_ERR_MASK
)
403 int be_cmd_POST(struct be_adapter
*adapter
)
406 int status
, timeout
= 0;
407 struct device
*dev
= &adapter
->pdev
->dev
;
410 status
= be_POST_stage_get(adapter
, &stage
);
412 dev_err(dev
, "POST error; stage=0x%x\n", stage
);
414 } else if (stage
!= POST_STAGE_ARMFW_RDY
) {
415 if (msleep_interruptible(2000)) {
416 dev_err(dev
, "Waiting for POST aborted\n");
423 } while (timeout
< 40);
425 dev_err(dev
, "POST timeout; stage=0x%x\n", stage
);
429 static inline void *embedded_payload(struct be_mcc_wrb
*wrb
)
431 return wrb
->payload
.embedded_payload
;
434 static inline struct be_sge
*nonembedded_sgl(struct be_mcc_wrb
*wrb
)
436 return &wrb
->payload
.sgl
[0];
439 /* Don't touch the hdr after it's prepared */
440 static void be_wrb_hdr_prepare(struct be_mcc_wrb
*wrb
, int payload_len
,
441 bool embedded
, u8 sge_cnt
, u32 opcode
)
444 wrb
->embedded
|= MCC_WRB_EMBEDDED_MASK
;
446 wrb
->embedded
|= (sge_cnt
& MCC_WRB_SGE_CNT_MASK
) <<
447 MCC_WRB_SGE_CNT_SHIFT
;
448 wrb
->payload_length
= payload_len
;
450 be_dws_cpu_to_le(wrb
, 8);
453 /* Don't touch the hdr after it's prepared */
454 static void be_cmd_hdr_prepare(struct be_cmd_req_hdr
*req_hdr
,
455 u8 subsystem
, u8 opcode
, int cmd_len
)
457 req_hdr
->opcode
= opcode
;
458 req_hdr
->subsystem
= subsystem
;
459 req_hdr
->request_length
= cpu_to_le32(cmd_len
- sizeof(*req_hdr
));
460 req_hdr
->version
= 0;
463 static void be_cmd_page_addrs_prepare(struct phys_addr
*pages
, u32 max_pages
,
464 struct be_dma_mem
*mem
)
466 int i
, buf_pages
= min(PAGES_4K_SPANNED(mem
->va
, mem
->size
), max_pages
);
467 u64 dma
= (u64
)mem
->dma
;
469 for (i
= 0; i
< buf_pages
; i
++) {
470 pages
[i
].lo
= cpu_to_le32(dma
& 0xFFFFFFFF);
471 pages
[i
].hi
= cpu_to_le32(upper_32_bits(dma
));
476 /* Converts interrupt delay in microseconds to multiplier value */
477 static u32
eq_delay_to_mult(u32 usec_delay
)
479 #define MAX_INTR_RATE 651042
480 const u32 round
= 10;
486 u32 interrupt_rate
= 1000000 / usec_delay
;
487 /* Max delay, corresponding to the lowest interrupt rate */
488 if (interrupt_rate
== 0)
491 multiplier
= (MAX_INTR_RATE
- interrupt_rate
) * round
;
492 multiplier
/= interrupt_rate
;
493 /* Round the multiplier to the closest value.*/
494 multiplier
= (multiplier
+ round
/2) / round
;
495 multiplier
= min(multiplier
, (u32
)1023);
501 static inline struct be_mcc_wrb
*wrb_from_mbox(struct be_adapter
*adapter
)
503 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
504 struct be_mcc_wrb
*wrb
505 = &((struct be_mcc_mailbox
*)(mbox_mem
->va
))->wrb
;
506 memset(wrb
, 0, sizeof(*wrb
));
510 static struct be_mcc_wrb
*wrb_from_mccq(struct be_adapter
*adapter
)
512 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
513 struct be_mcc_wrb
*wrb
;
515 if (atomic_read(&mccq
->used
) >= mccq
->len
) {
516 dev_err(&adapter
->pdev
->dev
, "Out of MCCQ wrbs\n");
520 wrb
= queue_head_node(mccq
);
521 queue_head_inc(mccq
);
522 atomic_inc(&mccq
->used
);
523 memset(wrb
, 0, sizeof(*wrb
));
527 /* Tell fw we're about to start firing cmds by writing a
528 * special pattern across the wrb hdr; uses mbox
530 int be_cmd_fw_init(struct be_adapter
*adapter
)
535 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
538 wrb
= (u8
*)wrb_from_mbox(adapter
);
548 status
= be_mbox_notify_wait(adapter
);
550 mutex_unlock(&adapter
->mbox_lock
);
554 /* Tell fw we're done with firing cmds by writing a
555 * special pattern across the wrb hdr; uses mbox
557 int be_cmd_fw_clean(struct be_adapter
*adapter
)
562 if (adapter
->eeh_err
)
565 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
568 wrb
= (u8
*)wrb_from_mbox(adapter
);
578 status
= be_mbox_notify_wait(adapter
);
580 mutex_unlock(&adapter
->mbox_lock
);
583 int be_cmd_eq_create(struct be_adapter
*adapter
,
584 struct be_queue_info
*eq
, int eq_delay
)
586 struct be_mcc_wrb
*wrb
;
587 struct be_cmd_req_eq_create
*req
;
588 struct be_dma_mem
*q_mem
= &eq
->dma_mem
;
591 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
594 wrb
= wrb_from_mbox(adapter
);
595 req
= embedded_payload(wrb
);
597 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_COMMON_EQ_CREATE
);
599 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
600 OPCODE_COMMON_EQ_CREATE
, sizeof(*req
));
602 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
604 AMAP_SET_BITS(struct amap_eq_context
, valid
, req
->context
, 1);
606 AMAP_SET_BITS(struct amap_eq_context
, size
, req
->context
, 0);
607 AMAP_SET_BITS(struct amap_eq_context
, count
, req
->context
,
608 __ilog2_u32(eq
->len
/256));
609 AMAP_SET_BITS(struct amap_eq_context
, delaymult
, req
->context
,
610 eq_delay_to_mult(eq_delay
));
611 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
613 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
615 status
= be_mbox_notify_wait(adapter
);
617 struct be_cmd_resp_eq_create
*resp
= embedded_payload(wrb
);
618 eq
->id
= le16_to_cpu(resp
->eq_id
);
622 mutex_unlock(&adapter
->mbox_lock
);
627 int be_cmd_mac_addr_query(struct be_adapter
*adapter
, u8
*mac_addr
,
628 u8 type
, bool permanent
, u32 if_handle
)
630 struct be_mcc_wrb
*wrb
;
631 struct be_cmd_req_mac_query
*req
;
634 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
637 wrb
= wrb_from_mbox(adapter
);
638 req
= embedded_payload(wrb
);
640 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
641 OPCODE_COMMON_NTWK_MAC_QUERY
);
643 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
644 OPCODE_COMMON_NTWK_MAC_QUERY
, sizeof(*req
));
650 req
->if_id
= cpu_to_le16((u16
) if_handle
);
654 status
= be_mbox_notify_wait(adapter
);
656 struct be_cmd_resp_mac_query
*resp
= embedded_payload(wrb
);
657 memcpy(mac_addr
, resp
->mac
.addr
, ETH_ALEN
);
660 mutex_unlock(&adapter
->mbox_lock
);
664 /* Uses synchronous MCCQ */
665 int be_cmd_pmac_add(struct be_adapter
*adapter
, u8
*mac_addr
,
666 u32 if_id
, u32
*pmac_id
, u32 domain
)
668 struct be_mcc_wrb
*wrb
;
669 struct be_cmd_req_pmac_add
*req
;
672 spin_lock_bh(&adapter
->mcc_lock
);
674 wrb
= wrb_from_mccq(adapter
);
679 req
= embedded_payload(wrb
);
681 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
682 OPCODE_COMMON_NTWK_PMAC_ADD
);
684 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
685 OPCODE_COMMON_NTWK_PMAC_ADD
, sizeof(*req
));
687 req
->hdr
.domain
= domain
;
688 req
->if_id
= cpu_to_le32(if_id
);
689 memcpy(req
->mac_address
, mac_addr
, ETH_ALEN
);
691 status
= be_mcc_notify_wait(adapter
);
693 struct be_cmd_resp_pmac_add
*resp
= embedded_payload(wrb
);
694 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
698 spin_unlock_bh(&adapter
->mcc_lock
);
702 /* Uses synchronous MCCQ */
703 int be_cmd_pmac_del(struct be_adapter
*adapter
, u32 if_id
, u32 pmac_id
, u32 dom
)
705 struct be_mcc_wrb
*wrb
;
706 struct be_cmd_req_pmac_del
*req
;
709 spin_lock_bh(&adapter
->mcc_lock
);
711 wrb
= wrb_from_mccq(adapter
);
716 req
= embedded_payload(wrb
);
718 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
719 OPCODE_COMMON_NTWK_PMAC_DEL
);
721 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
722 OPCODE_COMMON_NTWK_PMAC_DEL
, sizeof(*req
));
724 req
->hdr
.domain
= dom
;
725 req
->if_id
= cpu_to_le32(if_id
);
726 req
->pmac_id
= cpu_to_le32(pmac_id
);
728 status
= be_mcc_notify_wait(adapter
);
731 spin_unlock_bh(&adapter
->mcc_lock
);
736 int be_cmd_cq_create(struct be_adapter
*adapter
,
737 struct be_queue_info
*cq
, struct be_queue_info
*eq
,
738 bool sol_evts
, bool no_delay
, int coalesce_wm
)
740 struct be_mcc_wrb
*wrb
;
741 struct be_cmd_req_cq_create
*req
;
742 struct be_dma_mem
*q_mem
= &cq
->dma_mem
;
746 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
749 wrb
= wrb_from_mbox(adapter
);
750 req
= embedded_payload(wrb
);
751 ctxt
= &req
->context
;
753 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
754 OPCODE_COMMON_CQ_CREATE
);
756 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
757 OPCODE_COMMON_CQ_CREATE
, sizeof(*req
));
759 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
760 if (lancer_chip(adapter
)) {
761 req
->hdr
.version
= 2;
762 req
->page_size
= 1; /* 1 for 4K */
763 AMAP_SET_BITS(struct amap_cq_context_lancer
, nodelay
, ctxt
,
765 AMAP_SET_BITS(struct amap_cq_context_lancer
, count
, ctxt
,
766 __ilog2_u32(cq
->len
/256));
767 AMAP_SET_BITS(struct amap_cq_context_lancer
, valid
, ctxt
, 1);
768 AMAP_SET_BITS(struct amap_cq_context_lancer
, eventable
,
770 AMAP_SET_BITS(struct amap_cq_context_lancer
, eqid
,
772 AMAP_SET_BITS(struct amap_cq_context_lancer
, armed
, ctxt
, 1);
774 AMAP_SET_BITS(struct amap_cq_context_be
, coalescwm
, ctxt
,
776 AMAP_SET_BITS(struct amap_cq_context_be
, nodelay
,
778 AMAP_SET_BITS(struct amap_cq_context_be
, count
, ctxt
,
779 __ilog2_u32(cq
->len
/256));
780 AMAP_SET_BITS(struct amap_cq_context_be
, valid
, ctxt
, 1);
781 AMAP_SET_BITS(struct amap_cq_context_be
, solevent
,
783 AMAP_SET_BITS(struct amap_cq_context_be
, eventable
, ctxt
, 1);
784 AMAP_SET_BITS(struct amap_cq_context_be
, eqid
, ctxt
, eq
->id
);
785 AMAP_SET_BITS(struct amap_cq_context_be
, armed
, ctxt
, 1);
788 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
790 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
792 status
= be_mbox_notify_wait(adapter
);
794 struct be_cmd_resp_cq_create
*resp
= embedded_payload(wrb
);
795 cq
->id
= le16_to_cpu(resp
->cq_id
);
799 mutex_unlock(&adapter
->mbox_lock
);
804 static u32
be_encoded_q_len(int q_len
)
806 u32 len_encoded
= fls(q_len
); /* log2(len) + 1 */
807 if (len_encoded
== 16)
812 int be_cmd_mccq_ext_create(struct be_adapter
*adapter
,
813 struct be_queue_info
*mccq
,
814 struct be_queue_info
*cq
)
816 struct be_mcc_wrb
*wrb
;
817 struct be_cmd_req_mcc_ext_create
*req
;
818 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
822 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
825 wrb
= wrb_from_mbox(adapter
);
826 req
= embedded_payload(wrb
);
827 ctxt
= &req
->context
;
829 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
830 OPCODE_COMMON_MCC_CREATE_EXT
);
832 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
833 OPCODE_COMMON_MCC_CREATE_EXT
, sizeof(*req
));
835 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
836 if (lancer_chip(adapter
)) {
837 req
->hdr
.version
= 1;
838 req
->cq_id
= cpu_to_le16(cq
->id
);
840 AMAP_SET_BITS(struct amap_mcc_context_lancer
, ring_size
, ctxt
,
841 be_encoded_q_len(mccq
->len
));
842 AMAP_SET_BITS(struct amap_mcc_context_lancer
, valid
, ctxt
, 1);
843 AMAP_SET_BITS(struct amap_mcc_context_lancer
, async_cq_id
,
845 AMAP_SET_BITS(struct amap_mcc_context_lancer
, async_cq_valid
,
849 AMAP_SET_BITS(struct amap_mcc_context_be
, valid
, ctxt
, 1);
850 AMAP_SET_BITS(struct amap_mcc_context_be
, ring_size
, ctxt
,
851 be_encoded_q_len(mccq
->len
));
852 AMAP_SET_BITS(struct amap_mcc_context_be
, cq_id
, ctxt
, cq
->id
);
855 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
856 req
->async_event_bitmap
[0] = cpu_to_le32(0x00000022);
857 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
859 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
861 status
= be_mbox_notify_wait(adapter
);
863 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
864 mccq
->id
= le16_to_cpu(resp
->id
);
865 mccq
->created
= true;
867 mutex_unlock(&adapter
->mbox_lock
);
872 int be_cmd_mccq_org_create(struct be_adapter
*adapter
,
873 struct be_queue_info
*mccq
,
874 struct be_queue_info
*cq
)
876 struct be_mcc_wrb
*wrb
;
877 struct be_cmd_req_mcc_create
*req
;
878 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
882 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
885 wrb
= wrb_from_mbox(adapter
);
886 req
= embedded_payload(wrb
);
887 ctxt
= &req
->context
;
889 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
890 OPCODE_COMMON_MCC_CREATE
);
892 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
893 OPCODE_COMMON_MCC_CREATE
, sizeof(*req
));
895 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
897 AMAP_SET_BITS(struct amap_mcc_context_be
, valid
, ctxt
, 1);
898 AMAP_SET_BITS(struct amap_mcc_context_be
, ring_size
, ctxt
,
899 be_encoded_q_len(mccq
->len
));
900 AMAP_SET_BITS(struct amap_mcc_context_be
, cq_id
, ctxt
, cq
->id
);
902 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
904 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
906 status
= be_mbox_notify_wait(adapter
);
908 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
909 mccq
->id
= le16_to_cpu(resp
->id
);
910 mccq
->created
= true;
913 mutex_unlock(&adapter
->mbox_lock
);
917 int be_cmd_mccq_create(struct be_adapter
*adapter
,
918 struct be_queue_info
*mccq
,
919 struct be_queue_info
*cq
)
923 status
= be_cmd_mccq_ext_create(adapter
, mccq
, cq
);
924 if (status
&& !lancer_chip(adapter
)) {
925 dev_warn(&adapter
->pdev
->dev
, "Upgrade to F/W ver 2.102.235.0 "
926 "or newer to avoid conflicting priorities between NIC "
928 status
= be_cmd_mccq_org_create(adapter
, mccq
, cq
);
933 int be_cmd_txq_create(struct be_adapter
*adapter
,
934 struct be_queue_info
*txq
,
935 struct be_queue_info
*cq
)
937 struct be_mcc_wrb
*wrb
;
938 struct be_cmd_req_eth_tx_create
*req
;
939 struct be_dma_mem
*q_mem
= &txq
->dma_mem
;
943 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
946 wrb
= wrb_from_mbox(adapter
);
947 req
= embedded_payload(wrb
);
948 ctxt
= &req
->context
;
950 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
951 OPCODE_ETH_TX_CREATE
);
953 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_TX_CREATE
,
956 if (lancer_chip(adapter
)) {
957 req
->hdr
.version
= 1;
958 AMAP_SET_BITS(struct amap_tx_context
, if_id
, ctxt
,
962 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
963 req
->ulp_num
= BE_ULP1_NUM
;
964 req
->type
= BE_ETH_TX_RING_TYPE_STANDARD
;
966 AMAP_SET_BITS(struct amap_tx_context
, tx_ring_size
, ctxt
,
967 be_encoded_q_len(txq
->len
));
968 AMAP_SET_BITS(struct amap_tx_context
, ctx_valid
, ctxt
, 1);
969 AMAP_SET_BITS(struct amap_tx_context
, cq_id_send
, ctxt
, cq
->id
);
971 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
973 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
975 status
= be_mbox_notify_wait(adapter
);
977 struct be_cmd_resp_eth_tx_create
*resp
= embedded_payload(wrb
);
978 txq
->id
= le16_to_cpu(resp
->cid
);
982 mutex_unlock(&adapter
->mbox_lock
);
988 int be_cmd_rxq_create(struct be_adapter
*adapter
,
989 struct be_queue_info
*rxq
, u16 cq_id
, u16 frag_size
,
990 u16 max_frame_size
, u32 if_id
, u32 rss
, u8
*rss_id
)
992 struct be_mcc_wrb
*wrb
;
993 struct be_cmd_req_eth_rx_create
*req
;
994 struct be_dma_mem
*q_mem
= &rxq
->dma_mem
;
997 spin_lock_bh(&adapter
->mcc_lock
);
999 wrb
= wrb_from_mccq(adapter
);
1004 req
= embedded_payload(wrb
);
1006 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1007 OPCODE_ETH_RX_CREATE
);
1009 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_RX_CREATE
,
1012 req
->cq_id
= cpu_to_le16(cq_id
);
1013 req
->frag_size
= fls(frag_size
) - 1;
1015 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1016 req
->interface_id
= cpu_to_le32(if_id
);
1017 req
->max_frame_size
= cpu_to_le16(max_frame_size
);
1018 req
->rss_queue
= cpu_to_le32(rss
);
1020 status
= be_mcc_notify_wait(adapter
);
1022 struct be_cmd_resp_eth_rx_create
*resp
= embedded_payload(wrb
);
1023 rxq
->id
= le16_to_cpu(resp
->id
);
1024 rxq
->created
= true;
1025 *rss_id
= resp
->rss_id
;
1029 spin_unlock_bh(&adapter
->mcc_lock
);
1033 /* Generic destroyer function for all types of queues
1036 int be_cmd_q_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
,
1039 struct be_mcc_wrb
*wrb
;
1040 struct be_cmd_req_q_destroy
*req
;
1041 u8 subsys
= 0, opcode
= 0;
1044 if (adapter
->eeh_err
)
1047 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1050 wrb
= wrb_from_mbox(adapter
);
1051 req
= embedded_payload(wrb
);
1053 switch (queue_type
) {
1055 subsys
= CMD_SUBSYSTEM_COMMON
;
1056 opcode
= OPCODE_COMMON_EQ_DESTROY
;
1059 subsys
= CMD_SUBSYSTEM_COMMON
;
1060 opcode
= OPCODE_COMMON_CQ_DESTROY
;
1063 subsys
= CMD_SUBSYSTEM_ETH
;
1064 opcode
= OPCODE_ETH_TX_DESTROY
;
1067 subsys
= CMD_SUBSYSTEM_ETH
;
1068 opcode
= OPCODE_ETH_RX_DESTROY
;
1071 subsys
= CMD_SUBSYSTEM_COMMON
;
1072 opcode
= OPCODE_COMMON_MCC_DESTROY
;
1078 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, opcode
);
1080 be_cmd_hdr_prepare(&req
->hdr
, subsys
, opcode
, sizeof(*req
));
1081 req
->id
= cpu_to_le16(q
->id
);
1083 status
= be_mbox_notify_wait(adapter
);
1087 mutex_unlock(&adapter
->mbox_lock
);
1092 int be_cmd_rxq_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
)
1094 struct be_mcc_wrb
*wrb
;
1095 struct be_cmd_req_q_destroy
*req
;
1098 spin_lock_bh(&adapter
->mcc_lock
);
1100 wrb
= wrb_from_mccq(adapter
);
1105 req
= embedded_payload(wrb
);
1107 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0, OPCODE_ETH_RX_DESTROY
);
1108 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
, OPCODE_ETH_RX_DESTROY
,
1110 req
->id
= cpu_to_le16(q
->id
);
1112 status
= be_mcc_notify_wait(adapter
);
1117 spin_unlock_bh(&adapter
->mcc_lock
);
1121 /* Create an rx filtering policy configuration on an i/f
1124 int be_cmd_if_create(struct be_adapter
*adapter
, u32 cap_flags
, u32 en_flags
,
1125 u8
*mac
, bool pmac_invalid
, u32
*if_handle
, u32
*pmac_id
,
1128 struct be_mcc_wrb
*wrb
;
1129 struct be_cmd_req_if_create
*req
;
1132 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1135 wrb
= wrb_from_mbox(adapter
);
1136 req
= embedded_payload(wrb
);
1138 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1139 OPCODE_COMMON_NTWK_INTERFACE_CREATE
);
1141 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1142 OPCODE_COMMON_NTWK_INTERFACE_CREATE
, sizeof(*req
));
1144 req
->hdr
.domain
= domain
;
1145 req
->capability_flags
= cpu_to_le32(cap_flags
);
1146 req
->enable_flags
= cpu_to_le32(en_flags
);
1147 req
->pmac_invalid
= pmac_invalid
;
1149 memcpy(req
->mac_addr
, mac
, ETH_ALEN
);
1151 status
= be_mbox_notify_wait(adapter
);
1153 struct be_cmd_resp_if_create
*resp
= embedded_payload(wrb
);
1154 *if_handle
= le32_to_cpu(resp
->interface_id
);
1156 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
1159 mutex_unlock(&adapter
->mbox_lock
);
1164 int be_cmd_if_destroy(struct be_adapter
*adapter
, u32 interface_id
, u32 domain
)
1166 struct be_mcc_wrb
*wrb
;
1167 struct be_cmd_req_if_destroy
*req
;
1170 if (adapter
->eeh_err
)
1173 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1176 wrb
= wrb_from_mbox(adapter
);
1177 req
= embedded_payload(wrb
);
1179 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1180 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
);
1182 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1183 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
, sizeof(*req
));
1185 req
->hdr
.domain
= domain
;
1186 req
->interface_id
= cpu_to_le32(interface_id
);
1188 status
= be_mbox_notify_wait(adapter
);
1190 mutex_unlock(&adapter
->mbox_lock
);
1195 /* Get stats is a non embedded command: the request is not embedded inside
1196 * WRB but is a separate dma memory block
1197 * Uses asynchronous MCC
1199 int be_cmd_get_stats(struct be_adapter
*adapter
, struct be_dma_mem
*nonemb_cmd
)
1201 struct be_mcc_wrb
*wrb
;
1202 struct be_cmd_req_hdr
*hdr
;
1206 if (MODULO(adapter
->work_counter
, be_get_temp_freq
) == 0)
1207 be_cmd_get_die_temperature(adapter
);
1209 spin_lock_bh(&adapter
->mcc_lock
);
1211 wrb
= wrb_from_mccq(adapter
);
1216 hdr
= nonemb_cmd
->va
;
1217 sge
= nonembedded_sgl(wrb
);
1219 be_wrb_hdr_prepare(wrb
, nonemb_cmd
->size
, false, 1,
1220 OPCODE_ETH_GET_STATISTICS
);
1222 be_cmd_hdr_prepare(hdr
, CMD_SUBSYSTEM_ETH
,
1223 OPCODE_ETH_GET_STATISTICS
, nonemb_cmd
->size
);
1225 if (adapter
->generation
== BE_GEN3
)
1228 wrb
->tag1
= CMD_SUBSYSTEM_ETH
;
1229 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1230 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1231 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1233 be_mcc_notify(adapter
);
1234 adapter
->stats_cmd_sent
= true;
1237 spin_unlock_bh(&adapter
->mcc_lock
);
1242 int lancer_cmd_get_pport_stats(struct be_adapter
*adapter
,
1243 struct be_dma_mem
*nonemb_cmd
)
1246 struct be_mcc_wrb
*wrb
;
1247 struct lancer_cmd_req_pport_stats
*req
;
1251 spin_lock_bh(&adapter
->mcc_lock
);
1253 wrb
= wrb_from_mccq(adapter
);
1258 req
= nonemb_cmd
->va
;
1259 sge
= nonembedded_sgl(wrb
);
1261 be_wrb_hdr_prepare(wrb
, nonemb_cmd
->size
, false, 1,
1262 OPCODE_ETH_GET_PPORT_STATS
);
1264 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1265 OPCODE_ETH_GET_PPORT_STATS
, nonemb_cmd
->size
);
1268 req
->cmd_params
.params
.pport_num
= cpu_to_le16(adapter
->port_num
);
1269 req
->cmd_params
.params
.reset_stats
= 0;
1271 wrb
->tag1
= CMD_SUBSYSTEM_ETH
;
1272 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
1273 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
1274 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
1276 be_mcc_notify(adapter
);
1277 adapter
->stats_cmd_sent
= true;
1280 spin_unlock_bh(&adapter
->mcc_lock
);
1284 /* Uses synchronous mcc */
1285 int be_cmd_link_status_query(struct be_adapter
*adapter
,
1286 bool *link_up
, u8
*mac_speed
, u16
*link_speed
, u32 dom
)
1288 struct be_mcc_wrb
*wrb
;
1289 struct be_cmd_req_link_status
*req
;
1292 spin_lock_bh(&adapter
->mcc_lock
);
1294 wrb
= wrb_from_mccq(adapter
);
1299 req
= embedded_payload(wrb
);
1303 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1304 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
);
1306 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1307 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
, sizeof(*req
));
1309 status
= be_mcc_notify_wait(adapter
);
1311 struct be_cmd_resp_link_status
*resp
= embedded_payload(wrb
);
1312 if (resp
->mac_speed
!= PHY_LINK_SPEED_ZERO
) {
1314 *link_speed
= le16_to_cpu(resp
->link_speed
);
1315 *mac_speed
= resp
->mac_speed
;
1320 spin_unlock_bh(&adapter
->mcc_lock
);
1324 /* Uses synchronous mcc */
1325 int be_cmd_get_die_temperature(struct be_adapter
*adapter
)
1327 struct be_mcc_wrb
*wrb
;
1328 struct be_cmd_req_get_cntl_addnl_attribs
*req
;
1331 spin_lock_bh(&adapter
->mcc_lock
);
1333 wrb
= wrb_from_mccq(adapter
);
1338 req
= embedded_payload(wrb
);
1340 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1341 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES
);
1343 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1344 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES
, sizeof(*req
));
1346 status
= be_mcc_notify_wait(adapter
);
1348 struct be_cmd_resp_get_cntl_addnl_attribs
*resp
=
1349 embedded_payload(wrb
);
1350 adapter
->drv_stats
.be_on_die_temperature
=
1351 resp
->on_die_temperature
;
1353 /* If IOCTL fails once, do not bother issuing it again */
1355 be_get_temp_freq
= 0;
1358 spin_unlock_bh(&adapter
->mcc_lock
);
1362 /* Uses synchronous mcc */
1363 int be_cmd_get_reg_len(struct be_adapter
*adapter
, u32
*log_size
)
1365 struct be_mcc_wrb
*wrb
;
1366 struct be_cmd_req_get_fat
*req
;
1369 spin_lock_bh(&adapter
->mcc_lock
);
1371 wrb
= wrb_from_mccq(adapter
);
1376 req
= embedded_payload(wrb
);
1378 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1379 OPCODE_COMMON_MANAGE_FAT
);
1381 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1382 OPCODE_COMMON_MANAGE_FAT
, sizeof(*req
));
1383 req
->fat_operation
= cpu_to_le32(QUERY_FAT
);
1384 status
= be_mcc_notify_wait(adapter
);
1386 struct be_cmd_resp_get_fat
*resp
= embedded_payload(wrb
);
1387 if (log_size
&& resp
->log_size
)
1388 *log_size
= le32_to_cpu(resp
->log_size
) -
1392 spin_unlock_bh(&adapter
->mcc_lock
);
1396 void be_cmd_get_regs(struct be_adapter
*adapter
, u32 buf_len
, void *buf
)
1398 struct be_dma_mem get_fat_cmd
;
1399 struct be_mcc_wrb
*wrb
;
1400 struct be_cmd_req_get_fat
*req
;
1402 u32 offset
= 0, total_size
, buf_size
,
1403 log_offset
= sizeof(u32
), payload_len
;
1409 total_size
= buf_len
;
1411 get_fat_cmd
.size
= sizeof(struct be_cmd_req_get_fat
) + 60*1024;
1412 get_fat_cmd
.va
= pci_alloc_consistent(adapter
->pdev
,
1415 if (!get_fat_cmd
.va
) {
1417 dev_err(&adapter
->pdev
->dev
,
1418 "Memory allocation failure while retrieving FAT data\n");
1422 spin_lock_bh(&adapter
->mcc_lock
);
1424 while (total_size
) {
1425 buf_size
= min(total_size
, (u32
)60*1024);
1426 total_size
-= buf_size
;
1428 wrb
= wrb_from_mccq(adapter
);
1433 req
= get_fat_cmd
.va
;
1434 sge
= nonembedded_sgl(wrb
);
1436 payload_len
= sizeof(struct be_cmd_req_get_fat
) + buf_size
;
1437 be_wrb_hdr_prepare(wrb
, payload_len
, false, 1,
1438 OPCODE_COMMON_MANAGE_FAT
);
1440 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1441 OPCODE_COMMON_MANAGE_FAT
, payload_len
);
1443 sge
->pa_hi
= cpu_to_le32(upper_32_bits(get_fat_cmd
.dma
));
1444 sge
->pa_lo
= cpu_to_le32(get_fat_cmd
.dma
& 0xFFFFFFFF);
1445 sge
->len
= cpu_to_le32(get_fat_cmd
.size
);
1447 req
->fat_operation
= cpu_to_le32(RETRIEVE_FAT
);
1448 req
->read_log_offset
= cpu_to_le32(log_offset
);
1449 req
->read_log_length
= cpu_to_le32(buf_size
);
1450 req
->data_buffer_size
= cpu_to_le32(buf_size
);
1452 status
= be_mcc_notify_wait(adapter
);
1454 struct be_cmd_resp_get_fat
*resp
= get_fat_cmd
.va
;
1455 memcpy(buf
+ offset
,
1457 resp
->read_log_length
);
1459 dev_err(&adapter
->pdev
->dev
, "FAT Table Retrieve error\n");
1463 log_offset
+= buf_size
;
1466 pci_free_consistent(adapter
->pdev
, get_fat_cmd
.size
,
1469 spin_unlock_bh(&adapter
->mcc_lock
);
1473 int be_cmd_get_fw_ver(struct be_adapter
*adapter
, char *fw_ver
)
1475 struct be_mcc_wrb
*wrb
;
1476 struct be_cmd_req_get_fw_version
*req
;
1479 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1482 wrb
= wrb_from_mbox(adapter
);
1483 req
= embedded_payload(wrb
);
1485 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1486 OPCODE_COMMON_GET_FW_VERSION
);
1488 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1489 OPCODE_COMMON_GET_FW_VERSION
, sizeof(*req
));
1491 status
= be_mbox_notify_wait(adapter
);
1493 struct be_cmd_resp_get_fw_version
*resp
= embedded_payload(wrb
);
1494 strncpy(fw_ver
, resp
->firmware_version_string
, FW_VER_LEN
);
1497 mutex_unlock(&adapter
->mbox_lock
);
1501 /* set the EQ delay interval of an EQ to specified value
1504 int be_cmd_modify_eqd(struct be_adapter
*adapter
, u32 eq_id
, u32 eqd
)
1506 struct be_mcc_wrb
*wrb
;
1507 struct be_cmd_req_modify_eq_delay
*req
;
1510 spin_lock_bh(&adapter
->mcc_lock
);
1512 wrb
= wrb_from_mccq(adapter
);
1517 req
= embedded_payload(wrb
);
1519 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1520 OPCODE_COMMON_MODIFY_EQ_DELAY
);
1522 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1523 OPCODE_COMMON_MODIFY_EQ_DELAY
, sizeof(*req
));
1525 req
->num_eq
= cpu_to_le32(1);
1526 req
->delay
[0].eq_id
= cpu_to_le32(eq_id
);
1527 req
->delay
[0].phase
= 0;
1528 req
->delay
[0].delay_multiplier
= cpu_to_le32(eqd
);
1530 be_mcc_notify(adapter
);
1533 spin_unlock_bh(&adapter
->mcc_lock
);
1537 /* Uses sycnhronous mcc */
1538 int be_cmd_vlan_config(struct be_adapter
*adapter
, u32 if_id
, u16
*vtag_array
,
1539 u32 num
, bool untagged
, bool promiscuous
)
1541 struct be_mcc_wrb
*wrb
;
1542 struct be_cmd_req_vlan_config
*req
;
1545 spin_lock_bh(&adapter
->mcc_lock
);
1547 wrb
= wrb_from_mccq(adapter
);
1552 req
= embedded_payload(wrb
);
1554 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1555 OPCODE_COMMON_NTWK_VLAN_CONFIG
);
1557 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1558 OPCODE_COMMON_NTWK_VLAN_CONFIG
, sizeof(*req
));
1560 req
->interface_id
= if_id
;
1561 req
->promiscuous
= promiscuous
;
1562 req
->untagged
= untagged
;
1563 req
->num_vlan
= num
;
1565 memcpy(req
->normal_vlan
, vtag_array
,
1566 req
->num_vlan
* sizeof(vtag_array
[0]));
1569 status
= be_mcc_notify_wait(adapter
);
1572 spin_unlock_bh(&adapter
->mcc_lock
);
1576 /* Uses MCC for this command as it may be called in BH context
1577 * Uses synchronous mcc
1579 int be_cmd_promiscuous_config(struct be_adapter
*adapter
, bool en
)
1581 struct be_mcc_wrb
*wrb
;
1582 struct be_cmd_req_rx_filter
*req
;
1583 struct be_dma_mem promiscous_cmd
;
1587 memset(&promiscous_cmd
, 0, sizeof(struct be_dma_mem
));
1588 promiscous_cmd
.size
= sizeof(struct be_cmd_req_rx_filter
);
1589 promiscous_cmd
.va
= pci_alloc_consistent(adapter
->pdev
,
1590 promiscous_cmd
.size
, &promiscous_cmd
.dma
);
1591 if (!promiscous_cmd
.va
) {
1592 dev_err(&adapter
->pdev
->dev
,
1593 "Memory allocation failure\n");
1597 spin_lock_bh(&adapter
->mcc_lock
);
1599 wrb
= wrb_from_mccq(adapter
);
1605 req
= promiscous_cmd
.va
;
1606 sge
= nonembedded_sgl(wrb
);
1608 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1609 OPCODE_COMMON_NTWK_RX_FILTER
);
1610 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1611 OPCODE_COMMON_NTWK_RX_FILTER
, sizeof(*req
));
1613 req
->if_id
= cpu_to_le32(adapter
->if_handle
);
1614 req
->if_flags_mask
= cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS
);
1616 req
->if_flags
= cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS
);
1618 sge
->pa_hi
= cpu_to_le32(upper_32_bits(promiscous_cmd
.dma
));
1619 sge
->pa_lo
= cpu_to_le32(promiscous_cmd
.dma
& 0xFFFFFFFF);
1620 sge
->len
= cpu_to_le32(promiscous_cmd
.size
);
1622 status
= be_mcc_notify_wait(adapter
);
1625 spin_unlock_bh(&adapter
->mcc_lock
);
1626 pci_free_consistent(adapter
->pdev
, promiscous_cmd
.size
,
1627 promiscous_cmd
.va
, promiscous_cmd
.dma
);
1632 * Uses MCC for this command as it may be called in BH context
1633 * (mc == NULL) => multicast promiscuous
1635 int be_cmd_multicast_set(struct be_adapter
*adapter
, u32 if_id
,
1636 struct net_device
*netdev
, struct be_dma_mem
*mem
)
1638 struct be_mcc_wrb
*wrb
;
1639 struct be_cmd_req_mcast_mac_config
*req
= mem
->va
;
1643 spin_lock_bh(&adapter
->mcc_lock
);
1645 wrb
= wrb_from_mccq(adapter
);
1650 sge
= nonembedded_sgl(wrb
);
1651 memset(req
, 0, sizeof(*req
));
1653 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
1654 OPCODE_COMMON_NTWK_MULTICAST_SET
);
1655 sge
->pa_hi
= cpu_to_le32(upper_32_bits(mem
->dma
));
1656 sge
->pa_lo
= cpu_to_le32(mem
->dma
& 0xFFFFFFFF);
1657 sge
->len
= cpu_to_le32(mem
->size
);
1659 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1660 OPCODE_COMMON_NTWK_MULTICAST_SET
, sizeof(*req
));
1662 req
->interface_id
= if_id
;
1665 struct netdev_hw_addr
*ha
;
1667 req
->num_mac
= cpu_to_le16(netdev_mc_count(netdev
));
1670 netdev_for_each_mc_addr(ha
, netdev
)
1671 memcpy(req
->mac
[i
++].byte
, ha
->addr
, ETH_ALEN
);
1673 req
->promiscuous
= 1;
1676 status
= be_mcc_notify_wait(adapter
);
1679 spin_unlock_bh(&adapter
->mcc_lock
);
1683 /* Uses synchrounous mcc */
1684 int be_cmd_set_flow_control(struct be_adapter
*adapter
, u32 tx_fc
, u32 rx_fc
)
1686 struct be_mcc_wrb
*wrb
;
1687 struct be_cmd_req_set_flow_control
*req
;
1690 spin_lock_bh(&adapter
->mcc_lock
);
1692 wrb
= wrb_from_mccq(adapter
);
1697 req
= embedded_payload(wrb
);
1699 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1700 OPCODE_COMMON_SET_FLOW_CONTROL
);
1702 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1703 OPCODE_COMMON_SET_FLOW_CONTROL
, sizeof(*req
));
1705 req
->tx_flow_control
= cpu_to_le16((u16
)tx_fc
);
1706 req
->rx_flow_control
= cpu_to_le16((u16
)rx_fc
);
1708 status
= be_mcc_notify_wait(adapter
);
1711 spin_unlock_bh(&adapter
->mcc_lock
);
1716 int be_cmd_get_flow_control(struct be_adapter
*adapter
, u32
*tx_fc
, u32
*rx_fc
)
1718 struct be_mcc_wrb
*wrb
;
1719 struct be_cmd_req_get_flow_control
*req
;
1722 spin_lock_bh(&adapter
->mcc_lock
);
1724 wrb
= wrb_from_mccq(adapter
);
1729 req
= embedded_payload(wrb
);
1731 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1732 OPCODE_COMMON_GET_FLOW_CONTROL
);
1734 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1735 OPCODE_COMMON_GET_FLOW_CONTROL
, sizeof(*req
));
1737 status
= be_mcc_notify_wait(adapter
);
1739 struct be_cmd_resp_get_flow_control
*resp
=
1740 embedded_payload(wrb
);
1741 *tx_fc
= le16_to_cpu(resp
->tx_flow_control
);
1742 *rx_fc
= le16_to_cpu(resp
->rx_flow_control
);
1746 spin_unlock_bh(&adapter
->mcc_lock
);
1751 int be_cmd_query_fw_cfg(struct be_adapter
*adapter
, u32
*port_num
,
1752 u32
*mode
, u32
*caps
)
1754 struct be_mcc_wrb
*wrb
;
1755 struct be_cmd_req_query_fw_cfg
*req
;
1758 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1761 wrb
= wrb_from_mbox(adapter
);
1762 req
= embedded_payload(wrb
);
1764 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1765 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
);
1767 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1768 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
, sizeof(*req
));
1770 status
= be_mbox_notify_wait(adapter
);
1772 struct be_cmd_resp_query_fw_cfg
*resp
= embedded_payload(wrb
);
1773 *port_num
= le32_to_cpu(resp
->phys_port
);
1774 *mode
= le32_to_cpu(resp
->function_mode
);
1775 *caps
= le32_to_cpu(resp
->function_caps
);
1778 mutex_unlock(&adapter
->mbox_lock
);
1783 int be_cmd_reset_function(struct be_adapter
*adapter
)
1785 struct be_mcc_wrb
*wrb
;
1786 struct be_cmd_req_hdr
*req
;
1789 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1792 wrb
= wrb_from_mbox(adapter
);
1793 req
= embedded_payload(wrb
);
1795 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1796 OPCODE_COMMON_FUNCTION_RESET
);
1798 be_cmd_hdr_prepare(req
, CMD_SUBSYSTEM_COMMON
,
1799 OPCODE_COMMON_FUNCTION_RESET
, sizeof(*req
));
1801 status
= be_mbox_notify_wait(adapter
);
1803 mutex_unlock(&adapter
->mbox_lock
);
1807 int be_cmd_rss_config(struct be_adapter
*adapter
, u8
*rsstable
, u16 table_size
)
1809 struct be_mcc_wrb
*wrb
;
1810 struct be_cmd_req_rss_config
*req
;
1811 u32 myhash
[10] = {0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF,
1812 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF};
1815 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1818 wrb
= wrb_from_mbox(adapter
);
1819 req
= embedded_payload(wrb
);
1821 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1822 OPCODE_ETH_RSS_CONFIG
);
1824 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1825 OPCODE_ETH_RSS_CONFIG
, sizeof(*req
));
1827 req
->if_id
= cpu_to_le32(adapter
->if_handle
);
1828 req
->enable_rss
= cpu_to_le16(RSS_ENABLE_TCP_IPV4
| RSS_ENABLE_IPV4
);
1829 req
->cpu_table_size_log2
= cpu_to_le16(fls(table_size
) - 1);
1830 memcpy(req
->cpu_table
, rsstable
, table_size
);
1831 memcpy(req
->hash
, myhash
, sizeof(myhash
));
1832 be_dws_cpu_to_le(req
->hash
, sizeof(req
->hash
));
1834 status
= be_mbox_notify_wait(adapter
);
1836 mutex_unlock(&adapter
->mbox_lock
);
1841 int be_cmd_set_beacon_state(struct be_adapter
*adapter
, u8 port_num
,
1842 u8 bcn
, u8 sts
, u8 state
)
1844 struct be_mcc_wrb
*wrb
;
1845 struct be_cmd_req_enable_disable_beacon
*req
;
1848 spin_lock_bh(&adapter
->mcc_lock
);
1850 wrb
= wrb_from_mccq(adapter
);
1855 req
= embedded_payload(wrb
);
1857 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1858 OPCODE_COMMON_ENABLE_DISABLE_BEACON
);
1860 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1861 OPCODE_COMMON_ENABLE_DISABLE_BEACON
, sizeof(*req
));
1863 req
->port_num
= port_num
;
1864 req
->beacon_state
= state
;
1865 req
->beacon_duration
= bcn
;
1866 req
->status_duration
= sts
;
1868 status
= be_mcc_notify_wait(adapter
);
1871 spin_unlock_bh(&adapter
->mcc_lock
);
1876 int be_cmd_get_beacon_state(struct be_adapter
*adapter
, u8 port_num
, u32
*state
)
1878 struct be_mcc_wrb
*wrb
;
1879 struct be_cmd_req_get_beacon_state
*req
;
1882 spin_lock_bh(&adapter
->mcc_lock
);
1884 wrb
= wrb_from_mccq(adapter
);
1889 req
= embedded_payload(wrb
);
1891 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
1892 OPCODE_COMMON_GET_BEACON_STATE
);
1894 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1895 OPCODE_COMMON_GET_BEACON_STATE
, sizeof(*req
));
1897 req
->port_num
= port_num
;
1899 status
= be_mcc_notify_wait(adapter
);
1901 struct be_cmd_resp_get_beacon_state
*resp
=
1902 embedded_payload(wrb
);
1903 *state
= resp
->beacon_state
;
1907 spin_unlock_bh(&adapter
->mcc_lock
);
1911 int lancer_cmd_write_object(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
1912 u32 data_size
, u32 data_offset
, const char *obj_name
,
1913 u32
*data_written
, u8
*addn_status
)
1915 struct be_mcc_wrb
*wrb
;
1916 struct lancer_cmd_req_write_object
*req
;
1917 struct lancer_cmd_resp_write_object
*resp
;
1921 spin_lock_bh(&adapter
->mcc_lock
);
1922 adapter
->flash_status
= 0;
1924 wrb
= wrb_from_mccq(adapter
);
1930 req
= embedded_payload(wrb
);
1932 be_wrb_hdr_prepare(wrb
, sizeof(struct lancer_cmd_req_write_object
),
1933 true, 1, OPCODE_COMMON_WRITE_OBJECT
);
1934 wrb
->tag1
= CMD_SUBSYSTEM_COMMON
;
1936 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1937 OPCODE_COMMON_WRITE_OBJECT
,
1938 sizeof(struct lancer_cmd_req_write_object
));
1940 ctxt
= &req
->context
;
1941 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
1942 write_length
, ctxt
, data_size
);
1945 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
1948 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
1951 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
1952 req
->write_offset
= cpu_to_le32(data_offset
);
1953 strcpy(req
->object_name
, obj_name
);
1954 req
->descriptor_count
= cpu_to_le32(1);
1955 req
->buf_len
= cpu_to_le32(data_size
);
1956 req
->addr_low
= cpu_to_le32((cmd
->dma
+
1957 sizeof(struct lancer_cmd_req_write_object
))
1959 req
->addr_high
= cpu_to_le32(upper_32_bits(cmd
->dma
+
1960 sizeof(struct lancer_cmd_req_write_object
)));
1962 be_mcc_notify(adapter
);
1963 spin_unlock_bh(&adapter
->mcc_lock
);
1965 if (!wait_for_completion_timeout(&adapter
->flash_compl
,
1966 msecs_to_jiffies(12000)))
1969 status
= adapter
->flash_status
;
1971 resp
= embedded_payload(wrb
);
1973 *data_written
= le32_to_cpu(resp
->actual_write_len
);
1975 *addn_status
= resp
->additional_status
;
1976 status
= resp
->status
;
1982 spin_unlock_bh(&adapter
->mcc_lock
);
1986 int be_cmd_write_flashrom(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
1987 u32 flash_type
, u32 flash_opcode
, u32 buf_size
)
1989 struct be_mcc_wrb
*wrb
;
1990 struct be_cmd_write_flashrom
*req
;
1994 spin_lock_bh(&adapter
->mcc_lock
);
1995 adapter
->flash_status
= 0;
1997 wrb
= wrb_from_mccq(adapter
);
2003 sge
= nonembedded_sgl(wrb
);
2005 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
2006 OPCODE_COMMON_WRITE_FLASHROM
);
2007 wrb
->tag1
= CMD_SUBSYSTEM_COMMON
;
2009 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2010 OPCODE_COMMON_WRITE_FLASHROM
, cmd
->size
);
2011 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
2012 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
2013 sge
->len
= cpu_to_le32(cmd
->size
);
2015 req
->params
.op_type
= cpu_to_le32(flash_type
);
2016 req
->params
.op_code
= cpu_to_le32(flash_opcode
);
2017 req
->params
.data_buf_size
= cpu_to_le32(buf_size
);
2019 be_mcc_notify(adapter
);
2020 spin_unlock_bh(&adapter
->mcc_lock
);
2022 if (!wait_for_completion_timeout(&adapter
->flash_compl
,
2023 msecs_to_jiffies(12000)))
2026 status
= adapter
->flash_status
;
2031 spin_unlock_bh(&adapter
->mcc_lock
);
2035 int be_cmd_get_flash_crc(struct be_adapter
*adapter
, u8
*flashed_crc
,
2038 struct be_mcc_wrb
*wrb
;
2039 struct be_cmd_write_flashrom
*req
;
2042 spin_lock_bh(&adapter
->mcc_lock
);
2044 wrb
= wrb_from_mccq(adapter
);
2049 req
= embedded_payload(wrb
);
2051 be_wrb_hdr_prepare(wrb
, sizeof(*req
)+4, true, 0,
2052 OPCODE_COMMON_READ_FLASHROM
);
2054 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2055 OPCODE_COMMON_READ_FLASHROM
, sizeof(*req
)+4);
2057 req
->params
.op_type
= cpu_to_le32(IMG_TYPE_REDBOOT
);
2058 req
->params
.op_code
= cpu_to_le32(FLASHROM_OPER_REPORT
);
2059 req
->params
.offset
= cpu_to_le32(offset
);
2060 req
->params
.data_buf_size
= cpu_to_le32(0x4);
2062 status
= be_mcc_notify_wait(adapter
);
2064 memcpy(flashed_crc
, req
->params
.data_buf
, 4);
2067 spin_unlock_bh(&adapter
->mcc_lock
);
2071 int be_cmd_enable_magic_wol(struct be_adapter
*adapter
, u8
*mac
,
2072 struct be_dma_mem
*nonemb_cmd
)
2074 struct be_mcc_wrb
*wrb
;
2075 struct be_cmd_req_acpi_wol_magic_config
*req
;
2079 spin_lock_bh(&adapter
->mcc_lock
);
2081 wrb
= wrb_from_mccq(adapter
);
2086 req
= nonemb_cmd
->va
;
2087 sge
= nonembedded_sgl(wrb
);
2089 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
2090 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
);
2092 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
2093 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
, sizeof(*req
));
2094 memcpy(req
->magic_mac
, mac
, ETH_ALEN
);
2096 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
2097 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
2098 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
2100 status
= be_mcc_notify_wait(adapter
);
2103 spin_unlock_bh(&adapter
->mcc_lock
);
2107 int be_cmd_set_loopback(struct be_adapter
*adapter
, u8 port_num
,
2108 u8 loopback_type
, u8 enable
)
2110 struct be_mcc_wrb
*wrb
;
2111 struct be_cmd_req_set_lmode
*req
;
2114 spin_lock_bh(&adapter
->mcc_lock
);
2116 wrb
= wrb_from_mccq(adapter
);
2122 req
= embedded_payload(wrb
);
2124 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
2125 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
);
2127 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
2128 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
2131 req
->src_port
= port_num
;
2132 req
->dest_port
= port_num
;
2133 req
->loopback_type
= loopback_type
;
2134 req
->loopback_state
= enable
;
2136 status
= be_mcc_notify_wait(adapter
);
2138 spin_unlock_bh(&adapter
->mcc_lock
);
2142 int be_cmd_loopback_test(struct be_adapter
*adapter
, u32 port_num
,
2143 u32 loopback_type
, u32 pkt_size
, u32 num_pkts
, u64 pattern
)
2145 struct be_mcc_wrb
*wrb
;
2146 struct be_cmd_req_loopback_test
*req
;
2149 spin_lock_bh(&adapter
->mcc_lock
);
2151 wrb
= wrb_from_mccq(adapter
);
2157 req
= embedded_payload(wrb
);
2159 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
2160 OPCODE_LOWLEVEL_LOOPBACK_TEST
);
2162 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
2163 OPCODE_LOWLEVEL_LOOPBACK_TEST
, sizeof(*req
));
2164 req
->hdr
.timeout
= cpu_to_le32(4);
2166 req
->pattern
= cpu_to_le64(pattern
);
2167 req
->src_port
= cpu_to_le32(port_num
);
2168 req
->dest_port
= cpu_to_le32(port_num
);
2169 req
->pkt_size
= cpu_to_le32(pkt_size
);
2170 req
->num_pkts
= cpu_to_le32(num_pkts
);
2171 req
->loopback_type
= cpu_to_le32(loopback_type
);
2173 status
= be_mcc_notify_wait(adapter
);
2175 struct be_cmd_resp_loopback_test
*resp
= embedded_payload(wrb
);
2176 status
= le32_to_cpu(resp
->status
);
2180 spin_unlock_bh(&adapter
->mcc_lock
);
2184 int be_cmd_ddr_dma_test(struct be_adapter
*adapter
, u64 pattern
,
2185 u32 byte_cnt
, struct be_dma_mem
*cmd
)
2187 struct be_mcc_wrb
*wrb
;
2188 struct be_cmd_req_ddrdma_test
*req
;
2193 spin_lock_bh(&adapter
->mcc_lock
);
2195 wrb
= wrb_from_mccq(adapter
);
2201 sge
= nonembedded_sgl(wrb
);
2202 be_wrb_hdr_prepare(wrb
, cmd
->size
, false, 1,
2203 OPCODE_LOWLEVEL_HOST_DDR_DMA
);
2204 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
2205 OPCODE_LOWLEVEL_HOST_DDR_DMA
, cmd
->size
);
2207 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
2208 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
2209 sge
->len
= cpu_to_le32(cmd
->size
);
2211 req
->pattern
= cpu_to_le64(pattern
);
2212 req
->byte_count
= cpu_to_le32(byte_cnt
);
2213 for (i
= 0; i
< byte_cnt
; i
++) {
2214 req
->snd_buff
[i
] = (u8
)(pattern
>> (j
*8));
2220 status
= be_mcc_notify_wait(adapter
);
2223 struct be_cmd_resp_ddrdma_test
*resp
;
2225 if ((memcmp(resp
->rcv_buff
, req
->snd_buff
, byte_cnt
) != 0) ||
2232 spin_unlock_bh(&adapter
->mcc_lock
);
2236 int be_cmd_get_seeprom_data(struct be_adapter
*adapter
,
2237 struct be_dma_mem
*nonemb_cmd
)
2239 struct be_mcc_wrb
*wrb
;
2240 struct be_cmd_req_seeprom_read
*req
;
2244 spin_lock_bh(&adapter
->mcc_lock
);
2246 wrb
= wrb_from_mccq(adapter
);
2251 req
= nonemb_cmd
->va
;
2252 sge
= nonembedded_sgl(wrb
);
2254 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
2255 OPCODE_COMMON_SEEPROM_READ
);
2257 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2258 OPCODE_COMMON_SEEPROM_READ
, sizeof(*req
));
2260 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
2261 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
2262 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
2264 status
= be_mcc_notify_wait(adapter
);
2267 spin_unlock_bh(&adapter
->mcc_lock
);
2271 int be_cmd_get_phy_info(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
)
2273 struct be_mcc_wrb
*wrb
;
2274 struct be_cmd_req_get_phy_info
*req
;
2278 spin_lock_bh(&adapter
->mcc_lock
);
2280 wrb
= wrb_from_mccq(adapter
);
2287 sge
= nonembedded_sgl(wrb
);
2289 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1,
2290 OPCODE_COMMON_GET_PHY_DETAILS
);
2292 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2293 OPCODE_COMMON_GET_PHY_DETAILS
,
2296 sge
->pa_hi
= cpu_to_le32(upper_32_bits(cmd
->dma
));
2297 sge
->pa_lo
= cpu_to_le32(cmd
->dma
& 0xFFFFFFFF);
2298 sge
->len
= cpu_to_le32(cmd
->size
);
2300 status
= be_mcc_notify_wait(adapter
);
2302 spin_unlock_bh(&adapter
->mcc_lock
);
2306 int be_cmd_set_qos(struct be_adapter
*adapter
, u32 bps
, u32 domain
)
2308 struct be_mcc_wrb
*wrb
;
2309 struct be_cmd_req_set_qos
*req
;
2312 spin_lock_bh(&adapter
->mcc_lock
);
2314 wrb
= wrb_from_mccq(adapter
);
2320 req
= embedded_payload(wrb
);
2322 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
2323 OPCODE_COMMON_SET_QOS
);
2325 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2326 OPCODE_COMMON_SET_QOS
, sizeof(*req
));
2328 req
->hdr
.domain
= domain
;
2329 req
->valid_bits
= cpu_to_le32(BE_QOS_BITS_NIC
);
2330 req
->max_bps_nic
= cpu_to_le32(bps
);
2332 status
= be_mcc_notify_wait(adapter
);
2335 spin_unlock_bh(&adapter
->mcc_lock
);
2339 int be_cmd_get_cntl_attributes(struct be_adapter
*adapter
)
2341 struct be_mcc_wrb
*wrb
;
2342 struct be_cmd_req_cntl_attribs
*req
;
2343 struct be_cmd_resp_cntl_attribs
*resp
;
2346 int payload_len
= max(sizeof(*req
), sizeof(*resp
));
2347 struct mgmt_controller_attrib
*attribs
;
2348 struct be_dma_mem attribs_cmd
;
2350 memset(&attribs_cmd
, 0, sizeof(struct be_dma_mem
));
2351 attribs_cmd
.size
= sizeof(struct be_cmd_resp_cntl_attribs
);
2352 attribs_cmd
.va
= pci_alloc_consistent(adapter
->pdev
, attribs_cmd
.size
,
2354 if (!attribs_cmd
.va
) {
2355 dev_err(&adapter
->pdev
->dev
,
2356 "Memory allocation failure\n");
2360 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
2363 wrb
= wrb_from_mbox(adapter
);
2368 req
= attribs_cmd
.va
;
2369 sge
= nonembedded_sgl(wrb
);
2371 be_wrb_hdr_prepare(wrb
, payload_len
, false, 1,
2372 OPCODE_COMMON_GET_CNTL_ATTRIBUTES
);
2373 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2374 OPCODE_COMMON_GET_CNTL_ATTRIBUTES
, payload_len
);
2375 sge
->pa_hi
= cpu_to_le32(upper_32_bits(attribs_cmd
.dma
));
2376 sge
->pa_lo
= cpu_to_le32(attribs_cmd
.dma
& 0xFFFFFFFF);
2377 sge
->len
= cpu_to_le32(attribs_cmd
.size
);
2379 status
= be_mbox_notify_wait(adapter
);
2381 attribs
= attribs_cmd
.va
+ sizeof(struct be_cmd_resp_hdr
);
2382 adapter
->hba_port_num
= attribs
->hba_attribs
.phy_port
;
2386 mutex_unlock(&adapter
->mbox_lock
);
2387 pci_free_consistent(adapter
->pdev
, attribs_cmd
.size
, attribs_cmd
.va
,
2393 int be_cmd_req_native_mode(struct be_adapter
*adapter
)
2395 struct be_mcc_wrb
*wrb
;
2396 struct be_cmd_req_set_func_cap
*req
;
2399 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
2402 wrb
= wrb_from_mbox(adapter
);
2408 req
= embedded_payload(wrb
);
2410 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0,
2411 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP
);
2413 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2414 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP
, sizeof(*req
));
2416 req
->valid_cap_flags
= cpu_to_le32(CAPABILITY_SW_TIMESTAMPS
|
2417 CAPABILITY_BE3_NATIVE_ERX_API
);
2418 req
->cap_flags
= cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API
);
2420 status
= be_mbox_notify_wait(adapter
);
2422 struct be_cmd_resp_set_func_cap
*resp
= embedded_payload(wrb
);
2423 adapter
->be3_native
= le32_to_cpu(resp
->cap_flags
) &
2424 CAPABILITY_BE3_NATIVE_ERX_API
;
2427 mutex_unlock(&adapter
->mbox_lock
);