blob: dbe62c0e6916752b72f69c9e883c1ab9e1407cbf [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 Bhivare53aefe22016-01-20 14:10:53 +0530408static void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530409 struct be_async_event_link_state *evt)
410{
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700411 if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
412 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
413 (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
414 phba->state = BE_ADAPTER_LINK_DOWN;
415
John Soni Jose99bc5d52012-08-20 23:00:18 +0530416 beiscsi_log(phba, KERN_ERR,
417 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700418 "BC_%d : Link Down on Port %d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +0530419 evt->physical_port);
420
Jayamohan Kallickalda7408c2010-01-05 05:11:23 +0530421 iscsi_host_for_each_session(phba->shost,
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +0530422 beiscsi_fail_session);
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700423 } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
424 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
425 (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -0400426 phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT;
John Soni Jose3efde862015-04-25 08:16:57 +0530427 phba->get_boot = BE_GET_BOOT_RETRIES;
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700428
John Soni Jose99bc5d52012-08-20 23:00:18 +0530429 beiscsi_log(phba, KERN_ERR,
430 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700431 "BC_%d : Link UP on Port %d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +0530432 evt->physical_port);
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:
509 beiscsi_async_link_state_process(phba,
510 (struct be_async_event_link_state *)compl);
511 break;
512 case ASYNC_EVENT_CODE_ISCSI:
513 phba->state |= BE_ADAPTER_CHECK_BOOT;
514 phba->get_boot = BE_GET_BOOT_RETRIES;
515 sev = KERN_ERR;
516 break;
517 case ASYNC_EVENT_CODE_SLI:
518 beiscsi_process_async_sli(phba, compl);
519 break;
520 default:
521 /* event not registered */
522 sev = KERN_ERR;
523 }
524
525 beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
526 "BC_%d : ASYNC Event: status 0x%08x flags 0x%08x\n",
527 compl->status, compl->flags);
528}
529
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530530int beiscsi_process_mcc(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530531{
532 struct be_mcc_compl *compl;
533 int num = 0, status = 0;
534 struct be_ctrl_info *ctrl = &phba->ctrl;
535
536 spin_lock_bh(&phba->ctrl.mcc_cq_lock);
537 while ((compl = be_mcc_compl_get(phba))) {
538 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530539 beiscsi_process_async_event(phba, compl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530540 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530541 status = be_mcc_compl_process(ctrl, compl);
542 atomic_dec(&phba->ctrl.mcc_obj.q.used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530543 }
544 be_mcc_compl_use(compl);
545 num++;
546 }
547
548 if (num)
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -0500549 hwi_ring_cq_db(phba, phba->ctrl.mcc_obj.cq.id, num, 1, 0);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530550
551 spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
552 return status;
553}
554
John Soni Josee175def2012-10-20 04:45:40 +0530555/*
556 * be_mcc_wait_compl()- Wait for MBX completion
557 * @phba: driver private structure
558 *
559 * Wait till no more pending mcc requests are present
560 *
561 * return
562 * Success: 0
563 * Failure: Non-Zero
564 *
565 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530566static int be_mcc_wait_compl(struct beiscsi_hba *phba)
567{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530568 int i, status;
569 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530570 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530571 return -EIO;
572
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530573 status = beiscsi_process_mcc(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530574 if (status)
575 return status;
576
577 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
578 break;
579 udelay(100);
580 }
581 if (i == mcc_timeout) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530582 beiscsi_log(phba, KERN_ERR,
583 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530584 "BC_%d : FW Timed Out\n");
585 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530586 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530587 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530588 }
589 return 0;
590}
591
John Soni Josee175def2012-10-20 04:45:40 +0530592/*
593 * be_mcc_notify_wait()- Notify and wait for Compl
594 * @phba: driver private structure
595 *
596 * Notify MCC requests and wait for completion
597 *
598 * return
599 * Success: 0
600 * Failure: Non-Zero
601 **/
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530602int be_mcc_notify_wait(struct beiscsi_hba *phba, unsigned int tag)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530603{
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530604 be_mcc_notify(phba, tag);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530605 return be_mcc_wait_compl(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530606}
607
John Soni Josee175def2012-10-20 04:45:40 +0530608/*
609 * be_mbox_db_ready_wait()- Check ready status
610 * @ctrl: Function specific MBX data structure
611 *
612 * Check for the ready status of FW to send BMBX
613 * commands to adapter.
614 *
615 * return
616 * Success: 0
617 * Failure: Non-Zero
618 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530619static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
620{
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530621 /* wait 30s for generic non-flash MBOX operation */
622#define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530623 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530624 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700625 unsigned long timeout;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530626 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700627
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530628 /*
629 * This BMBX busy wait path is used during init only.
630 * For the commands executed during init, 5s should suffice.
631 */
632 timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530633 do {
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530634 if (beiscsi_error(phba))
635 return -EIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530636
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530637 ready = ioread32(db);
638 if (ready == 0xffffffff)
639 return -EIO;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700640
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530641 ready &= MPU_MAILBOX_DB_RDY_MASK;
642 if (ready)
643 return 0;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700644
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530645 if (time_after(jiffies, timeout))
646 break;
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530647 msleep(20);
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530648 } while (!ready);
649
650 beiscsi_log(phba, KERN_ERR,
651 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
652 "BC_%d : FW Timed Out\n");
653
654 phba->fw_timeout = true;
655 beiscsi_ue_detect(phba);
656
657 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530658}
659
John Soni Josee175def2012-10-20 04:45:40 +0530660/*
661 * be_mbox_notify: Notify adapter of new BMBX command
662 * @ctrl: Function specific MBX data structure
663 *
664 * Ring doorbell to inform adapter of a BMBX command
665 * to process
666 *
667 * return
668 * Success: 0
669 * Failure: Non-Zero
670 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530671int be_mbox_notify(struct be_ctrl_info *ctrl)
672{
673 int status;
674 u32 val = 0;
675 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
676 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
677 struct be_mcc_mailbox *mbox = mbox_mem->va;
678 struct be_mcc_compl *compl = &mbox->compl;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530679 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530680
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700681 status = be_mbox_db_ready_wait(ctrl);
682 if (status)
683 return status;
684
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530685 val &= ~MPU_MAILBOX_DB_RDY_MASK;
686 val |= MPU_MAILBOX_DB_HI_MASK;
687 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
688 iowrite32(val, db);
689
690 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530691 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530692 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530693
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530694 val = 0;
695 val &= ~MPU_MAILBOX_DB_RDY_MASK;
696 val &= ~MPU_MAILBOX_DB_HI_MASK;
697 val |= (u32) (mbox_mem->dma >> 4) << 2;
698 iowrite32(val, db);
699
700 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530701 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530702 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530703
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530704 /* RDY is set; small delay before CQE read. */
705 udelay(1);
706
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530707 if (be_mcc_compl_is_new(compl)) {
708 status = be_mcc_compl_process(ctrl, &mbox->compl);
709 be_mcc_compl_use(compl);
710 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530711 beiscsi_log(phba, KERN_ERR,
712 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
713 "BC_%d : After be_mcc_compl_process\n");
714
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530715 return status;
716 }
717 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530718 beiscsi_log(phba, KERN_ERR,
719 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
720 "BC_%d : Invalid Mailbox Completion\n");
721
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530722 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530723 }
724 return 0;
725}
726
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530727/*
728 * Insert the mailbox address into the doorbell in two steps
729 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
730 */
731static int be_mbox_notify_wait(struct beiscsi_hba *phba)
732{
733 int status;
734 u32 val = 0;
735 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
736 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
737 struct be_mcc_mailbox *mbox = mbox_mem->va;
738 struct be_mcc_compl *compl = &mbox->compl;
739 struct be_ctrl_info *ctrl = &phba->ctrl;
740
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700741 status = be_mbox_db_ready_wait(ctrl);
742 if (status)
743 return status;
744
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530745 val |= MPU_MAILBOX_DB_HI_MASK;
746 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
747 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
748 iowrite32(val, db);
749
750 /* wait for ready to be set */
751 status = be_mbox_db_ready_wait(ctrl);
752 if (status != 0)
753 return status;
754
755 val = 0;
756 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
757 val |= (u32)(mbox_mem->dma >> 4) << 2;
758 iowrite32(val, db);
759
760 status = be_mbox_db_ready_wait(ctrl);
761 if (status != 0)
762 return status;
763
764 /* A cq entry has been made now */
765 if (be_mcc_compl_is_new(compl)) {
766 status = be_mcc_compl_process(ctrl, &mbox->compl);
767 be_mcc_compl_use(compl);
768 if (status)
769 return status;
770 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530771 beiscsi_log(phba, KERN_ERR,
772 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
773 "BC_%d : invalid mailbox completion\n");
774
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530775 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530776 }
777 return 0;
778}
779
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530780void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
781 bool embedded, u8 sge_cnt)
782{
783 if (embedded)
784 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
785 else
786 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
787 MCC_WRB_SGE_CNT_SHIFT;
788 wrb->payload_length = payload_len;
789 be_dws_cpu_to_le(wrb, 8);
790}
791
792void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
793 u8 subsystem, u8 opcode, int cmd_len)
794{
795 req_hdr->opcode = opcode;
796 req_hdr->subsystem = subsystem;
797 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530798 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530799}
800
801static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
802 struct be_dma_mem *mem)
803{
804 int i, buf_pages;
805 u64 dma = (u64) mem->dma;
806
807 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
808 for (i = 0; i < buf_pages; i++) {
809 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
810 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
811 dma += PAGE_SIZE_4K;
812 }
813}
814
815static u32 eq_delay_to_mult(u32 usec_delay)
816{
817#define MAX_INTR_RATE 651042
818 const u32 round = 10;
819 u32 multiplier;
820
821 if (usec_delay == 0)
822 multiplier = 0;
823 else {
824 u32 interrupt_rate = 1000000 / usec_delay;
825 if (interrupt_rate == 0)
826 multiplier = 1023;
827 else {
828 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
829 multiplier /= interrupt_rate;
830 multiplier = (multiplier + round / 2) / round;
831 multiplier = min(multiplier, (u32) 1023);
832 }
833 }
834 return multiplier;
835}
836
837struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
838{
839 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
840}
841
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530842struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
843{
844 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
845 struct be_mcc_wrb *wrb;
846
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700847 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530848 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530849 memset(wrb, 0, sizeof(*wrb));
850 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530851 queue_head_inc(mccq);
852 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530853 return wrb;
854}
855
856
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530857int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
858 struct be_queue_info *eq, int eq_delay)
859{
860 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
861 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
862 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
863 struct be_dma_mem *q_mem = &eq->dma_mem;
864 int status;
865
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530866 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530867 memset(wrb, 0, sizeof(*wrb));
868
869 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
870
871 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
872 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
873
874 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
875
876 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
877 PCI_FUNC(ctrl->pdev->devfn));
878 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
879 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
880 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
881 __ilog2_u32(eq->len / 256));
882 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
883 eq_delay_to_mult(eq_delay));
884 be_dws_cpu_to_le(req->context, sizeof(req->context));
885
886 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
887
888 status = be_mbox_notify(ctrl);
889 if (!status) {
890 eq->id = le16_to_cpu(resp->eq_id);
891 eq->created = true;
892 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530893 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530894 return status;
895}
896
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700897/**
898 * be_cmd_fw_initialize()- Initialize FW
899 * @ctrl: Pointer to function control structure
900 *
901 * Send FW initialize pattern for the function.
902 *
903 * return
904 * Success: 0
905 * Failure: Non-Zero value
906 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530907int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
908{
909 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530910 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530911 int status;
912 u8 *endian_check;
913
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530914 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530915 memset(wrb, 0, sizeof(*wrb));
916
917 endian_check = (u8 *) wrb;
918 *endian_check++ = 0xFF;
919 *endian_check++ = 0x12;
920 *endian_check++ = 0x34;
921 *endian_check++ = 0xFF;
922 *endian_check++ = 0xFF;
923 *endian_check++ = 0x56;
924 *endian_check++ = 0x78;
925 *endian_check++ = 0xFF;
926 be_dws_cpu_to_le(wrb, sizeof(*wrb));
927
928 status = be_mbox_notify(ctrl);
929 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530930 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
931 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530932
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530933 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530934 return status;
935}
936
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700937/**
938 * be_cmd_fw_uninit()- Uinitialize FW
939 * @ctrl: Pointer to function control structure
940 *
941 * Send FW uninitialize pattern for the function
942 *
943 * return
944 * Success: 0
945 * Failure: Non-Zero value
946 **/
947int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
948{
949 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
950 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
951 int status;
952 u8 *endian_check;
953
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530954 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700955 memset(wrb, 0, sizeof(*wrb));
956
957 endian_check = (u8 *) wrb;
958 *endian_check++ = 0xFF;
959 *endian_check++ = 0xAA;
960 *endian_check++ = 0xBB;
961 *endian_check++ = 0xFF;
962 *endian_check++ = 0xFF;
963 *endian_check++ = 0xCC;
964 *endian_check++ = 0xDD;
965 *endian_check = 0xFF;
966
967 be_dws_cpu_to_le(wrb, sizeof(*wrb));
968
969 status = be_mbox_notify(ctrl);
970 if (status)
971 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
972 "BC_%d : be_cmd_fw_uninit Failed\n");
973
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530974 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700975 return status;
976}
977
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530978int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
979 struct be_queue_info *cq, struct be_queue_info *eq,
980 bool sol_evts, bool no_delay, int coalesce_wm)
981{
982 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
983 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
984 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530985 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530986 struct be_dma_mem *q_mem = &cq->dma_mem;
987 void *ctxt = &req->context;
988 int status;
989
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530990 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530991 memset(wrb, 0, sizeof(*wrb));
992
993 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
994
995 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
996 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530997
998 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700999 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +05301000 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
1001 ctxt, coalesce_wm);
1002 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
1003 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
1004 __ilog2_u32(cq->len / 256));
1005 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
1006 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
1007 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
1008 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
1009 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
1010 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
1011 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001012 } else {
1013 req->hdr.version = MBX_CMD_VER2;
1014 req->page_size = 1;
1015 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1016 ctxt, coalesce_wm);
1017 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
1018 ctxt, no_delay);
1019 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
1020 __ilog2_u32(cq->len / 256));
1021 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
1022 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1023 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
1024 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +05301025 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301026
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301027 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1028
1029 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1030
1031 status = be_mbox_notify(ctrl);
1032 if (!status) {
1033 cq->id = le16_to_cpu(resp->cq_id);
1034 cq->created = true;
1035 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05301036 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1037 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
1038 status);
1039
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301040 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301041
1042 return status;
1043}
1044
1045static u32 be_encoded_q_len(int q_len)
1046{
1047 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
1048 if (len_encoded == 16)
1049 len_encoded = 0;
1050 return len_encoded;
1051}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301052
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301053int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301054 struct be_queue_info *mccq,
1055 struct be_queue_info *cq)
1056{
1057 struct be_mcc_wrb *wrb;
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301058 struct be_cmd_req_mcc_create_ext *req;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301059 struct be_dma_mem *q_mem = &mccq->dma_mem;
1060 struct be_ctrl_info *ctrl;
1061 void *ctxt;
1062 int status;
1063
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301064 mutex_lock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301065 ctrl = &phba->ctrl;
1066 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -05001067 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301068 req = embedded_payload(wrb);
1069 ctxt = &req->context;
1070
1071 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1072
1073 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301074 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301075
1076 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05301077 req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
1078 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
1079 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301080
1081 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
1082 PCI_FUNC(phba->pcidev->devfn));
1083 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
1084 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
1085 be_encoded_q_len(mccq->len));
1086 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
1087
1088 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1089
1090 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1091
1092 status = be_mbox_notify_wait(phba);
1093 if (!status) {
1094 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1095 mccq->id = le16_to_cpu(resp->id);
1096 mccq->created = true;
1097 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301098 mutex_unlock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301099
1100 return status;
1101}
1102
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301103int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
1104 int queue_type)
1105{
1106 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1107 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301108 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301109 u8 subsys = 0, opcode = 0;
1110 int status;
1111
John Soni Jose99bc5d52012-08-20 23:00:18 +05301112 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
1113 "BC_%d : In beiscsi_cmd_q_destroy "
1114 "queue_type : %d\n", queue_type);
1115
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301116 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301117 memset(wrb, 0, sizeof(*wrb));
1118 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1119
1120 switch (queue_type) {
1121 case QTYPE_EQ:
1122 subsys = CMD_SUBSYSTEM_COMMON;
1123 opcode = OPCODE_COMMON_EQ_DESTROY;
1124 break;
1125 case QTYPE_CQ:
1126 subsys = CMD_SUBSYSTEM_COMMON;
1127 opcode = OPCODE_COMMON_CQ_DESTROY;
1128 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301129 case QTYPE_MCCQ:
1130 subsys = CMD_SUBSYSTEM_COMMON;
1131 opcode = OPCODE_COMMON_MCC_DESTROY;
1132 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301133 case QTYPE_WRBQ:
1134 subsys = CMD_SUBSYSTEM_ISCSI;
1135 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1136 break;
1137 case QTYPE_DPDUQ:
1138 subsys = CMD_SUBSYSTEM_ISCSI;
1139 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1140 break;
1141 case QTYPE_SGL:
1142 subsys = CMD_SUBSYSTEM_ISCSI;
1143 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1144 break;
1145 default:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301146 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301147 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301148 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301149 }
1150 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1151 if (queue_type != QTYPE_SGL)
1152 req->id = cpu_to_le16(q->id);
1153
1154 status = be_mbox_notify(ctrl);
1155
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301156 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301157 return status;
1158}
1159
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001160/**
1161 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1162 * @ctrl: ptr to ctrl_info
1163 * @cq: Completion Queue
1164 * @dq: Default Queue
1165 * @lenght: ring size
1166 * @entry_size: size of each entry in DEFQ
1167 * @is_header: Header or Data DEFQ
1168 * @ulp_num: Bind to which ULP
1169 *
1170 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1171 * on this queue by the FW
1172 *
1173 * return
1174 * Success: 0
1175 * Failure: Non-Zero Value
1176 *
1177 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301178int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1179 struct be_queue_info *cq,
1180 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001181 int entry_size, uint8_t is_header,
1182 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301183{
1184 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1185 struct be_defq_create_req *req = embedded_payload(wrb);
1186 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001187 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301188 void *ctxt = &req->context;
1189 int status;
1190
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301191 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301192 memset(wrb, 0, sizeof(*wrb));
1193
1194 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1195
1196 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1197 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1198
1199 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001200 if (phba->fw_config.dual_ulp_aware) {
1201 req->ulp_num = ulp_num;
1202 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1203 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1204 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001205
1206 if (is_chip_be2_be3r(phba)) {
1207 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1208 rx_pdid, ctxt, 0);
1209 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1210 rx_pdid_valid, ctxt, 1);
1211 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1212 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1213 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1214 ring_size, ctxt,
1215 be_encoded_q_len(length /
1216 sizeof(struct phys_addr)));
1217 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1218 default_buffer_size, ctxt, entry_size);
1219 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1220 cq_id_recv, ctxt, cq->id);
1221 } else {
1222 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1223 rx_pdid, ctxt, 0);
1224 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1225 rx_pdid_valid, ctxt, 1);
1226 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1227 ring_size, ctxt,
1228 be_encoded_q_len(length /
1229 sizeof(struct phys_addr)));
1230 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1231 default_buffer_size, ctxt, entry_size);
1232 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1233 cq_id_recv, ctxt, cq->id);
1234 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301235
1236 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1237
1238 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1239
1240 status = be_mbox_notify(ctrl);
1241 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001242 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301243 struct be_defq_create_resp *resp = embedded_payload(wrb);
1244
1245 dq->id = le16_to_cpu(resp->id);
1246 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001247 if (is_header)
1248 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1249 else
1250 defq_ring = &phba->phwi_ctrlr->
1251 default_pdu_data[ulp_num];
1252
1253 defq_ring->id = dq->id;
1254
1255 if (!phba->fw_config.dual_ulp_aware) {
1256 defq_ring->ulp_num = BEISCSI_ULP0;
1257 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1258 } else {
1259 defq_ring->ulp_num = resp->ulp_num;
1260 defq_ring->doorbell_offset = resp->doorbell_offset;
1261 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301262 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301263 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301264
1265 return status;
1266}
1267
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001268/**
1269 * be_cmd_wrbq_create()- Create WRBQ
1270 * @ctrl: ptr to ctrl_info
1271 * @q_mem: memory details for the queue
1272 * @wrbq: queue info
1273 * @pwrb_context: ptr to wrb_context
1274 * @ulp_num: ULP on which the WRBQ is to be created
1275 *
1276 * Create WRBQ on the passed ULP_NUM.
1277 *
1278 **/
1279int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1280 struct be_dma_mem *q_mem,
1281 struct be_queue_info *wrbq,
1282 struct hwi_wrb_context *pwrb_context,
1283 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301284{
1285 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1286 struct be_wrbq_create_req *req = embedded_payload(wrb);
1287 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001288 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301289 int status;
1290
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301291 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301292 memset(wrb, 0, sizeof(*wrb));
1293
1294 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1295
1296 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1297 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1298 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001299
1300 if (phba->fw_config.dual_ulp_aware) {
1301 req->ulp_num = ulp_num;
1302 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1303 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1304 }
1305
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301306 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1307
1308 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301309 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301310 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301311 wrbq->created = true;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001312
1313 pwrb_context->cid = wrbq->id;
1314 if (!phba->fw_config.dual_ulp_aware) {
1315 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1316 pwrb_context->ulp_num = BEISCSI_ULP0;
1317 } else {
1318 pwrb_context->ulp_num = resp->ulp_num;
1319 pwrb_context->doorbell_offset = resp->doorbell_offset;
1320 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301321 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301322 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301323 return status;
1324}
1325
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001326int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1327 struct be_dma_mem *q_mem)
1328{
1329 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1330 struct be_post_template_pages_req *req = embedded_payload(wrb);
1331 int status;
1332
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301333 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001334
1335 memset(wrb, 0, sizeof(*wrb));
1336 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1337 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1338 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1339 sizeof(*req));
1340
1341 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1342 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1343 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1344
1345 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301346 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001347 return status;
1348}
1349
1350int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1351{
1352 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1353 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1354 int status;
1355
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301356 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001357
1358 memset(wrb, 0, sizeof(*wrb));
1359 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1360 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1361 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1362 sizeof(*req));
1363
1364 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1365
1366 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301367 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001368 return status;
1369}
1370
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301371int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1372 struct be_dma_mem *q_mem,
1373 u32 page_offset, u32 num_pages)
1374{
1375 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1376 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301377 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301378 int status;
1379 unsigned int curr_pages;
1380 u32 internal_page_offset = 0;
1381 u32 temp_num_pages = num_pages;
1382
1383 if (num_pages == 0xff)
1384 num_pages = 1;
1385
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301386 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301387 do {
1388 memset(wrb, 0, sizeof(*wrb));
1389 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1390 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1391 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1392 sizeof(*req));
1393 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1394 pages);
1395 req->num_pages = min(num_pages, curr_pages);
1396 req->page_offset = page_offset;
1397 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1398 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1399 internal_page_offset += req->num_pages;
1400 page_offset += req->num_pages;
1401 num_pages -= req->num_pages;
1402
1403 if (temp_num_pages == 0xff)
1404 req->num_pages = temp_num_pages;
1405
1406 status = be_mbox_notify(ctrl);
1407 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301408 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1409 "BC_%d : FW CMD to map iscsi frags failed.\n");
1410
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301411 goto error;
1412 }
1413 } while (num_pages > 0);
1414error:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301415 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301416 if (status != 0)
1417 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1418 return status;
1419}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001420
1421int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1422{
1423 struct be_ctrl_info *ctrl = &phba->ctrl;
1424 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1425 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1426 int status;
1427
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301428 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001429
1430 req = embedded_payload(wrb);
1431 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1432 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1433 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1434 status = be_mbox_notify_wait(phba);
1435
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301436 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001437 return status;
1438}
John Soni Jose6f722382012-08-20 23:00:43 +05301439
1440/**
1441 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1442 * @phba: device priv structure instance
1443 * @vlan_tag: TAG to be set
1444 *
1445 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1446 *
1447 * returns
1448 * TAG for the MBX Cmd
1449 * **/
1450int be_cmd_set_vlan(struct beiscsi_hba *phba,
1451 uint16_t vlan_tag)
1452{
1453 unsigned int tag = 0;
1454 struct be_mcc_wrb *wrb;
1455 struct be_cmd_set_vlan_req *req;
1456 struct be_ctrl_info *ctrl = &phba->ctrl;
1457
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301458 if (mutex_lock_interruptible(&ctrl->mbox_lock))
1459 return 0;
John Soni Jose6f722382012-08-20 23:00:43 +05301460 tag = alloc_mcc_tag(phba);
1461 if (!tag) {
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301462 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301463 return tag;
1464 }
1465
1466 wrb = wrb_from_mccq(phba);
1467 req = embedded_payload(wrb);
1468 wrb->tag0 |= tag;
1469 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1470 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1471 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1472 sizeof(*req));
1473
1474 req->interface_hndl = phba->interface_handle;
1475 req->vlan_priority = vlan_tag;
1476
Jitendra Bhivarecdde6682016-01-20 14:10:47 +05301477 be_mcc_notify(phba, tag);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301478 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301479
1480 return tag;
1481}