blob: 12b60dd8d1c94a0fa0fca0596149ae3c31c0c92d [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +05302 * Copyright (C) 2005 - 2015 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
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.
9 *
10 * Contact Information:
Minh Tran4627de92015-05-14 23:16:17 -070011 * linux-drivers@avagotech.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053012 *
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +053013 * Emulex
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070014 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053016 */
17
John Soni Jose21771992012-04-03 23:41:49 -050018#include <scsi/iscsi_proto.h>
19
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -070020#include "be_main.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053021#include "be.h"
22#include "be_mgmt.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023
Jayamohan Kallickale9b91192010-07-22 04:24:53 +053024int beiscsi_pci_soft_reset(struct beiscsi_hba *phba)
25{
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;
33
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);
40
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++;
48 }
49
50 if (sreset & BE2_SET_RESET) {
John Soni Jose99bc5d52012-08-20 23:00:18 +053051 printk(KERN_ERR DRV_NAME
52 " Soft Reset did not deassert\n");
Jayamohan Kallickale9b91192010-07-22 04:24:53 +053053 return -EIO;
54 }
55 pconline1 = BE2_MPU_IRAM_ONLINE;
56 writel(pconline0, (void *)pci_online0_offset);
57 writel(pconline1, (void *)pci_online1_offset);
58
Minh Tran1d8bc702012-10-20 04:41:24 +053059 sreset |= BE2_SET_RESET;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +053060 writel(sreset, (void *)pci_reset_offset);
61
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++;
69 }
70 if (sreset & BE2_SET_RESET) {
John Soni Jose99bc5d52012-08-20 23:00:18 +053071 printk(KERN_ERR DRV_NAME
72 " MPU Online Soft Reset did not deassert\n");
Jayamohan Kallickale9b91192010-07-22 04:24:53 +053073 return -EIO;
74 }
75 return 0;
76}
77
78int be_chk_reset_complete(struct beiscsi_hba *phba)
79{
80 unsigned int num_loop;
81 u8 *mpu_sem = 0;
82 u32 status;
83
84 num_loop = 1000;
85 mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
86 msleep(5000);
87
88 while (num_loop) {
89 status = readl((void *)mpu_sem);
90
91 if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000)
92 break;
93 msleep(60);
94 num_loop--;
95 }
96
97 if ((status & 0x80000000) || (!num_loop)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +053098 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
99 "BC_%d : Failed in be_chk_reset_complete"
100 "status = 0x%x\n", status);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +0530101 return -EIO;
102 }
103
104 return 0;
105}
106
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530107void be_mcc_notify(struct beiscsi_hba *phba, unsigned int tag)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530108{
109 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
110 u32 val = 0;
111
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530112 set_bit(MCC_TAG_STATE_RUNNING, &phba->ctrl.ptag_state[tag].tag_state);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530113 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
114 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530115 /* ring doorbell after all of request and state is written */
116 wmb();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530117 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
118}
119
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530120unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
121{
122 unsigned int tag = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530123
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530124 spin_lock(&phba->ctrl.mcc_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530125 if (phba->ctrl.mcc_tag_available) {
126 tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
127 phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530128 phba->ctrl.mcc_tag_status[tag] = 0;
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530129 phba->ctrl.ptag_state[tag].tag_state = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530130 }
131 if (tag) {
132 phba->ctrl.mcc_tag_available--;
133 if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
134 phba->ctrl.mcc_alloc_index = 0;
135 else
136 phba->ctrl.mcc_alloc_index++;
137 }
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530138 spin_unlock(&phba->ctrl.mcc_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530139 return tag;
140}
141
John Soni Josee175def2012-10-20 04:45:40 +0530142/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530143 * beiscsi_mccq_compl_wait()- Process completion in MCC CQ
John Soni Josee175def2012-10-20 04:45:40 +0530144 * @phba: Driver private structure
145 * @tag: Tag for the MBX Command
146 * @wrb: the WRB used for the MBX Command
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500147 * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
John Soni Josee175def2012-10-20 04:45:40 +0530148 *
149 * Waits for MBX completion with the passed TAG.
150 *
151 * return
152 * Success: 0
153 * Failure: Non-Zero
154 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530155int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba,
156 uint32_t tag, struct be_mcc_wrb **wrb,
157 struct be_dma_mem *mbx_cmd_mem)
John Soni Josee175def2012-10-20 04:45:40 +0530158{
159 int rc = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530160 uint32_t mcc_tag_status;
John Soni Josee175def2012-10-20 04:45:40 +0530161 uint16_t status = 0, addl_status = 0, wrb_num = 0;
162 struct be_mcc_wrb *temp_wrb;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500163 struct be_cmd_req_hdr *mbx_hdr;
164 struct be_cmd_resp_hdr *mbx_resp_hdr;
John Soni Josee175def2012-10-20 04:45:40 +0530165 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
166
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700167 if (beiscsi_error(phba)) {
168 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500169 return -EPERM;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700170 }
John Soni Jose7a158002012-10-20 04:45:51 +0530171
John Soni Josee175def2012-10-20 04:45:40 +0530172 /* wait for the mccq completion */
173 rc = wait_event_interruptible_timeout(
174 phba->ctrl.mcc_wait[tag],
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530175 phba->ctrl.mcc_tag_status[tag],
John Soni Josee175def2012-10-20 04:45:40 +0530176 msecs_to_jiffies(
177 BEISCSI_HOST_MBX_TIMEOUT));
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530178 /**
179 * If MBOX cmd timeout expired, tag and resource allocated
180 * for cmd is not freed until FW returns completion.
181 */
John Soni Josee175def2012-10-20 04:45:40 +0530182 if (rc <= 0) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500183 struct be_dma_mem *tag_mem;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500184
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530185 /**
186 * PCI/DMA memory allocated and posted in non-embedded mode
187 * will have mbx_cmd_mem != NULL.
188 * Save virtual and bus addresses for the command so that it
189 * can be freed later.
190 **/
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500191 tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
192 if (mbx_cmd_mem) {
193 tag_mem->size = mbx_cmd_mem->size;
194 tag_mem->va = mbx_cmd_mem->va;
195 tag_mem->dma = mbx_cmd_mem->dma;
196 } else
197 tag_mem->size = 0;
198
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530199 /* first make tag_mem_state visible to all */
200 wmb();
201 set_bit(MCC_TAG_STATE_TIMEOUT,
202 &phba->ctrl.ptag_state[tag].tag_state);
203
John Soni Josee175def2012-10-20 04:45:40 +0530204 beiscsi_log(phba, KERN_ERR,
205 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
206 BEISCSI_LOG_CONFIG,
207 "BC_%d : MBX Cmd Completion timed out\n");
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500208 return -EBUSY;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500209 }
John Soni Josee175def2012-10-20 04:45:40 +0530210
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530211 rc = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530212 mcc_tag_status = phba->ctrl.mcc_tag_status[tag];
213 status = (mcc_tag_status & CQE_STATUS_MASK);
214 addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >>
John Soni Josee175def2012-10-20 04:45:40 +0530215 CQE_STATUS_ADDL_SHIFT);
216
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500217 if (mbx_cmd_mem) {
218 mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va;
John Soni Josee175def2012-10-20 04:45:40 +0530219 } else {
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530220 wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >>
John Soni Josee175def2012-10-20 04:45:40 +0530221 CQE_STATUS_WRB_SHIFT;
222 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500223 mbx_hdr = embedded_payload(temp_wrb);
John Soni Josee175def2012-10-20 04:45:40 +0530224
225 if (wrb)
226 *wrb = temp_wrb;
227 }
228
229 if (status || addl_status) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500230 beiscsi_log(phba, KERN_WARNING,
John Soni Josee175def2012-10-20 04:45:40 +0530231 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
232 BEISCSI_LOG_CONFIG,
233 "BC_%d : MBX Cmd Failed for "
234 "Subsys : %d Opcode : %d with "
235 "Status : %d and Extd_Status : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500236 mbx_hdr->subsystem,
237 mbx_hdr->opcode,
John Soni Josee175def2012-10-20 04:45:40 +0530238 status, addl_status);
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530239 rc = -EIO;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700240 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500241 mbx_resp_hdr = (struct be_cmd_resp_hdr *) mbx_hdr;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700242 beiscsi_log(phba, KERN_WARNING,
243 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
244 BEISCSI_LOG_CONFIG,
Masanari Iidad939be32015-02-27 23:52:31 +0900245 "BC_%d : Insufficient Buffer Error "
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700246 "Resp_Len : %d Actual_Resp_Len : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500247 mbx_resp_hdr->response_length,
248 mbx_resp_hdr->actual_resp_len);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700249 rc = -EAGAIN;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700250 }
John Soni Josee175def2012-10-20 04:45:40 +0530251 }
252
John Soni Josee175def2012-10-20 04:45:40 +0530253 free_mcc_tag(&phba->ctrl, tag);
John Soni Josee175def2012-10-20 04:45:40 +0530254 return rc;
255}
256
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530257void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
258{
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530259 spin_lock(&ctrl->mcc_lock);
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530260 tag = tag & MCC_Q_CMD_TAG_MASK;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530261 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
262 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
263 ctrl->mcc_free_index = 0;
264 else
265 ctrl->mcc_free_index++;
266 ctrl->mcc_tag_available++;
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530267 spin_unlock(&ctrl->mcc_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530268}
269
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530270static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
271{
272 if (compl->flags != 0) {
273 compl->flags = le32_to_cpu(compl->flags);
274 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
275 return true;
276 } else
277 return false;
278}
279
280static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
281{
282 compl->flags = 0;
283}
284
John Soni Josee175def2012-10-20 04:45:40 +0530285/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530286 * beiscsi_process_mbox_compl()- Check the MBX completion status
John Soni Josee175def2012-10-20 04:45:40 +0530287 * @ctrl: Function specific MBX data structure
288 * @compl: Completion status of MBX Command
289 *
290 * Check for the MBX completion status when BMBX method used
291 *
292 * return
293 * Success: Zero
294 * Failure: Non-Zero
295 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530296static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl,
297 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530298{
299 u16 compl_status, extd_status;
John Soni Josee175def2012-10-20 04:45:40 +0530300 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530301 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
John Soni Josee175def2012-10-20 04:45:40 +0530302 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700303 struct be_cmd_resp_hdr *resp_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530304
305 be_dws_le_to_cpu(compl, 4);
306
307 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
308 CQE_STATUS_COMPL_MASK;
309 if (compl_status != MCC_STATUS_SUCCESS) {
310 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
311 CQE_STATUS_EXTD_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530312
313 beiscsi_log(phba, KERN_ERR,
314 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530315 "BC_%d : error in cmd completion: "
316 "Subsystem : %d Opcode : %d "
317 "status(compl/extd)=%d/%d\n",
318 hdr->subsystem, hdr->opcode,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530319 compl_status, extd_status);
320
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700321 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
322 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
323 if (resp_hdr->response_length)
324 return 0;
325 }
Jitendra Bhivare23d7ccf12016-01-20 14:10:55 +0530326 return -EINVAL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530327 }
328 return 0;
329}
330
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500331/**
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +0530332 * beiscsi_fail_session(): Closing session with appropriate error
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500333 * @cls_session: ptr to session
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500334 **/
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +0530335void beiscsi_fail_session(struct iscsi_cls_session *cls_session)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530336{
337 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
338}
339
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530340static void beiscsi_process_async_link(struct beiscsi_hba *phba,
341 struct be_mcc_compl *compl)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530342{
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530343 struct be_async_event_link_state *evt;
344
345 evt = (struct be_async_event_link_state *)compl;
346
Jitendra Bhivare048084c2016-01-20 14:10:58 +0530347 phba->port_speed = evt->port_speed;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530348 /**
349 * Check logical link status in ASYNC event.
350 * This has been newly introduced in SKH-R Firmware 10.0.338.45.
351 **/
352 if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) {
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -0400353 phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT;
John Soni Jose3efde862015-04-25 08:16:57 +0530354 phba->get_boot = BE_GET_BOOT_RETRIES;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530355 __beiscsi_log(phba, KERN_ERR,
356 "BC_%d : Link Up on Port %d tag 0x%x\n",
357 evt->physical_port, evt->event_tag);
358 } else {
359 phba->state = BE_ADAPTER_LINK_DOWN;
360 __beiscsi_log(phba, KERN_ERR,
361 "BC_%d : Link Down on Port %d tag 0x%x\n",
362 evt->physical_port, evt->event_tag);
363 iscsi_host_for_each_session(phba->shost,
364 beiscsi_fail_session);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530365 }
366}
367
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530368static char *beiscsi_port_misconf_event_msg[] = {
369 "Physical Link is functional.",
370 "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.",
371 "Optics of two types installed - Remove one optic or install matching pair of optics.",
372 "Incompatible optics - Replace with compatible optics for card to function.",
373 "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.",
374 "Uncertified optics - Replace with Avago Certified optics to enable link operation."
375};
376
377static void beiscsi_process_async_sli(struct beiscsi_hba *phba,
378 struct be_mcc_compl *compl)
379{
380 struct be_async_event_sli *async_sli;
381 u8 evt_type, state, old_state, le;
382 char *sev = KERN_WARNING;
383 char *msg = NULL;
384
385 evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT;
386 evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK;
387
388 /* processing only MISCONFIGURED physical port event */
389 if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED)
390 return;
391
392 async_sli = (struct be_async_event_sli *)compl;
393 state = async_sli->event_data1 >>
394 (phba->fw_config.phys_port * 8) & 0xff;
395 le = async_sli->event_data2 >>
396 (phba->fw_config.phys_port * 8) & 0xff;
397
398 old_state = phba->optic_state;
399 phba->optic_state = state;
400
401 if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) {
402 /* fw is reporting a state we don't know, log and return */
403 __beiscsi_log(phba, KERN_ERR,
404 "BC_%d : Port %c: Unrecognized optic state 0x%x\n",
405 phba->port_name, async_sli->event_data1);
406 return;
407 }
408
409 if (ASYNC_SLI_LINK_EFFECT_VALID(le)) {
410 /* log link effect for unqualified-4, uncertified-5 optics */
411 if (state > 3)
412 msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ?
413 " Link is non-operational." :
414 " Link is operational.";
415 /* 1 - info */
416 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1)
417 sev = KERN_INFO;
418 /* 2 - error */
419 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2)
420 sev = KERN_ERR;
421 }
422
423 if (old_state != phba->optic_state)
424 __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n",
425 phba->port_name,
426 beiscsi_port_misconf_event_msg[state],
427 !msg ? "" : msg);
428}
429
430void beiscsi_process_async_event(struct beiscsi_hba *phba,
431 struct be_mcc_compl *compl)
432{
433 char *sev = KERN_INFO;
434 u8 evt_code;
435
436 /* interpret flags as an async trailer */
437 evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT;
438 evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK;
439 switch (evt_code) {
440 case ASYNC_EVENT_CODE_LINK_STATE:
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530441 beiscsi_process_async_link(phba, compl);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530442 break;
443 case ASYNC_EVENT_CODE_ISCSI:
444 phba->state |= BE_ADAPTER_CHECK_BOOT;
445 phba->get_boot = BE_GET_BOOT_RETRIES;
446 sev = KERN_ERR;
447 break;
448 case ASYNC_EVENT_CODE_SLI:
449 beiscsi_process_async_sli(phba, compl);
450 break;
451 default:
452 /* event not registered */
453 sev = KERN_ERR;
454 }
455
456 beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530457 "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n",
458 evt_code, compl->status, compl->flags);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530459}
460
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530461int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
462 struct be_mcc_compl *compl)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530463{
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530464 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
465 u16 compl_status, extd_status;
466 struct be_dma_mem *tag_mem;
467 unsigned int tag, wrb_idx;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530468
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530469 /**
470 * Just swap the status to host endian; mcc tag is opaquely copied
471 * from mcc_wrb
472 */
473 be_dws_le_to_cpu(compl, 4);
474 tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK);
475 wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT;
476
477 if (!test_bit(MCC_TAG_STATE_RUNNING,
478 &ctrl->ptag_state[tag].tag_state)) {
479 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX |
480 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
481 "BC_%d : MBX cmd completed but not posted\n");
482 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530483 }
484
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530485 if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) {
486 beiscsi_log(phba, KERN_WARNING,
487 BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
488 BEISCSI_LOG_CONFIG,
489 "BC_%d : MBX Completion for timeout Command from FW\n");
490 /**
491 * Check for the size before freeing resource.
492 * Only for non-embedded cmd, PCI resource is allocated.
493 **/
494 tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
495 if (tag_mem->size)
496 pci_free_consistent(ctrl->pdev, tag_mem->size,
497 tag_mem->va, tag_mem->dma);
498 free_mcc_tag(ctrl, tag);
499 return 0;
500 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530501
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530502 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
503 CQE_STATUS_COMPL_MASK;
504 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
505 CQE_STATUS_EXTD_MASK;
506 /* The ctrl.mcc_tag_status[tag] is filled with
507 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
508 * [7:0] = compl_status
509 */
510 ctrl->mcc_tag_status[tag] = CQE_VALID_MASK;
511 ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT);
512 ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) &
513 CQE_STATUS_ADDL_MASK;
514 ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK);
515
516 /* write ordering forced in wake_up_interruptible */
517 clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state);
518 wake_up_interruptible(&ctrl->mcc_wait[tag]);
519 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530520}
521
John Soni Josee175def2012-10-20 04:45:40 +0530522/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530523 * be_mcc_compl_poll()- Wait for MBX completion
John Soni Josee175def2012-10-20 04:45:40 +0530524 * @phba: driver private structure
525 *
526 * Wait till no more pending mcc requests are present
527 *
528 * return
529 * Success: 0
530 * Failure: Non-Zero
531 *
532 **/
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530533int be_mcc_compl_poll(struct beiscsi_hba *phba, unsigned int tag)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530534{
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530535 int i;
536
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530537 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530538 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530539 return -EIO;
540
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530541 beiscsi_process_mcc_cq(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530542
543 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
544 break;
545 udelay(100);
546 }
547 if (i == mcc_timeout) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530548 beiscsi_log(phba, KERN_ERR,
549 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530550 "BC_%d : FW Timed Out\n");
551 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530552 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530553 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530554 }
555 return 0;
556}
557
John Soni Josee175def2012-10-20 04:45:40 +0530558/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530559 * be_mbox_db_ready_poll()- Check ready status
John Soni Josee175def2012-10-20 04:45:40 +0530560 * @ctrl: Function specific MBX data structure
561 *
562 * Check for the ready status of FW to send BMBX
563 * commands to adapter.
564 *
565 * return
566 * Success: 0
567 * Failure: Non-Zero
568 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530569static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530570{
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530571 /* wait 30s for generic non-flash MBOX operation */
572#define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530573 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530574 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700575 unsigned long timeout;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530576 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700577
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530578 /*
579 * This BMBX busy wait path is used during init only.
580 * For the commands executed during init, 5s should suffice.
581 */
582 timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530583 do {
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530584 if (beiscsi_error(phba))
585 return -EIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530586
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530587 ready = ioread32(db);
588 if (ready == 0xffffffff)
589 return -EIO;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700590
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530591 ready &= MPU_MAILBOX_DB_RDY_MASK;
592 if (ready)
593 return 0;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700594
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530595 if (time_after(jiffies, timeout))
596 break;
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530597 msleep(20);
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530598 } while (!ready);
599
600 beiscsi_log(phba, KERN_ERR,
601 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
602 "BC_%d : FW Timed Out\n");
603
604 phba->fw_timeout = true;
605 beiscsi_ue_detect(phba);
606
607 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530608}
609
John Soni Josee175def2012-10-20 04:45:40 +0530610/*
611 * be_mbox_notify: Notify adapter of new BMBX command
612 * @ctrl: Function specific MBX data structure
613 *
614 * Ring doorbell to inform adapter of a BMBX command
615 * to process
616 *
617 * return
618 * Success: 0
619 * Failure: Non-Zero
620 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530621int be_mbox_notify(struct be_ctrl_info *ctrl)
622{
623 int status;
624 u32 val = 0;
625 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
626 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
627 struct be_mcc_mailbox *mbox = mbox_mem->va;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530628
Jitendra Bhivare88840332016-02-04 15:49:12 +0530629 status = be_mbox_db_ready_poll(ctrl);
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700630 if (status)
631 return status;
632
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530633 val &= ~MPU_MAILBOX_DB_RDY_MASK;
634 val |= MPU_MAILBOX_DB_HI_MASK;
635 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
636 iowrite32(val, db);
637
Jitendra Bhivare88840332016-02-04 15:49:12 +0530638 status = be_mbox_db_ready_poll(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530639 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530640 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530641
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530642 val = 0;
643 val &= ~MPU_MAILBOX_DB_RDY_MASK;
644 val &= ~MPU_MAILBOX_DB_HI_MASK;
645 val |= (u32) (mbox_mem->dma >> 4) << 2;
646 iowrite32(val, db);
647
Jitendra Bhivare88840332016-02-04 15:49:12 +0530648 status = be_mbox_db_ready_poll(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530649 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530650 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530651
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530652 /* RDY is set; small delay before CQE read. */
653 udelay(1);
654
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +0530655 status = beiscsi_process_mbox_compl(ctrl, &mbox->compl);
656 return status;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530657}
658
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530659void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
660 bool embedded, u8 sge_cnt)
661{
662 if (embedded)
663 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
664 else
665 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
666 MCC_WRB_SGE_CNT_SHIFT;
667 wrb->payload_length = payload_len;
668 be_dws_cpu_to_le(wrb, 8);
669}
670
671void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
672 u8 subsystem, u8 opcode, int cmd_len)
673{
674 req_hdr->opcode = opcode;
675 req_hdr->subsystem = subsystem;
676 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530677 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530678}
679
680static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
681 struct be_dma_mem *mem)
682{
683 int i, buf_pages;
684 u64 dma = (u64) mem->dma;
685
686 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
687 for (i = 0; i < buf_pages; i++) {
688 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
689 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
690 dma += PAGE_SIZE_4K;
691 }
692}
693
694static u32 eq_delay_to_mult(u32 usec_delay)
695{
696#define MAX_INTR_RATE 651042
697 const u32 round = 10;
698 u32 multiplier;
699
700 if (usec_delay == 0)
701 multiplier = 0;
702 else {
703 u32 interrupt_rate = 1000000 / usec_delay;
704 if (interrupt_rate == 0)
705 multiplier = 1023;
706 else {
707 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
708 multiplier /= interrupt_rate;
709 multiplier = (multiplier + round / 2) / round;
710 multiplier = min(multiplier, (u32) 1023);
711 }
712 }
713 return multiplier;
714}
715
716struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
717{
718 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
719}
720
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530721struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
722{
723 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
724 struct be_mcc_wrb *wrb;
725
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700726 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530727 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530728 memset(wrb, 0, sizeof(*wrb));
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530729 wrb->tag0 = (mccq->head << MCC_Q_WRB_IDX_SHIFT) & MCC_Q_WRB_IDX_MASK;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530730 queue_head_inc(mccq);
731 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530732 return wrb;
733}
734
735
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530736int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
737 struct be_queue_info *eq, int eq_delay)
738{
739 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
740 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
741 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
742 struct be_dma_mem *q_mem = &eq->dma_mem;
743 int status;
744
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530745 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530746 memset(wrb, 0, sizeof(*wrb));
747
748 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
749
750 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
751 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
752
753 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
754
755 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
756 PCI_FUNC(ctrl->pdev->devfn));
757 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
758 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
759 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
760 __ilog2_u32(eq->len / 256));
761 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
762 eq_delay_to_mult(eq_delay));
763 be_dws_cpu_to_le(req->context, sizeof(req->context));
764
765 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
766
767 status = be_mbox_notify(ctrl);
768 if (!status) {
769 eq->id = le16_to_cpu(resp->eq_id);
770 eq->created = true;
771 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530772 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530773 return status;
774}
775
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700776/**
777 * be_cmd_fw_initialize()- Initialize FW
778 * @ctrl: Pointer to function control structure
779 *
780 * Send FW initialize pattern for the function.
781 *
782 * return
783 * Success: 0
784 * Failure: Non-Zero value
785 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530786int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
787{
788 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530789 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530790 int status;
791 u8 *endian_check;
792
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530793 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530794 memset(wrb, 0, sizeof(*wrb));
795
796 endian_check = (u8 *) wrb;
797 *endian_check++ = 0xFF;
798 *endian_check++ = 0x12;
799 *endian_check++ = 0x34;
800 *endian_check++ = 0xFF;
801 *endian_check++ = 0xFF;
802 *endian_check++ = 0x56;
803 *endian_check++ = 0x78;
804 *endian_check++ = 0xFF;
805 be_dws_cpu_to_le(wrb, sizeof(*wrb));
806
807 status = be_mbox_notify(ctrl);
808 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530809 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
810 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530811
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530812 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530813 return status;
814}
815
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700816/**
817 * be_cmd_fw_uninit()- Uinitialize FW
818 * @ctrl: Pointer to function control structure
819 *
820 * Send FW uninitialize pattern for the function
821 *
822 * return
823 * Success: 0
824 * Failure: Non-Zero value
825 **/
826int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
827{
828 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
829 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
830 int status;
831 u8 *endian_check;
832
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530833 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700834 memset(wrb, 0, sizeof(*wrb));
835
836 endian_check = (u8 *) wrb;
837 *endian_check++ = 0xFF;
838 *endian_check++ = 0xAA;
839 *endian_check++ = 0xBB;
840 *endian_check++ = 0xFF;
841 *endian_check++ = 0xFF;
842 *endian_check++ = 0xCC;
843 *endian_check++ = 0xDD;
844 *endian_check = 0xFF;
845
846 be_dws_cpu_to_le(wrb, sizeof(*wrb));
847
848 status = be_mbox_notify(ctrl);
849 if (status)
850 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
851 "BC_%d : be_cmd_fw_uninit Failed\n");
852
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530853 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700854 return status;
855}
856
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530857int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
858 struct be_queue_info *cq, struct be_queue_info *eq,
859 bool sol_evts, bool no_delay, int coalesce_wm)
860{
861 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
862 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
863 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530864 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530865 struct be_dma_mem *q_mem = &cq->dma_mem;
866 void *ctxt = &req->context;
867 int status;
868
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530869 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530870 memset(wrb, 0, sizeof(*wrb));
871
872 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
873
874 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
875 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530876
877 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700878 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530879 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
880 ctxt, coalesce_wm);
881 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
882 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
883 __ilog2_u32(cq->len / 256));
884 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
885 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
886 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
887 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
888 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
889 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
890 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700891 } else {
892 req->hdr.version = MBX_CMD_VER2;
893 req->page_size = 1;
894 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
895 ctxt, coalesce_wm);
896 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
897 ctxt, no_delay);
898 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
899 __ilog2_u32(cq->len / 256));
900 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
901 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
902 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
903 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +0530904 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530905
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530906 be_dws_cpu_to_le(ctxt, sizeof(req->context));
907
908 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
909
910 status = be_mbox_notify(ctrl);
911 if (!status) {
912 cq->id = le16_to_cpu(resp->cq_id);
913 cq->created = true;
914 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530915 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
916 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
917 status);
918
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530919 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530920
921 return status;
922}
923
924static u32 be_encoded_q_len(int q_len)
925{
926 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
927 if (len_encoded == 16)
928 len_encoded = 0;
929 return len_encoded;
930}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530931
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530932int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530933 struct be_queue_info *mccq,
934 struct be_queue_info *cq)
935{
936 struct be_mcc_wrb *wrb;
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530937 struct be_cmd_req_mcc_create_ext *req;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530938 struct be_dma_mem *q_mem = &mccq->dma_mem;
939 struct be_ctrl_info *ctrl;
940 void *ctxt;
941 int status;
942
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530943 mutex_lock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530944 ctrl = &phba->ctrl;
945 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -0500946 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530947 req = embedded_payload(wrb);
948 ctxt = &req->context;
949
950 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
951
952 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530953 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530954
955 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530956 req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
957 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
958 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530959
960 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
961 PCI_FUNC(phba->pcidev->devfn));
962 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
963 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
964 be_encoded_q_len(mccq->len));
965 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
966
967 be_dws_cpu_to_le(ctxt, sizeof(req->context));
968
969 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
970
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +0530971 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530972 if (!status) {
973 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
974 mccq->id = le16_to_cpu(resp->id);
975 mccq->created = true;
976 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530977 mutex_unlock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530978
979 return status;
980}
981
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530982int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
983 int queue_type)
984{
985 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
986 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530987 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530988 u8 subsys = 0, opcode = 0;
989 int status;
990
John Soni Jose99bc5d52012-08-20 23:00:18 +0530991 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
992 "BC_%d : In beiscsi_cmd_q_destroy "
993 "queue_type : %d\n", queue_type);
994
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530995 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530996 memset(wrb, 0, sizeof(*wrb));
997 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
998
999 switch (queue_type) {
1000 case QTYPE_EQ:
1001 subsys = CMD_SUBSYSTEM_COMMON;
1002 opcode = OPCODE_COMMON_EQ_DESTROY;
1003 break;
1004 case QTYPE_CQ:
1005 subsys = CMD_SUBSYSTEM_COMMON;
1006 opcode = OPCODE_COMMON_CQ_DESTROY;
1007 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301008 case QTYPE_MCCQ:
1009 subsys = CMD_SUBSYSTEM_COMMON;
1010 opcode = OPCODE_COMMON_MCC_DESTROY;
1011 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301012 case QTYPE_WRBQ:
1013 subsys = CMD_SUBSYSTEM_ISCSI;
1014 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1015 break;
1016 case QTYPE_DPDUQ:
1017 subsys = CMD_SUBSYSTEM_ISCSI;
1018 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1019 break;
1020 case QTYPE_SGL:
1021 subsys = CMD_SUBSYSTEM_ISCSI;
1022 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1023 break;
1024 default:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301025 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301026 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301027 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301028 }
1029 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1030 if (queue_type != QTYPE_SGL)
1031 req->id = cpu_to_le16(q->id);
1032
1033 status = be_mbox_notify(ctrl);
1034
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301035 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301036 return status;
1037}
1038
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001039/**
1040 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1041 * @ctrl: ptr to ctrl_info
1042 * @cq: Completion Queue
1043 * @dq: Default Queue
1044 * @lenght: ring size
1045 * @entry_size: size of each entry in DEFQ
1046 * @is_header: Header or Data DEFQ
1047 * @ulp_num: Bind to which ULP
1048 *
1049 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1050 * on this queue by the FW
1051 *
1052 * return
1053 * Success: 0
1054 * Failure: Non-Zero Value
1055 *
1056 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301057int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1058 struct be_queue_info *cq,
1059 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001060 int entry_size, uint8_t is_header,
1061 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301062{
1063 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1064 struct be_defq_create_req *req = embedded_payload(wrb);
1065 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001066 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301067 void *ctxt = &req->context;
1068 int status;
1069
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301070 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301071 memset(wrb, 0, sizeof(*wrb));
1072
1073 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1074
1075 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1076 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1077
1078 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001079 if (phba->fw_config.dual_ulp_aware) {
1080 req->ulp_num = ulp_num;
1081 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1082 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1083 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001084
1085 if (is_chip_be2_be3r(phba)) {
1086 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1087 rx_pdid, ctxt, 0);
1088 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1089 rx_pdid_valid, ctxt, 1);
1090 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1091 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1092 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1093 ring_size, ctxt,
1094 be_encoded_q_len(length /
1095 sizeof(struct phys_addr)));
1096 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1097 default_buffer_size, ctxt, entry_size);
1098 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1099 cq_id_recv, ctxt, cq->id);
1100 } else {
1101 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1102 rx_pdid, ctxt, 0);
1103 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1104 rx_pdid_valid, ctxt, 1);
1105 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1106 ring_size, ctxt,
1107 be_encoded_q_len(length /
1108 sizeof(struct phys_addr)));
1109 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1110 default_buffer_size, ctxt, entry_size);
1111 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1112 cq_id_recv, ctxt, cq->id);
1113 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301114
1115 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1116
1117 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1118
1119 status = be_mbox_notify(ctrl);
1120 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001121 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301122 struct be_defq_create_resp *resp = embedded_payload(wrb);
1123
1124 dq->id = le16_to_cpu(resp->id);
1125 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001126 if (is_header)
1127 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1128 else
1129 defq_ring = &phba->phwi_ctrlr->
1130 default_pdu_data[ulp_num];
1131
1132 defq_ring->id = dq->id;
1133
1134 if (!phba->fw_config.dual_ulp_aware) {
1135 defq_ring->ulp_num = BEISCSI_ULP0;
1136 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1137 } else {
1138 defq_ring->ulp_num = resp->ulp_num;
1139 defq_ring->doorbell_offset = resp->doorbell_offset;
1140 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301141 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301142 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301143
1144 return status;
1145}
1146
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001147/**
1148 * be_cmd_wrbq_create()- Create WRBQ
1149 * @ctrl: ptr to ctrl_info
1150 * @q_mem: memory details for the queue
1151 * @wrbq: queue info
1152 * @pwrb_context: ptr to wrb_context
1153 * @ulp_num: ULP on which the WRBQ is to be created
1154 *
1155 * Create WRBQ on the passed ULP_NUM.
1156 *
1157 **/
1158int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1159 struct be_dma_mem *q_mem,
1160 struct be_queue_info *wrbq,
1161 struct hwi_wrb_context *pwrb_context,
1162 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301163{
1164 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1165 struct be_wrbq_create_req *req = embedded_payload(wrb);
1166 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001167 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301168 int status;
1169
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301170 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301171 memset(wrb, 0, sizeof(*wrb));
1172
1173 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1174
1175 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1176 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1177 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001178
1179 if (phba->fw_config.dual_ulp_aware) {
1180 req->ulp_num = ulp_num;
1181 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1182 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1183 }
1184
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301185 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1186
1187 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301188 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301189 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301190 wrbq->created = true;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001191
1192 pwrb_context->cid = wrbq->id;
1193 if (!phba->fw_config.dual_ulp_aware) {
1194 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1195 pwrb_context->ulp_num = BEISCSI_ULP0;
1196 } else {
1197 pwrb_context->ulp_num = resp->ulp_num;
1198 pwrb_context->doorbell_offset = resp->doorbell_offset;
1199 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301200 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301201 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301202 return status;
1203}
1204
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001205int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1206 struct be_dma_mem *q_mem)
1207{
1208 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1209 struct be_post_template_pages_req *req = embedded_payload(wrb);
1210 int status;
1211
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301212 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001213
1214 memset(wrb, 0, sizeof(*wrb));
1215 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1216 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1217 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1218 sizeof(*req));
1219
1220 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1221 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1222 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1223
1224 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301225 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001226 return status;
1227}
1228
1229int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1230{
1231 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1232 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1233 int status;
1234
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301235 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001236
1237 memset(wrb, 0, sizeof(*wrb));
1238 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1239 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1240 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1241 sizeof(*req));
1242
1243 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1244
1245 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301246 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001247 return status;
1248}
1249
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301250int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1251 struct be_dma_mem *q_mem,
1252 u32 page_offset, u32 num_pages)
1253{
1254 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1255 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301256 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301257 int status;
1258 unsigned int curr_pages;
1259 u32 internal_page_offset = 0;
1260 u32 temp_num_pages = num_pages;
1261
1262 if (num_pages == 0xff)
1263 num_pages = 1;
1264
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301265 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301266 do {
1267 memset(wrb, 0, sizeof(*wrb));
1268 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1269 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1270 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1271 sizeof(*req));
1272 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1273 pages);
1274 req->num_pages = min(num_pages, curr_pages);
1275 req->page_offset = page_offset;
1276 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1277 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1278 internal_page_offset += req->num_pages;
1279 page_offset += req->num_pages;
1280 num_pages -= req->num_pages;
1281
1282 if (temp_num_pages == 0xff)
1283 req->num_pages = temp_num_pages;
1284
1285 status = be_mbox_notify(ctrl);
1286 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301287 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1288 "BC_%d : FW CMD to map iscsi frags failed.\n");
1289
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301290 goto error;
1291 }
1292 } while (num_pages > 0);
1293error:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301294 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301295 if (status != 0)
1296 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1297 return status;
1298}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001299
1300int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1301{
1302 struct be_ctrl_info *ctrl = &phba->ctrl;
1303 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1304 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1305 int status;
1306
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301307 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001308
1309 req = embedded_payload(wrb);
1310 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1311 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1312 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +05301313 status = be_mbox_notify(ctrl);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001314
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301315 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001316 return status;
1317}
John Soni Jose6f722382012-08-20 23:00:43 +05301318
1319/**
1320 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1321 * @phba: device priv structure instance
1322 * @vlan_tag: TAG to be set
1323 *
1324 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1325 *
1326 * returns
1327 * TAG for the MBX Cmd
1328 * **/
1329int be_cmd_set_vlan(struct beiscsi_hba *phba,
1330 uint16_t vlan_tag)
1331{
1332 unsigned int tag = 0;
1333 struct be_mcc_wrb *wrb;
1334 struct be_cmd_set_vlan_req *req;
1335 struct be_ctrl_info *ctrl = &phba->ctrl;
1336
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301337 if (mutex_lock_interruptible(&ctrl->mbox_lock))
1338 return 0;
John Soni Jose6f722382012-08-20 23:00:43 +05301339 tag = alloc_mcc_tag(phba);
1340 if (!tag) {
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301341 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301342 return tag;
1343 }
1344
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));
1352
1353 req->interface_hndl = phba->interface_handle;
1354 req->vlan_priority = vlan_tag;
1355
Jitendra Bhivarecdde6682016-01-20 14:10:47 +05301356 be_mcc_notify(phba, tag);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301357 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301358
1359 return tag;
1360}