blob: 34c33d422ec4b8bb73fa45c863fca68021f5c08e [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;
128 phba->ctrl.mcc_numtag[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/*
143 * beiscsi_mccq_compl()- Wait for completion of MBX
144 * @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 **/
155int beiscsi_mccq_compl(struct beiscsi_hba *phba,
156 uint32_t tag, struct be_mcc_wrb **wrb,
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500157 struct be_dma_mem *mbx_cmd_mem)
John Soni Josee175def2012-10-20 04:45:40 +0530158{
159 int rc = 0;
160 uint32_t mcc_tag_response;
161 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],
175 phba->ctrl.mcc_numtag[tag],
176 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;
John Soni Josee175def2012-10-20 04:45:40 +0530212 mcc_tag_response = phba->ctrl.mcc_numtag[tag];
213 status = (mcc_tag_response & CQE_STATUS_MASK);
214 addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
215 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 {
220 wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
221 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);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530260 tag = tag & 0x000000FF;
261 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/*
286 * be_mcc_compl_process()- Check the MBX comapletion status
287 * @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 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530296static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
297 struct be_mcc_compl *compl)
298{
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 Kallickal756d29c2010-01-05 05:10:46 +0530331int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
332 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530333{
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500334 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530335 u16 compl_status, extd_status;
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530336 struct be_dma_mem *tag_mem;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530337 unsigned short tag;
338
339 be_dws_le_to_cpu(compl, 4);
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530340 tag = (compl->tag0 & 0x000000FF);
341
342 if (!test_bit(MCC_TAG_STATE_RUNNING,
343 &ctrl->ptag_state[tag].tag_state)) {
344 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX |
345 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
346 "BC_%d : MBX cmd completed but not posted\n");
347 return 0;
348 }
349
350 if (test_bit(MCC_TAG_STATE_TIMEOUT,
351 &ctrl->ptag_state[tag].tag_state)) {
352 beiscsi_log(phba, KERN_WARNING,
353 BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
354 BEISCSI_LOG_CONFIG,
355 "BC_%d : MBX Completion for timeout Command from FW\n");
356 /**
357 * Check for the size before freeing resource.
358 * Only for non-embedded cmd, PCI resource is allocated.
359 **/
360 tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
361 if (tag_mem->size)
362 pci_free_consistent(ctrl->pdev, tag_mem->size,
363 tag_mem->va, tag_mem->dma);
364 free_mcc_tag(ctrl, tag);
365 return 0;
366 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530367
368 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
369 CQE_STATUS_COMPL_MASK;
370 /* The ctrl.mcc_numtag[tag] is filled with
371 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
372 * [7:0] = compl_status
373 */
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530374 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
375 CQE_STATUS_EXTD_MASK;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530376 ctrl->mcc_numtag[tag] = 0x80000000;
377 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
378 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
379 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500380
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530381 /* write ordering implied in wake_up_interruptible */
382 clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state);
383 wake_up_interruptible(&ctrl->mcc_wait[tag]);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530384 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530385}
386
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530387static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
388{
389 struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
390 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
391
392 if (be_mcc_compl_is_new(compl)) {
393 queue_tail_inc(mcc_cq);
394 return compl;
395 }
396 return NULL;
397}
398
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500399/**
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +0530400 * beiscsi_fail_session(): Closing session with appropriate error
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500401 * @cls_session: ptr to session
Jayamohan Kallickal9343be72014-01-29 02:16:43 -0500402 **/
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +0530403void beiscsi_fail_session(struct iscsi_cls_session *cls_session)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530404{
405 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
406}
407
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530408static void beiscsi_process_async_link(struct beiscsi_hba *phba,
409 struct be_mcc_compl *compl)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530410{
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530411 struct be_async_event_link_state *evt;
412
413 evt = (struct be_async_event_link_state *)compl;
414
Jitendra Bhivare048084c2016-01-20 14:10:58 +0530415 phba->port_speed = evt->port_speed;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530416 /**
417 * Check logical link status in ASYNC event.
418 * This has been newly introduced in SKH-R Firmware 10.0.338.45.
419 **/
420 if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) {
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -0400421 phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT;
John Soni Jose3efde862015-04-25 08:16:57 +0530422 phba->get_boot = BE_GET_BOOT_RETRIES;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530423 __beiscsi_log(phba, KERN_ERR,
424 "BC_%d : Link Up on Port %d tag 0x%x\n",
425 evt->physical_port, evt->event_tag);
426 } else {
427 phba->state = BE_ADAPTER_LINK_DOWN;
428 __beiscsi_log(phba, KERN_ERR,
429 "BC_%d : Link Down on Port %d tag 0x%x\n",
430 evt->physical_port, evt->event_tag);
431 iscsi_host_for_each_session(phba->shost,
432 beiscsi_fail_session);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530433 }
434}
435
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530436static char *beiscsi_port_misconf_event_msg[] = {
437 "Physical Link is functional.",
438 "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.",
439 "Optics of two types installed - Remove one optic or install matching pair of optics.",
440 "Incompatible optics - Replace with compatible optics for card to function.",
441 "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.",
442 "Uncertified optics - Replace with Avago Certified optics to enable link operation."
443};
444
445static void beiscsi_process_async_sli(struct beiscsi_hba *phba,
446 struct be_mcc_compl *compl)
447{
448 struct be_async_event_sli *async_sli;
449 u8 evt_type, state, old_state, le;
450 char *sev = KERN_WARNING;
451 char *msg = NULL;
452
453 evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT;
454 evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK;
455
456 /* processing only MISCONFIGURED physical port event */
457 if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED)
458 return;
459
460 async_sli = (struct be_async_event_sli *)compl;
461 state = async_sli->event_data1 >>
462 (phba->fw_config.phys_port * 8) & 0xff;
463 le = async_sli->event_data2 >>
464 (phba->fw_config.phys_port * 8) & 0xff;
465
466 old_state = phba->optic_state;
467 phba->optic_state = state;
468
469 if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) {
470 /* fw is reporting a state we don't know, log and return */
471 __beiscsi_log(phba, KERN_ERR,
472 "BC_%d : Port %c: Unrecognized optic state 0x%x\n",
473 phba->port_name, async_sli->event_data1);
474 return;
475 }
476
477 if (ASYNC_SLI_LINK_EFFECT_VALID(le)) {
478 /* log link effect for unqualified-4, uncertified-5 optics */
479 if (state > 3)
480 msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ?
481 " Link is non-operational." :
482 " Link is operational.";
483 /* 1 - info */
484 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1)
485 sev = KERN_INFO;
486 /* 2 - error */
487 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2)
488 sev = KERN_ERR;
489 }
490
491 if (old_state != phba->optic_state)
492 __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n",
493 phba->port_name,
494 beiscsi_port_misconf_event_msg[state],
495 !msg ? "" : msg);
496}
497
498void beiscsi_process_async_event(struct beiscsi_hba *phba,
499 struct be_mcc_compl *compl)
500{
501 char *sev = KERN_INFO;
502 u8 evt_code;
503
504 /* interpret flags as an async trailer */
505 evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT;
506 evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK;
507 switch (evt_code) {
508 case ASYNC_EVENT_CODE_LINK_STATE:
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530509 beiscsi_process_async_link(phba, compl);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530510 break;
511 case ASYNC_EVENT_CODE_ISCSI:
512 phba->state |= BE_ADAPTER_CHECK_BOOT;
513 phba->get_boot = BE_GET_BOOT_RETRIES;
514 sev = KERN_ERR;
515 break;
516 case ASYNC_EVENT_CODE_SLI:
517 beiscsi_process_async_sli(phba, compl);
518 break;
519 default:
520 /* event not registered */
521 sev = KERN_ERR;
522 }
523
524 beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530525 "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n",
526 evt_code, compl->status, compl->flags);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530527}
528
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530529int beiscsi_process_mcc(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530530{
531 struct be_mcc_compl *compl;
532 int num = 0, status = 0;
533 struct be_ctrl_info *ctrl = &phba->ctrl;
534
535 spin_lock_bh(&phba->ctrl.mcc_cq_lock);
536 while ((compl = be_mcc_compl_get(phba))) {
537 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530538 beiscsi_process_async_event(phba, compl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530539 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530540 status = be_mcc_compl_process(ctrl, compl);
541 atomic_dec(&phba->ctrl.mcc_obj.q.used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530542 }
543 be_mcc_compl_use(compl);
544 num++;
545 }
546
547 if (num)
Jitendra Bhivare1094cf62016-01-20 14:10:56 +0530548 hwi_ring_cq_db(phba, phba->ctrl.mcc_obj.cq.id, num, 1);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530549
550 spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
551 return status;
552}
553
John Soni Josee175def2012-10-20 04:45:40 +0530554/*
555 * be_mcc_wait_compl()- Wait for MBX completion
556 * @phba: driver private structure
557 *
558 * Wait till no more pending mcc requests are present
559 *
560 * return
561 * Success: 0
562 * Failure: Non-Zero
563 *
564 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530565static int be_mcc_wait_compl(struct beiscsi_hba *phba)
566{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530567 int i, status;
568 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530569 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530570 return -EIO;
571
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530572 status = beiscsi_process_mcc(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530573 if (status)
574 return status;
575
576 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
577 break;
578 udelay(100);
579 }
580 if (i == mcc_timeout) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530581 beiscsi_log(phba, KERN_ERR,
582 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530583 "BC_%d : FW Timed Out\n");
584 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530585 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530586 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530587 }
588 return 0;
589}
590
John Soni Josee175def2012-10-20 04:45:40 +0530591/*
592 * be_mcc_notify_wait()- Notify and wait for Compl
593 * @phba: driver private structure
594 *
595 * Notify MCC requests and wait for completion
596 *
597 * return
598 * Success: 0
599 * Failure: Non-Zero
600 **/
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530601int be_mcc_notify_wait(struct beiscsi_hba *phba, unsigned int tag)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530602{
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530603 be_mcc_notify(phba, tag);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530604 return be_mcc_wait_compl(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530605}
606
John Soni Josee175def2012-10-20 04:45:40 +0530607/*
608 * be_mbox_db_ready_wait()- Check ready status
609 * @ctrl: Function specific MBX data structure
610 *
611 * Check for the ready status of FW to send BMBX
612 * commands to adapter.
613 *
614 * return
615 * Success: 0
616 * Failure: Non-Zero
617 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530618static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
619{
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530620 /* wait 30s for generic non-flash MBOX operation */
621#define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530622 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530623 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700624 unsigned long timeout;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530625 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700626
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530627 /*
628 * This BMBX busy wait path is used during init only.
629 * For the commands executed during init, 5s should suffice.
630 */
631 timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530632 do {
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530633 if (beiscsi_error(phba))
634 return -EIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530635
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530636 ready = ioread32(db);
637 if (ready == 0xffffffff)
638 return -EIO;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700639
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530640 ready &= MPU_MAILBOX_DB_RDY_MASK;
641 if (ready)
642 return 0;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700643
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530644 if (time_after(jiffies, timeout))
645 break;
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530646 msleep(20);
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530647 } while (!ready);
648
649 beiscsi_log(phba, KERN_ERR,
650 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
651 "BC_%d : FW Timed Out\n");
652
653 phba->fw_timeout = true;
654 beiscsi_ue_detect(phba);
655
656 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530657}
658
John Soni Josee175def2012-10-20 04:45:40 +0530659/*
660 * be_mbox_notify: Notify adapter of new BMBX command
661 * @ctrl: Function specific MBX data structure
662 *
663 * Ring doorbell to inform adapter of a BMBX command
664 * to process
665 *
666 * return
667 * Success: 0
668 * Failure: Non-Zero
669 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530670int be_mbox_notify(struct be_ctrl_info *ctrl)
671{
672 int status;
673 u32 val = 0;
674 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
675 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
676 struct be_mcc_mailbox *mbox = mbox_mem->va;
677 struct be_mcc_compl *compl = &mbox->compl;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530678 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530679
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700680 status = be_mbox_db_ready_wait(ctrl);
681 if (status)
682 return status;
683
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530684 val &= ~MPU_MAILBOX_DB_RDY_MASK;
685 val |= MPU_MAILBOX_DB_HI_MASK;
686 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
687 iowrite32(val, db);
688
689 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530690 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530691 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530692
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530693 val = 0;
694 val &= ~MPU_MAILBOX_DB_RDY_MASK;
695 val &= ~MPU_MAILBOX_DB_HI_MASK;
696 val |= (u32) (mbox_mem->dma >> 4) << 2;
697 iowrite32(val, db);
698
699 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530700 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530701 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530702
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530703 /* RDY is set; small delay before CQE read. */
704 udelay(1);
705
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530706 if (be_mcc_compl_is_new(compl)) {
707 status = be_mcc_compl_process(ctrl, &mbox->compl);
708 be_mcc_compl_use(compl);
709 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530710 beiscsi_log(phba, KERN_ERR,
711 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
712 "BC_%d : After be_mcc_compl_process\n");
713
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530714 return status;
715 }
716 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530717 beiscsi_log(phba, KERN_ERR,
718 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
719 "BC_%d : Invalid Mailbox Completion\n");
720
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530721 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530722 }
723 return 0;
724}
725
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530726/*
727 * Insert the mailbox address into the doorbell in two steps
728 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
729 */
730static int be_mbox_notify_wait(struct beiscsi_hba *phba)
731{
732 int status;
733 u32 val = 0;
734 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
735 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
736 struct be_mcc_mailbox *mbox = mbox_mem->va;
737 struct be_mcc_compl *compl = &mbox->compl;
738 struct be_ctrl_info *ctrl = &phba->ctrl;
739
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700740 status = be_mbox_db_ready_wait(ctrl);
741 if (status)
742 return status;
743
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530744 val |= MPU_MAILBOX_DB_HI_MASK;
745 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
746 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
747 iowrite32(val, db);
748
749 /* wait for ready to be set */
750 status = be_mbox_db_ready_wait(ctrl);
751 if (status != 0)
752 return status;
753
754 val = 0;
755 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
756 val |= (u32)(mbox_mem->dma >> 4) << 2;
757 iowrite32(val, db);
758
759 status = be_mbox_db_ready_wait(ctrl);
760 if (status != 0)
761 return status;
762
763 /* A cq entry has been made now */
764 if (be_mcc_compl_is_new(compl)) {
765 status = be_mcc_compl_process(ctrl, &mbox->compl);
766 be_mcc_compl_use(compl);
767 if (status)
768 return status;
769 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530770 beiscsi_log(phba, KERN_ERR,
771 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
772 "BC_%d : invalid mailbox completion\n");
773
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530774 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530775 }
776 return 0;
777}
778
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530779void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
780 bool embedded, u8 sge_cnt)
781{
782 if (embedded)
783 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
784 else
785 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
786 MCC_WRB_SGE_CNT_SHIFT;
787 wrb->payload_length = payload_len;
788 be_dws_cpu_to_le(wrb, 8);
789}
790
791void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
792 u8 subsystem, u8 opcode, int cmd_len)
793{
794 req_hdr->opcode = opcode;
795 req_hdr->subsystem = subsystem;
796 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530797 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530798}
799
800static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
801 struct be_dma_mem *mem)
802{
803 int i, buf_pages;
804 u64 dma = (u64) mem->dma;
805
806 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
807 for (i = 0; i < buf_pages; i++) {
808 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
809 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
810 dma += PAGE_SIZE_4K;
811 }
812}
813
814static u32 eq_delay_to_mult(u32 usec_delay)
815{
816#define MAX_INTR_RATE 651042
817 const u32 round = 10;
818 u32 multiplier;
819
820 if (usec_delay == 0)
821 multiplier = 0;
822 else {
823 u32 interrupt_rate = 1000000 / usec_delay;
824 if (interrupt_rate == 0)
825 multiplier = 1023;
826 else {
827 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
828 multiplier /= interrupt_rate;
829 multiplier = (multiplier + round / 2) / round;
830 multiplier = min(multiplier, (u32) 1023);
831 }
832 }
833 return multiplier;
834}
835
836struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
837{
838 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
839}
840
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530841struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
842{
843 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
844 struct be_mcc_wrb *wrb;
845
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700846 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530847 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530848 memset(wrb, 0, sizeof(*wrb));
849 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530850 queue_head_inc(mccq);
851 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530852 return wrb;
853}
854
855
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530856int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
857 struct be_queue_info *eq, int eq_delay)
858{
859 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
860 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
861 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
862 struct be_dma_mem *q_mem = &eq->dma_mem;
863 int status;
864
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530865 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530866 memset(wrb, 0, sizeof(*wrb));
867
868 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
869
870 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
871 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
872
873 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
874
875 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
876 PCI_FUNC(ctrl->pdev->devfn));
877 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
878 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
879 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
880 __ilog2_u32(eq->len / 256));
881 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
882 eq_delay_to_mult(eq_delay));
883 be_dws_cpu_to_le(req->context, sizeof(req->context));
884
885 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
886
887 status = be_mbox_notify(ctrl);
888 if (!status) {
889 eq->id = le16_to_cpu(resp->eq_id);
890 eq->created = true;
891 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530892 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530893 return status;
894}
895
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700896/**
897 * be_cmd_fw_initialize()- Initialize FW
898 * @ctrl: Pointer to function control structure
899 *
900 * Send FW initialize pattern for the function.
901 *
902 * return
903 * Success: 0
904 * Failure: Non-Zero value
905 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530906int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
907{
908 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530909 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530910 int status;
911 u8 *endian_check;
912
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530913 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530914 memset(wrb, 0, sizeof(*wrb));
915
916 endian_check = (u8 *) wrb;
917 *endian_check++ = 0xFF;
918 *endian_check++ = 0x12;
919 *endian_check++ = 0x34;
920 *endian_check++ = 0xFF;
921 *endian_check++ = 0xFF;
922 *endian_check++ = 0x56;
923 *endian_check++ = 0x78;
924 *endian_check++ = 0xFF;
925 be_dws_cpu_to_le(wrb, sizeof(*wrb));
926
927 status = be_mbox_notify(ctrl);
928 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530929 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
930 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530931
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530932 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530933 return status;
934}
935
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700936/**
937 * be_cmd_fw_uninit()- Uinitialize FW
938 * @ctrl: Pointer to function control structure
939 *
940 * Send FW uninitialize pattern for the function
941 *
942 * return
943 * Success: 0
944 * Failure: Non-Zero value
945 **/
946int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
947{
948 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
949 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
950 int status;
951 u8 *endian_check;
952
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530953 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700954 memset(wrb, 0, sizeof(*wrb));
955
956 endian_check = (u8 *) wrb;
957 *endian_check++ = 0xFF;
958 *endian_check++ = 0xAA;
959 *endian_check++ = 0xBB;
960 *endian_check++ = 0xFF;
961 *endian_check++ = 0xFF;
962 *endian_check++ = 0xCC;
963 *endian_check++ = 0xDD;
964 *endian_check = 0xFF;
965
966 be_dws_cpu_to_le(wrb, sizeof(*wrb));
967
968 status = be_mbox_notify(ctrl);
969 if (status)
970 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
971 "BC_%d : be_cmd_fw_uninit Failed\n");
972
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530973 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700974 return status;
975}
976
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530977int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
978 struct be_queue_info *cq, struct be_queue_info *eq,
979 bool sol_evts, bool no_delay, int coalesce_wm)
980{
981 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
982 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
983 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530984 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530985 struct be_dma_mem *q_mem = &cq->dma_mem;
986 void *ctxt = &req->context;
987 int status;
988
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530989 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530990 memset(wrb, 0, sizeof(*wrb));
991
992 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
993
994 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
995 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530996
997 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700998 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530999 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
1000 ctxt, coalesce_wm);
1001 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
1002 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
1003 __ilog2_u32(cq->len / 256));
1004 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
1005 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
1006 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
1007 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
1008 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
1009 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
1010 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001011 } else {
1012 req->hdr.version = MBX_CMD_VER2;
1013 req->page_size = 1;
1014 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1015 ctxt, coalesce_wm);
1016 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
1017 ctxt, no_delay);
1018 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
1019 __ilog2_u32(cq->len / 256));
1020 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
1021 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1022 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
1023 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +05301024 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301025
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301026 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1027
1028 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1029
1030 status = be_mbox_notify(ctrl);
1031 if (!status) {
1032 cq->id = le16_to_cpu(resp->cq_id);
1033 cq->created = true;
1034 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05301035 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1036 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
1037 status);
1038
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301039 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301040
1041 return status;
1042}
1043
1044static u32 be_encoded_q_len(int q_len)
1045{
1046 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
1047 if (len_encoded == 16)
1048 len_encoded = 0;
1049 return len_encoded;
1050}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301051
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301052int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301053 struct be_queue_info *mccq,
1054 struct be_queue_info *cq)
1055{
1056 struct be_mcc_wrb *wrb;
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301057 struct be_cmd_req_mcc_create_ext *req;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301058 struct be_dma_mem *q_mem = &mccq->dma_mem;
1059 struct be_ctrl_info *ctrl;
1060 void *ctxt;
1061 int status;
1062
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301063 mutex_lock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301064 ctrl = &phba->ctrl;
1065 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -05001066 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301067 req = embedded_payload(wrb);
1068 ctxt = &req->context;
1069
1070 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1071
1072 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301073 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301074
1075 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301076 req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
1077 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
1078 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301079
1080 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
1081 PCI_FUNC(phba->pcidev->devfn));
1082 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
1083 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
1084 be_encoded_q_len(mccq->len));
1085 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
1086
1087 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1088
1089 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1090
1091 status = be_mbox_notify_wait(phba);
1092 if (!status) {
1093 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1094 mccq->id = le16_to_cpu(resp->id);
1095 mccq->created = true;
1096 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301097 mutex_unlock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301098
1099 return status;
1100}
1101
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301102int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
1103 int queue_type)
1104{
1105 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1106 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301107 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301108 u8 subsys = 0, opcode = 0;
1109 int status;
1110
John Soni Jose99bc5d52012-08-20 23:00:18 +05301111 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
1112 "BC_%d : In beiscsi_cmd_q_destroy "
1113 "queue_type : %d\n", queue_type);
1114
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301115 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301116 memset(wrb, 0, sizeof(*wrb));
1117 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1118
1119 switch (queue_type) {
1120 case QTYPE_EQ:
1121 subsys = CMD_SUBSYSTEM_COMMON;
1122 opcode = OPCODE_COMMON_EQ_DESTROY;
1123 break;
1124 case QTYPE_CQ:
1125 subsys = CMD_SUBSYSTEM_COMMON;
1126 opcode = OPCODE_COMMON_CQ_DESTROY;
1127 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301128 case QTYPE_MCCQ:
1129 subsys = CMD_SUBSYSTEM_COMMON;
1130 opcode = OPCODE_COMMON_MCC_DESTROY;
1131 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301132 case QTYPE_WRBQ:
1133 subsys = CMD_SUBSYSTEM_ISCSI;
1134 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1135 break;
1136 case QTYPE_DPDUQ:
1137 subsys = CMD_SUBSYSTEM_ISCSI;
1138 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1139 break;
1140 case QTYPE_SGL:
1141 subsys = CMD_SUBSYSTEM_ISCSI;
1142 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1143 break;
1144 default:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301145 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301146 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301147 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301148 }
1149 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1150 if (queue_type != QTYPE_SGL)
1151 req->id = cpu_to_le16(q->id);
1152
1153 status = be_mbox_notify(ctrl);
1154
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301155 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301156 return status;
1157}
1158
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001159/**
1160 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1161 * @ctrl: ptr to ctrl_info
1162 * @cq: Completion Queue
1163 * @dq: Default Queue
1164 * @lenght: ring size
1165 * @entry_size: size of each entry in DEFQ
1166 * @is_header: Header or Data DEFQ
1167 * @ulp_num: Bind to which ULP
1168 *
1169 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1170 * on this queue by the FW
1171 *
1172 * return
1173 * Success: 0
1174 * Failure: Non-Zero Value
1175 *
1176 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301177int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1178 struct be_queue_info *cq,
1179 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001180 int entry_size, uint8_t is_header,
1181 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301182{
1183 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1184 struct be_defq_create_req *req = embedded_payload(wrb);
1185 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001186 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301187 void *ctxt = &req->context;
1188 int status;
1189
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301190 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301191 memset(wrb, 0, sizeof(*wrb));
1192
1193 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1194
1195 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1196 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1197
1198 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001199 if (phba->fw_config.dual_ulp_aware) {
1200 req->ulp_num = ulp_num;
1201 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1202 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1203 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001204
1205 if (is_chip_be2_be3r(phba)) {
1206 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1207 rx_pdid, ctxt, 0);
1208 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1209 rx_pdid_valid, ctxt, 1);
1210 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1211 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1212 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1213 ring_size, ctxt,
1214 be_encoded_q_len(length /
1215 sizeof(struct phys_addr)));
1216 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1217 default_buffer_size, ctxt, entry_size);
1218 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1219 cq_id_recv, ctxt, cq->id);
1220 } else {
1221 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1222 rx_pdid, ctxt, 0);
1223 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1224 rx_pdid_valid, ctxt, 1);
1225 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1226 ring_size, ctxt,
1227 be_encoded_q_len(length /
1228 sizeof(struct phys_addr)));
1229 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1230 default_buffer_size, ctxt, entry_size);
1231 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1232 cq_id_recv, ctxt, cq->id);
1233 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301234
1235 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1236
1237 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1238
1239 status = be_mbox_notify(ctrl);
1240 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001241 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301242 struct be_defq_create_resp *resp = embedded_payload(wrb);
1243
1244 dq->id = le16_to_cpu(resp->id);
1245 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001246 if (is_header)
1247 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1248 else
1249 defq_ring = &phba->phwi_ctrlr->
1250 default_pdu_data[ulp_num];
1251
1252 defq_ring->id = dq->id;
1253
1254 if (!phba->fw_config.dual_ulp_aware) {
1255 defq_ring->ulp_num = BEISCSI_ULP0;
1256 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1257 } else {
1258 defq_ring->ulp_num = resp->ulp_num;
1259 defq_ring->doorbell_offset = resp->doorbell_offset;
1260 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301261 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301262 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301263
1264 return status;
1265}
1266
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001267/**
1268 * be_cmd_wrbq_create()- Create WRBQ
1269 * @ctrl: ptr to ctrl_info
1270 * @q_mem: memory details for the queue
1271 * @wrbq: queue info
1272 * @pwrb_context: ptr to wrb_context
1273 * @ulp_num: ULP on which the WRBQ is to be created
1274 *
1275 * Create WRBQ on the passed ULP_NUM.
1276 *
1277 **/
1278int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1279 struct be_dma_mem *q_mem,
1280 struct be_queue_info *wrbq,
1281 struct hwi_wrb_context *pwrb_context,
1282 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301283{
1284 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1285 struct be_wrbq_create_req *req = embedded_payload(wrb);
1286 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001287 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301288 int status;
1289
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301290 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301291 memset(wrb, 0, sizeof(*wrb));
1292
1293 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1294
1295 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1296 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1297 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001298
1299 if (phba->fw_config.dual_ulp_aware) {
1300 req->ulp_num = ulp_num;
1301 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1302 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1303 }
1304
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301305 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1306
1307 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301308 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301309 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301310 wrbq->created = true;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001311
1312 pwrb_context->cid = wrbq->id;
1313 if (!phba->fw_config.dual_ulp_aware) {
1314 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1315 pwrb_context->ulp_num = BEISCSI_ULP0;
1316 } else {
1317 pwrb_context->ulp_num = resp->ulp_num;
1318 pwrb_context->doorbell_offset = resp->doorbell_offset;
1319 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301320 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301321 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301322 return status;
1323}
1324
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001325int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1326 struct be_dma_mem *q_mem)
1327{
1328 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1329 struct be_post_template_pages_req *req = embedded_payload(wrb);
1330 int status;
1331
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301332 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001333
1334 memset(wrb, 0, sizeof(*wrb));
1335 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1336 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1337 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1338 sizeof(*req));
1339
1340 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1341 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1342 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1343
1344 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301345 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001346 return status;
1347}
1348
1349int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1350{
1351 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1352 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1353 int status;
1354
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301355 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001356
1357 memset(wrb, 0, sizeof(*wrb));
1358 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1359 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1360 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1361 sizeof(*req));
1362
1363 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1364
1365 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301366 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001367 return status;
1368}
1369
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301370int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1371 struct be_dma_mem *q_mem,
1372 u32 page_offset, u32 num_pages)
1373{
1374 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1375 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301376 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301377 int status;
1378 unsigned int curr_pages;
1379 u32 internal_page_offset = 0;
1380 u32 temp_num_pages = num_pages;
1381
1382 if (num_pages == 0xff)
1383 num_pages = 1;
1384
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301385 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301386 do {
1387 memset(wrb, 0, sizeof(*wrb));
1388 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1389 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1390 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1391 sizeof(*req));
1392 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1393 pages);
1394 req->num_pages = min(num_pages, curr_pages);
1395 req->page_offset = page_offset;
1396 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1397 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1398 internal_page_offset += req->num_pages;
1399 page_offset += req->num_pages;
1400 num_pages -= req->num_pages;
1401
1402 if (temp_num_pages == 0xff)
1403 req->num_pages = temp_num_pages;
1404
1405 status = be_mbox_notify(ctrl);
1406 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301407 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1408 "BC_%d : FW CMD to map iscsi frags failed.\n");
1409
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301410 goto error;
1411 }
1412 } while (num_pages > 0);
1413error:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301414 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301415 if (status != 0)
1416 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1417 return status;
1418}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001419
1420int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1421{
1422 struct be_ctrl_info *ctrl = &phba->ctrl;
1423 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1424 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1425 int status;
1426
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301427 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001428
1429 req = embedded_payload(wrb);
1430 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1431 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1432 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1433 status = be_mbox_notify_wait(phba);
1434
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301435 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001436 return status;
1437}
John Soni Jose6f722382012-08-20 23:00:43 +05301438
1439/**
1440 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1441 * @phba: device priv structure instance
1442 * @vlan_tag: TAG to be set
1443 *
1444 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1445 *
1446 * returns
1447 * TAG for the MBX Cmd
1448 * **/
1449int be_cmd_set_vlan(struct beiscsi_hba *phba,
1450 uint16_t vlan_tag)
1451{
1452 unsigned int tag = 0;
1453 struct be_mcc_wrb *wrb;
1454 struct be_cmd_set_vlan_req *req;
1455 struct be_ctrl_info *ctrl = &phba->ctrl;
1456
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301457 if (mutex_lock_interruptible(&ctrl->mbox_lock))
1458 return 0;
John Soni Jose6f722382012-08-20 23:00:43 +05301459 tag = alloc_mcc_tag(phba);
1460 if (!tag) {
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301461 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301462 return tag;
1463 }
1464
1465 wrb = wrb_from_mccq(phba);
1466 req = embedded_payload(wrb);
1467 wrb->tag0 |= tag;
1468 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1469 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1470 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1471 sizeof(*req));
1472
1473 req->interface_hndl = phba->interface_handle;
1474 req->vlan_priority = vlan_tag;
1475
Jitendra Bhivarecdde6682016-01-20 14:10:47 +05301476 be_mcc_notify(phba, tag);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301477 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301478
1479 return tag;
1480}