PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / scsi / be2iscsi / be_cmds.c
blob3338391b64de9b1aba50844c014f7e5fc44706b3
1 /**
2 * Copyright (C) 2005 - 2013 Emulex
3 * All rights reserved.
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
13 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
18 #include <scsi/iscsi_proto.h>
20 #include "be_main.h"
21 #include "be.h"
22 #include "be_mgmt.h"
24 int beiscsi_pci_soft_reset(struct beiscsi_hba *phba)
26 u32 sreset;
27 u8 *pci_reset_offset = 0;
28 u8 *pci_online0_offset = 0;
29 u8 *pci_online1_offset = 0;
30 u32 pconline0 = 0;
31 u32 pconline1 = 0;
32 u32 i;
34 pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET;
35 pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0;
36 pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1;
37 sreset = readl((void *)pci_reset_offset);
38 sreset |= BE2_SET_RESET;
39 writel(sreset, (void *)pci_reset_offset);
41 i = 0;
42 while (sreset & BE2_SET_RESET) {
43 if (i > 64)
44 break;
45 msleep(100);
46 sreset = readl((void *)pci_reset_offset);
47 i++;
50 if (sreset & BE2_SET_RESET) {
51 printk(KERN_ERR DRV_NAME
52 " Soft Reset did not deassert\n");
53 return -EIO;
55 pconline1 = BE2_MPU_IRAM_ONLINE;
56 writel(pconline0, (void *)pci_online0_offset);
57 writel(pconline1, (void *)pci_online1_offset);
59 sreset |= BE2_SET_RESET;
60 writel(sreset, (void *)pci_reset_offset);
62 i = 0;
63 while (sreset & BE2_SET_RESET) {
64 if (i > 64)
65 break;
66 msleep(1);
67 sreset = readl((void *)pci_reset_offset);
68 i++;
70 if (sreset & BE2_SET_RESET) {
71 printk(KERN_ERR DRV_NAME
72 " MPU Online Soft Reset did not deassert\n");
73 return -EIO;
75 return 0;
78 int be_chk_reset_complete(struct beiscsi_hba *phba)
80 unsigned int num_loop;
81 u8 *mpu_sem = 0;
82 u32 status;
84 num_loop = 1000;
85 mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
86 msleep(5000);
88 while (num_loop) {
89 status = readl((void *)mpu_sem);
91 if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000)
92 break;
93 msleep(60);
94 num_loop--;
97 if ((status & 0x80000000) || (!num_loop)) {
98 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
99 "BC_%d : Failed in be_chk_reset_complete"
100 "status = 0x%x\n", status);
101 return -EIO;
104 return 0;
107 void be_mcc_notify(struct beiscsi_hba *phba)
109 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
110 u32 val = 0;
112 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
113 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
114 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
117 unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
119 unsigned int tag = 0;
121 if (phba->ctrl.mcc_tag_available) {
122 tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
123 phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
124 phba->ctrl.mcc_numtag[tag] = 0;
126 if (tag) {
127 phba->ctrl.mcc_tag_available--;
128 if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
129 phba->ctrl.mcc_alloc_index = 0;
130 else
131 phba->ctrl.mcc_alloc_index++;
133 return tag;
137 * beiscsi_mccq_compl()- Wait for completion of MBX
138 * @phba: Driver private structure
139 * @tag: Tag for the MBX Command
140 * @wrb: the WRB used for the MBX Command
141 * @cmd_hdr: IOCTL Hdr for the MBX Cmd
143 * Waits for MBX completion with the passed TAG.
145 * return
146 * Success: 0
147 * Failure: Non-Zero
149 int beiscsi_mccq_compl(struct beiscsi_hba *phba,
150 uint32_t tag, struct be_mcc_wrb **wrb,
151 void *cmd_hdr)
153 int rc = 0;
154 uint32_t mcc_tag_response;
155 uint16_t status = 0, addl_status = 0, wrb_num = 0;
156 struct be_mcc_wrb *temp_wrb;
157 struct be_cmd_req_hdr *ioctl_hdr;
158 struct be_cmd_resp_hdr *ioctl_resp_hdr;
159 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
161 if (beiscsi_error(phba)) {
162 free_mcc_tag(&phba->ctrl, tag);
163 return -EIO;
166 /* wait for the mccq completion */
167 rc = wait_event_interruptible_timeout(
168 phba->ctrl.mcc_wait[tag],
169 phba->ctrl.mcc_numtag[tag],
170 msecs_to_jiffies(
171 BEISCSI_HOST_MBX_TIMEOUT));
173 if (rc <= 0) {
174 beiscsi_log(phba, KERN_ERR,
175 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
176 BEISCSI_LOG_CONFIG,
177 "BC_%d : MBX Cmd Completion timed out\n");
178 rc = -EBUSY;
180 /* decrement the mccq used count */
181 atomic_dec(&phba->ctrl.mcc_obj.q.used);
183 goto release_mcc_tag;
184 } else
185 rc = 0;
187 mcc_tag_response = phba->ctrl.mcc_numtag[tag];
188 status = (mcc_tag_response & CQE_STATUS_MASK);
189 addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
190 CQE_STATUS_ADDL_SHIFT);
192 if (cmd_hdr) {
193 ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
194 } else {
195 wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
196 CQE_STATUS_WRB_SHIFT;
197 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
198 ioctl_hdr = embedded_payload(temp_wrb);
200 if (wrb)
201 *wrb = temp_wrb;
204 if (status || addl_status) {
205 beiscsi_log(phba, KERN_ERR,
206 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
207 BEISCSI_LOG_CONFIG,
208 "BC_%d : MBX Cmd Failed for "
209 "Subsys : %d Opcode : %d with "
210 "Status : %d and Extd_Status : %d\n",
211 ioctl_hdr->subsystem,
212 ioctl_hdr->opcode,
213 status, addl_status);
215 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
216 ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
217 beiscsi_log(phba, KERN_WARNING,
218 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
219 BEISCSI_LOG_CONFIG,
220 "BC_%d : Insufficent Buffer Error "
221 "Resp_Len : %d Actual_Resp_Len : %d\n",
222 ioctl_resp_hdr->response_length,
223 ioctl_resp_hdr->actual_resp_len);
225 rc = -EAGAIN;
226 goto release_mcc_tag;
228 rc = -EIO;
231 release_mcc_tag:
232 /* Release the MCC entry */
233 free_mcc_tag(&phba->ctrl, tag);
235 return rc;
238 void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
240 spin_lock(&ctrl->mbox_lock);
241 tag = tag & 0x000000FF;
242 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
243 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
244 ctrl->mcc_free_index = 0;
245 else
246 ctrl->mcc_free_index++;
247 ctrl->mcc_tag_available++;
248 spin_unlock(&ctrl->mbox_lock);
251 bool is_link_state_evt(u32 trailer)
253 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
254 ASYNC_TRAILER_EVENT_CODE_MASK) ==
255 ASYNC_EVENT_CODE_LINK_STATE);
258 static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
260 if (compl->flags != 0) {
261 compl->flags = le32_to_cpu(compl->flags);
262 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
263 return true;
264 } else
265 return false;
268 static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
270 compl->flags = 0;
274 * be_mcc_compl_process()- Check the MBX comapletion status
275 * @ctrl: Function specific MBX data structure
276 * @compl: Completion status of MBX Command
278 * Check for the MBX completion status when BMBX method used
280 * return
281 * Success: Zero
282 * Failure: Non-Zero
284 static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
285 struct be_mcc_compl *compl)
287 u16 compl_status, extd_status;
288 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
289 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
290 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
291 struct be_cmd_resp_hdr *resp_hdr;
293 be_dws_le_to_cpu(compl, 4);
295 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
296 CQE_STATUS_COMPL_MASK;
297 if (compl_status != MCC_STATUS_SUCCESS) {
298 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
299 CQE_STATUS_EXTD_MASK;
301 beiscsi_log(phba, KERN_ERR,
302 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
303 "BC_%d : error in cmd completion: "
304 "Subsystem : %d Opcode : %d "
305 "status(compl/extd)=%d/%d\n",
306 hdr->subsystem, hdr->opcode,
307 compl_status, extd_status);
309 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
310 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
311 if (resp_hdr->response_length)
312 return 0;
314 return -EBUSY;
316 return 0;
319 int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
320 struct be_mcc_compl *compl)
322 u16 compl_status, extd_status;
323 unsigned short tag;
325 be_dws_le_to_cpu(compl, 4);
327 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
328 CQE_STATUS_COMPL_MASK;
329 /* The ctrl.mcc_numtag[tag] is filled with
330 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
331 * [7:0] = compl_status
333 tag = (compl->tag0 & 0x000000FF);
334 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
335 CQE_STATUS_EXTD_MASK;
337 ctrl->mcc_numtag[tag] = 0x80000000;
338 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
339 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
340 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
341 wake_up_interruptible(&ctrl->mcc_wait[tag]);
342 return 0;
345 static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
347 struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
348 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
350 if (be_mcc_compl_is_new(compl)) {
351 queue_tail_inc(mcc_cq);
352 return compl;
354 return NULL;
357 static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
359 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
362 void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
363 struct be_async_event_link_state *evt)
365 if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
366 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
367 (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
368 phba->state = BE_ADAPTER_LINK_DOWN;
370 beiscsi_log(phba, KERN_ERR,
371 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
372 "BC_%d : Link Down on Port %d\n",
373 evt->physical_port);
375 iscsi_host_for_each_session(phba->shost,
376 be2iscsi_fail_session);
377 } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
378 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
379 (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
380 phba->state = BE_ADAPTER_LINK_UP;
382 beiscsi_log(phba, KERN_ERR,
383 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
384 "BC_%d : Link UP on Port %d\n",
385 evt->physical_port);
389 static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
390 u16 num_popped)
392 u32 val = 0;
393 val |= qid & DB_CQ_RING_ID_MASK;
394 if (arm)
395 val |= 1 << DB_CQ_REARM_SHIFT;
396 val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
397 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
401 int beiscsi_process_mcc(struct beiscsi_hba *phba)
403 struct be_mcc_compl *compl;
404 int num = 0, status = 0;
405 struct be_ctrl_info *ctrl = &phba->ctrl;
407 spin_lock_bh(&phba->ctrl.mcc_cq_lock);
408 while ((compl = be_mcc_compl_get(phba))) {
409 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
410 /* Interpret flags as an async trailer */
411 if (is_link_state_evt(compl->flags))
412 /* Interpret compl as a async link evt */
413 beiscsi_async_link_state_process(phba,
414 (struct be_async_event_link_state *) compl);
415 else
416 beiscsi_log(phba, KERN_ERR,
417 BEISCSI_LOG_CONFIG |
418 BEISCSI_LOG_MBOX,
419 "BC_%d : Unsupported Async Event, flags"
420 " = 0x%08x\n", compl->flags);
422 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
423 status = be_mcc_compl_process(ctrl, compl);
424 atomic_dec(&phba->ctrl.mcc_obj.q.used);
426 be_mcc_compl_use(compl);
427 num++;
430 if (num)
431 beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
433 spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
434 return status;
438 * be_mcc_wait_compl()- Wait for MBX completion
439 * @phba: driver private structure
441 * Wait till no more pending mcc requests are present
443 * return
444 * Success: 0
445 * Failure: Non-Zero
448 static int be_mcc_wait_compl(struct beiscsi_hba *phba)
450 int i, status;
451 for (i = 0; i < mcc_timeout; i++) {
452 if (beiscsi_error(phba))
453 return -EIO;
455 status = beiscsi_process_mcc(phba);
456 if (status)
457 return status;
459 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
460 break;
461 udelay(100);
463 if (i == mcc_timeout) {
464 beiscsi_log(phba, KERN_ERR,
465 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
466 "BC_%d : FW Timed Out\n");
467 phba->fw_timeout = true;
468 beiscsi_ue_detect(phba);
469 return -EBUSY;
471 return 0;
475 * be_mcc_notify_wait()- Notify and wait for Compl
476 * @phba: driver private structure
478 * Notify MCC requests and wait for completion
480 * return
481 * Success: 0
482 * Failure: Non-Zero
484 int be_mcc_notify_wait(struct beiscsi_hba *phba)
486 be_mcc_notify(phba);
487 return be_mcc_wait_compl(phba);
491 * be_mbox_db_ready_wait()- Check ready status
492 * @ctrl: Function specific MBX data structure
494 * Check for the ready status of FW to send BMBX
495 * commands to adapter.
497 * return
498 * Success: 0
499 * Failure: Non-Zero
501 static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
503 #define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */
504 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
505 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
506 unsigned long timeout;
507 bool read_flag = false;
508 int ret = 0, i;
509 u32 ready;
510 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q);
512 if (beiscsi_error(phba))
513 return -EIO;
515 timeout = jiffies + (HZ * 110);
517 do {
518 for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) {
519 ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
520 if (ready) {
521 read_flag = true;
522 break;
524 mdelay(1);
527 if (!read_flag) {
528 wait_event_timeout(rdybit_check_q,
529 (read_flag != true),
530 HZ * 5);
532 } while ((time_before(jiffies, timeout)) && !read_flag);
534 if (!read_flag) {
535 beiscsi_log(phba, KERN_ERR,
536 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
537 "BC_%d : FW Timed Out\n");
538 phba->fw_timeout = true;
539 beiscsi_ue_detect(phba);
540 ret = -EBUSY;
543 return ret;
547 * be_mbox_notify: Notify adapter of new BMBX command
548 * @ctrl: Function specific MBX data structure
550 * Ring doorbell to inform adapter of a BMBX command
551 * to process
553 * return
554 * Success: 0
555 * Failure: Non-Zero
557 int be_mbox_notify(struct be_ctrl_info *ctrl)
559 int status;
560 u32 val = 0;
561 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
562 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
563 struct be_mcc_mailbox *mbox = mbox_mem->va;
564 struct be_mcc_compl *compl = &mbox->compl;
565 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
567 status = be_mbox_db_ready_wait(ctrl);
568 if (status)
569 return status;
571 val &= ~MPU_MAILBOX_DB_RDY_MASK;
572 val |= MPU_MAILBOX_DB_HI_MASK;
573 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
574 iowrite32(val, db);
576 status = be_mbox_db_ready_wait(ctrl);
577 if (status)
578 return status;
580 val = 0;
581 val &= ~MPU_MAILBOX_DB_RDY_MASK;
582 val &= ~MPU_MAILBOX_DB_HI_MASK;
583 val |= (u32) (mbox_mem->dma >> 4) << 2;
584 iowrite32(val, db);
586 status = be_mbox_db_ready_wait(ctrl);
587 if (status)
588 return status;
590 if (be_mcc_compl_is_new(compl)) {
591 status = be_mcc_compl_process(ctrl, &mbox->compl);
592 be_mcc_compl_use(compl);
593 if (status) {
594 beiscsi_log(phba, KERN_ERR,
595 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
596 "BC_%d : After be_mcc_compl_process\n");
598 return status;
600 } else {
601 beiscsi_log(phba, KERN_ERR,
602 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
603 "BC_%d : Invalid Mailbox Completion\n");
605 return -EBUSY;
607 return 0;
611 * Insert the mailbox address into the doorbell in two steps
612 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
614 static int be_mbox_notify_wait(struct beiscsi_hba *phba)
616 int status;
617 u32 val = 0;
618 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
619 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
620 struct be_mcc_mailbox *mbox = mbox_mem->va;
621 struct be_mcc_compl *compl = &mbox->compl;
622 struct be_ctrl_info *ctrl = &phba->ctrl;
624 status = be_mbox_db_ready_wait(ctrl);
625 if (status)
626 return status;
628 val |= MPU_MAILBOX_DB_HI_MASK;
629 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
630 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
631 iowrite32(val, db);
633 /* wait for ready to be set */
634 status = be_mbox_db_ready_wait(ctrl);
635 if (status != 0)
636 return status;
638 val = 0;
639 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
640 val |= (u32)(mbox_mem->dma >> 4) << 2;
641 iowrite32(val, db);
643 status = be_mbox_db_ready_wait(ctrl);
644 if (status != 0)
645 return status;
647 /* A cq entry has been made now */
648 if (be_mcc_compl_is_new(compl)) {
649 status = be_mcc_compl_process(ctrl, &mbox->compl);
650 be_mcc_compl_use(compl);
651 if (status)
652 return status;
653 } else {
654 beiscsi_log(phba, KERN_ERR,
655 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
656 "BC_%d : invalid mailbox completion\n");
658 return -EBUSY;
660 return 0;
663 void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
664 bool embedded, u8 sge_cnt)
666 if (embedded)
667 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
668 else
669 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
670 MCC_WRB_SGE_CNT_SHIFT;
671 wrb->payload_length = payload_len;
672 be_dws_cpu_to_le(wrb, 8);
675 void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
676 u8 subsystem, u8 opcode, int cmd_len)
678 req_hdr->opcode = opcode;
679 req_hdr->subsystem = subsystem;
680 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
681 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
684 static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
685 struct be_dma_mem *mem)
687 int i, buf_pages;
688 u64 dma = (u64) mem->dma;
690 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
691 for (i = 0; i < buf_pages; i++) {
692 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
693 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
694 dma += PAGE_SIZE_4K;
698 static u32 eq_delay_to_mult(u32 usec_delay)
700 #define MAX_INTR_RATE 651042
701 const u32 round = 10;
702 u32 multiplier;
704 if (usec_delay == 0)
705 multiplier = 0;
706 else {
707 u32 interrupt_rate = 1000000 / usec_delay;
708 if (interrupt_rate == 0)
709 multiplier = 1023;
710 else {
711 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
712 multiplier /= interrupt_rate;
713 multiplier = (multiplier + round / 2) / round;
714 multiplier = min(multiplier, (u32) 1023);
717 return multiplier;
720 struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
722 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
725 struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
727 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
728 struct be_mcc_wrb *wrb;
730 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
731 wrb = queue_head_node(mccq);
732 memset(wrb, 0, sizeof(*wrb));
733 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
734 queue_head_inc(mccq);
735 atomic_inc(&mccq->used);
736 return wrb;
740 int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
741 struct be_queue_info *eq, int eq_delay)
743 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
744 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
745 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
746 struct be_dma_mem *q_mem = &eq->dma_mem;
747 int status;
749 spin_lock(&ctrl->mbox_lock);
750 memset(wrb, 0, sizeof(*wrb));
752 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
754 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
755 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
757 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
759 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
760 PCI_FUNC(ctrl->pdev->devfn));
761 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
762 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
763 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
764 __ilog2_u32(eq->len / 256));
765 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
766 eq_delay_to_mult(eq_delay));
767 be_dws_cpu_to_le(req->context, sizeof(req->context));
769 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
771 status = be_mbox_notify(ctrl);
772 if (!status) {
773 eq->id = le16_to_cpu(resp->eq_id);
774 eq->created = true;
776 spin_unlock(&ctrl->mbox_lock);
777 return status;
781 * be_cmd_fw_initialize()- Initialize FW
782 * @ctrl: Pointer to function control structure
784 * Send FW initialize pattern for the function.
786 * return
787 * Success: 0
788 * Failure: Non-Zero value
790 int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
792 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
793 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
794 int status;
795 u8 *endian_check;
797 spin_lock(&ctrl->mbox_lock);
798 memset(wrb, 0, sizeof(*wrb));
800 endian_check = (u8 *) wrb;
801 *endian_check++ = 0xFF;
802 *endian_check++ = 0x12;
803 *endian_check++ = 0x34;
804 *endian_check++ = 0xFF;
805 *endian_check++ = 0xFF;
806 *endian_check++ = 0x56;
807 *endian_check++ = 0x78;
808 *endian_check++ = 0xFF;
809 be_dws_cpu_to_le(wrb, sizeof(*wrb));
811 status = be_mbox_notify(ctrl);
812 if (status)
813 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
814 "BC_%d : be_cmd_fw_initialize Failed\n");
816 spin_unlock(&ctrl->mbox_lock);
817 return status;
821 * be_cmd_fw_uninit()- Uinitialize FW
822 * @ctrl: Pointer to function control structure
824 * Send FW uninitialize pattern for the function
826 * return
827 * Success: 0
828 * Failure: Non-Zero value
830 int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
832 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
833 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
834 int status;
835 u8 *endian_check;
837 spin_lock(&ctrl->mbox_lock);
838 memset(wrb, 0, sizeof(*wrb));
840 endian_check = (u8 *) wrb;
841 *endian_check++ = 0xFF;
842 *endian_check++ = 0xAA;
843 *endian_check++ = 0xBB;
844 *endian_check++ = 0xFF;
845 *endian_check++ = 0xFF;
846 *endian_check++ = 0xCC;
847 *endian_check++ = 0xDD;
848 *endian_check = 0xFF;
850 be_dws_cpu_to_le(wrb, sizeof(*wrb));
852 status = be_mbox_notify(ctrl);
853 if (status)
854 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
855 "BC_%d : be_cmd_fw_uninit Failed\n");
857 spin_unlock(&ctrl->mbox_lock);
858 return status;
861 int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
862 struct be_queue_info *cq, struct be_queue_info *eq,
863 bool sol_evts, bool no_delay, int coalesce_wm)
865 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
866 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
867 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
868 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
869 struct be_dma_mem *q_mem = &cq->dma_mem;
870 void *ctxt = &req->context;
871 int status;
873 spin_lock(&ctrl->mbox_lock);
874 memset(wrb, 0, sizeof(*wrb));
876 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
878 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
879 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
881 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
882 if (is_chip_be2_be3r(phba)) {
883 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
884 ctxt, coalesce_wm);
885 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
886 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
887 __ilog2_u32(cq->len / 256));
888 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
889 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
890 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
891 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
892 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
893 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
894 PCI_FUNC(ctrl->pdev->devfn));
895 } else {
896 req->hdr.version = MBX_CMD_VER2;
897 req->page_size = 1;
898 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
899 ctxt, coalesce_wm);
900 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
901 ctxt, no_delay);
902 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
903 __ilog2_u32(cq->len / 256));
904 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
905 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
906 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
907 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
910 be_dws_cpu_to_le(ctxt, sizeof(req->context));
912 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
914 status = be_mbox_notify(ctrl);
915 if (!status) {
916 cq->id = le16_to_cpu(resp->cq_id);
917 cq->created = true;
918 } else
919 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
920 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
921 status);
923 spin_unlock(&ctrl->mbox_lock);
925 return status;
928 static u32 be_encoded_q_len(int q_len)
930 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
931 if (len_encoded == 16)
932 len_encoded = 0;
933 return len_encoded;
936 int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
937 struct be_queue_info *mccq,
938 struct be_queue_info *cq)
940 struct be_mcc_wrb *wrb;
941 struct be_cmd_req_mcc_create *req;
942 struct be_dma_mem *q_mem = &mccq->dma_mem;
943 struct be_ctrl_info *ctrl;
944 void *ctxt;
945 int status;
947 spin_lock(&phba->ctrl.mbox_lock);
948 ctrl = &phba->ctrl;
949 wrb = wrb_from_mbox(&ctrl->mbox_mem);
950 memset(wrb, 0, sizeof(*wrb));
951 req = embedded_payload(wrb);
952 ctxt = &req->context;
954 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
956 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
957 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
959 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
961 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
962 PCI_FUNC(phba->pcidev->devfn));
963 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
964 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
965 be_encoded_q_len(mccq->len));
966 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
968 be_dws_cpu_to_le(ctxt, sizeof(req->context));
970 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
972 status = be_mbox_notify_wait(phba);
973 if (!status) {
974 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
975 mccq->id = le16_to_cpu(resp->id);
976 mccq->created = true;
978 spin_unlock(&phba->ctrl.mbox_lock);
980 return status;
983 int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
984 int queue_type)
986 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
987 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
988 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
989 u8 subsys = 0, opcode = 0;
990 int status;
992 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
993 "BC_%d : In beiscsi_cmd_q_destroy "
994 "queue_type : %d\n", queue_type);
996 spin_lock(&ctrl->mbox_lock);
997 memset(wrb, 0, sizeof(*wrb));
998 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1000 switch (queue_type) {
1001 case QTYPE_EQ:
1002 subsys = CMD_SUBSYSTEM_COMMON;
1003 opcode = OPCODE_COMMON_EQ_DESTROY;
1004 break;
1005 case QTYPE_CQ:
1006 subsys = CMD_SUBSYSTEM_COMMON;
1007 opcode = OPCODE_COMMON_CQ_DESTROY;
1008 break;
1009 case QTYPE_MCCQ:
1010 subsys = CMD_SUBSYSTEM_COMMON;
1011 opcode = OPCODE_COMMON_MCC_DESTROY;
1012 break;
1013 case QTYPE_WRBQ:
1014 subsys = CMD_SUBSYSTEM_ISCSI;
1015 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1016 break;
1017 case QTYPE_DPDUQ:
1018 subsys = CMD_SUBSYSTEM_ISCSI;
1019 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1020 break;
1021 case QTYPE_SGL:
1022 subsys = CMD_SUBSYSTEM_ISCSI;
1023 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1024 break;
1025 default:
1026 spin_unlock(&ctrl->mbox_lock);
1027 BUG();
1028 return -ENXIO;
1030 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1031 if (queue_type != QTYPE_SGL)
1032 req->id = cpu_to_le16(q->id);
1034 status = be_mbox_notify(ctrl);
1036 spin_unlock(&ctrl->mbox_lock);
1037 return status;
1041 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1042 * @ctrl: ptr to ctrl_info
1043 * @cq: Completion Queue
1044 * @dq: Default Queue
1045 * @lenght: ring size
1046 * @entry_size: size of each entry in DEFQ
1047 * @is_header: Header or Data DEFQ
1048 * @ulp_num: Bind to which ULP
1050 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1051 * on this queue by the FW
1053 * return
1054 * Success: 0
1055 * Failure: Non-Zero Value
1058 int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1059 struct be_queue_info *cq,
1060 struct be_queue_info *dq, int length,
1061 int entry_size, uint8_t is_header,
1062 uint8_t ulp_num)
1064 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1065 struct be_defq_create_req *req = embedded_payload(wrb);
1066 struct be_dma_mem *q_mem = &dq->dma_mem;
1067 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
1068 void *ctxt = &req->context;
1069 int status;
1071 spin_lock(&ctrl->mbox_lock);
1072 memset(wrb, 0, sizeof(*wrb));
1074 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1076 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1077 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1079 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1080 if (phba->fw_config.dual_ulp_aware) {
1081 req->ulp_num = ulp_num;
1082 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1083 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1086 if (is_chip_be2_be3r(phba)) {
1087 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1088 rx_pdid, ctxt, 0);
1089 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1090 rx_pdid_valid, ctxt, 1);
1091 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1092 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1093 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1094 ring_size, ctxt,
1095 be_encoded_q_len(length /
1096 sizeof(struct phys_addr)));
1097 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1098 default_buffer_size, ctxt, entry_size);
1099 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1100 cq_id_recv, ctxt, cq->id);
1101 } else {
1102 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1103 rx_pdid, ctxt, 0);
1104 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1105 rx_pdid_valid, ctxt, 1);
1106 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1107 ring_size, ctxt,
1108 be_encoded_q_len(length /
1109 sizeof(struct phys_addr)));
1110 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1111 default_buffer_size, ctxt, entry_size);
1112 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1113 cq_id_recv, ctxt, cq->id);
1116 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1118 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1120 status = be_mbox_notify(ctrl);
1121 if (!status) {
1122 struct be_ring *defq_ring;
1123 struct be_defq_create_resp *resp = embedded_payload(wrb);
1125 dq->id = le16_to_cpu(resp->id);
1126 dq->created = true;
1127 if (is_header)
1128 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1129 else
1130 defq_ring = &phba->phwi_ctrlr->
1131 default_pdu_data[ulp_num];
1133 defq_ring->id = dq->id;
1135 if (!phba->fw_config.dual_ulp_aware) {
1136 defq_ring->ulp_num = BEISCSI_ULP0;
1137 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1138 } else {
1139 defq_ring->ulp_num = resp->ulp_num;
1140 defq_ring->doorbell_offset = resp->doorbell_offset;
1143 spin_unlock(&ctrl->mbox_lock);
1145 return status;
1149 * be_cmd_wrbq_create()- Create WRBQ
1150 * @ctrl: ptr to ctrl_info
1151 * @q_mem: memory details for the queue
1152 * @wrbq: queue info
1153 * @pwrb_context: ptr to wrb_context
1154 * @ulp_num: ULP on which the WRBQ is to be created
1156 * Create WRBQ on the passed ULP_NUM.
1159 int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1160 struct be_dma_mem *q_mem,
1161 struct be_queue_info *wrbq,
1162 struct hwi_wrb_context *pwrb_context,
1163 uint8_t ulp_num)
1165 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1166 struct be_wrbq_create_req *req = embedded_payload(wrb);
1167 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
1168 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
1169 int status;
1171 spin_lock(&ctrl->mbox_lock);
1172 memset(wrb, 0, sizeof(*wrb));
1174 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1176 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1177 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1178 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1180 if (phba->fw_config.dual_ulp_aware) {
1181 req->ulp_num = ulp_num;
1182 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1183 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1186 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1188 status = be_mbox_notify(ctrl);
1189 if (!status) {
1190 wrbq->id = le16_to_cpu(resp->cid);
1191 wrbq->created = true;
1193 pwrb_context->cid = wrbq->id;
1194 if (!phba->fw_config.dual_ulp_aware) {
1195 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1196 pwrb_context->ulp_num = BEISCSI_ULP0;
1197 } else {
1198 pwrb_context->ulp_num = resp->ulp_num;
1199 pwrb_context->doorbell_offset = resp->doorbell_offset;
1202 spin_unlock(&ctrl->mbox_lock);
1203 return status;
1206 int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1207 struct be_dma_mem *q_mem)
1209 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1210 struct be_post_template_pages_req *req = embedded_payload(wrb);
1211 int status;
1213 spin_lock(&ctrl->mbox_lock);
1215 memset(wrb, 0, sizeof(*wrb));
1216 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1217 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1218 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1219 sizeof(*req));
1221 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1222 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1223 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1225 status = be_mbox_notify(ctrl);
1226 spin_unlock(&ctrl->mbox_lock);
1227 return status;
1230 int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1232 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1233 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1234 int status;
1236 spin_lock(&ctrl->mbox_lock);
1238 memset(wrb, 0, sizeof(*wrb));
1239 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1240 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1241 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1242 sizeof(*req));
1244 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1246 status = be_mbox_notify(ctrl);
1247 spin_unlock(&ctrl->mbox_lock);
1248 return status;
1251 int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1252 struct be_dma_mem *q_mem,
1253 u32 page_offset, u32 num_pages)
1255 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1256 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1257 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
1258 int status;
1259 unsigned int curr_pages;
1260 u32 internal_page_offset = 0;
1261 u32 temp_num_pages = num_pages;
1263 if (num_pages == 0xff)
1264 num_pages = 1;
1266 spin_lock(&ctrl->mbox_lock);
1267 do {
1268 memset(wrb, 0, sizeof(*wrb));
1269 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1270 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1271 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1272 sizeof(*req));
1273 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1274 pages);
1275 req->num_pages = min(num_pages, curr_pages);
1276 req->page_offset = page_offset;
1277 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1278 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1279 internal_page_offset += req->num_pages;
1280 page_offset += req->num_pages;
1281 num_pages -= req->num_pages;
1283 if (temp_num_pages == 0xff)
1284 req->num_pages = temp_num_pages;
1286 status = be_mbox_notify(ctrl);
1287 if (status) {
1288 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1289 "BC_%d : FW CMD to map iscsi frags failed.\n");
1291 goto error;
1293 } while (num_pages > 0);
1294 error:
1295 spin_unlock(&ctrl->mbox_lock);
1296 if (status != 0)
1297 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1298 return status;
1301 int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1303 struct be_ctrl_info *ctrl = &phba->ctrl;
1304 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1305 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1306 int status;
1308 spin_lock(&ctrl->mbox_lock);
1310 req = embedded_payload(wrb);
1311 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1312 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1313 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1314 status = be_mbox_notify_wait(phba);
1316 spin_unlock(&ctrl->mbox_lock);
1317 return status;
1321 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1322 * @phba: device priv structure instance
1323 * @vlan_tag: TAG to be set
1325 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1327 * returns
1328 * TAG for the MBX Cmd
1329 * **/
1330 int be_cmd_set_vlan(struct beiscsi_hba *phba,
1331 uint16_t vlan_tag)
1333 unsigned int tag = 0;
1334 struct be_mcc_wrb *wrb;
1335 struct be_cmd_set_vlan_req *req;
1336 struct be_ctrl_info *ctrl = &phba->ctrl;
1338 spin_lock(&ctrl->mbox_lock);
1339 tag = alloc_mcc_tag(phba);
1340 if (!tag) {
1341 spin_unlock(&ctrl->mbox_lock);
1342 return tag;
1345 wrb = wrb_from_mccq(phba);
1346 req = embedded_payload(wrb);
1347 wrb->tag0 |= tag;
1348 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1349 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1350 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1351 sizeof(*req));
1353 req->interface_hndl = phba->interface_handle;
1354 req->vlan_priority = vlan_tag;
1356 be_mcc_notify(phba);
1357 spin_unlock(&ctrl->mbox_lock);
1359 return tag;