blob: 60db2de9ed8a2ca2523d4f9a548337050138ab0d [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
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530107unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
108{
109 unsigned int tag = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530110
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530111 spin_lock(&phba->ctrl.mcc_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530112 if (phba->ctrl.mcc_tag_available) {
113 tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
114 phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530115 phba->ctrl.mcc_tag_status[tag] = 0;
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530116 phba->ctrl.ptag_state[tag].tag_state = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530117 }
118 if (tag) {
119 phba->ctrl.mcc_tag_available--;
120 if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
121 phba->ctrl.mcc_alloc_index = 0;
122 else
123 phba->ctrl.mcc_alloc_index++;
124 }
Jitendra Bhivare12843f02016-01-20 14:10:48 +0530125 spin_unlock(&phba->ctrl.mcc_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530126 return tag;
127}
128
Jitendra Bhivare69fd6d72016-02-04 15:49:14 +0530129void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
130{
131 spin_lock_bh(&ctrl->mcc_lock);
132 tag = tag & MCC_Q_CMD_TAG_MASK;
133 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
134 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
135 ctrl->mcc_free_index = 0;
136 else
137 ctrl->mcc_free_index++;
138 ctrl->mcc_tag_available++;
139 spin_unlock_bh(&ctrl->mcc_lock);
140}
141
142/**
143 * beiscsi_fail_session(): Closing session with appropriate error
144 * @cls_session: ptr to session
145 **/
146void beiscsi_fail_session(struct iscsi_cls_session *cls_session)
147{
148 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
149}
150
John Soni Josee175def2012-10-20 04:45:40 +0530151/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530152 * beiscsi_mccq_compl_wait()- Process completion in MCC CQ
John Soni Josee175def2012-10-20 04:45:40 +0530153 * @phba: Driver private structure
154 * @tag: Tag for the MBX Command
155 * @wrb: the WRB used for the MBX Command
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500156 * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
John Soni Josee175def2012-10-20 04:45:40 +0530157 *
158 * Waits for MBX completion with the passed TAG.
159 *
160 * return
161 * Success: 0
162 * Failure: Non-Zero
163 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530164int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba,
165 uint32_t tag, struct be_mcc_wrb **wrb,
166 struct be_dma_mem *mbx_cmd_mem)
John Soni Josee175def2012-10-20 04:45:40 +0530167{
168 int rc = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530169 uint32_t mcc_tag_status;
John Soni Josee175def2012-10-20 04:45:40 +0530170 uint16_t status = 0, addl_status = 0, wrb_num = 0;
171 struct be_mcc_wrb *temp_wrb;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500172 struct be_cmd_req_hdr *mbx_hdr;
173 struct be_cmd_resp_hdr *mbx_resp_hdr;
John Soni Josee175def2012-10-20 04:45:40 +0530174 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
175
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700176 if (beiscsi_error(phba)) {
177 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500178 return -EPERM;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700179 }
John Soni Jose7a158002012-10-20 04:45:51 +0530180
John Soni Josee175def2012-10-20 04:45:40 +0530181 /* wait for the mccq completion */
182 rc = wait_event_interruptible_timeout(
183 phba->ctrl.mcc_wait[tag],
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530184 phba->ctrl.mcc_tag_status[tag],
John Soni Josee175def2012-10-20 04:45:40 +0530185 msecs_to_jiffies(
186 BEISCSI_HOST_MBX_TIMEOUT));
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530187 /**
188 * If MBOX cmd timeout expired, tag and resource allocated
189 * for cmd is not freed until FW returns completion.
190 */
John Soni Josee175def2012-10-20 04:45:40 +0530191 if (rc <= 0) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500192 struct be_dma_mem *tag_mem;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500193
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530194 /**
195 * PCI/DMA memory allocated and posted in non-embedded mode
196 * will have mbx_cmd_mem != NULL.
197 * Save virtual and bus addresses for the command so that it
198 * can be freed later.
199 **/
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500200 tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
201 if (mbx_cmd_mem) {
202 tag_mem->size = mbx_cmd_mem->size;
203 tag_mem->va = mbx_cmd_mem->va;
204 tag_mem->dma = mbx_cmd_mem->dma;
205 } else
206 tag_mem->size = 0;
207
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530208 /* first make tag_mem_state visible to all */
209 wmb();
210 set_bit(MCC_TAG_STATE_TIMEOUT,
211 &phba->ctrl.ptag_state[tag].tag_state);
212
John Soni Josee175def2012-10-20 04:45:40 +0530213 beiscsi_log(phba, KERN_ERR,
214 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
215 BEISCSI_LOG_CONFIG,
216 "BC_%d : MBX Cmd Completion timed out\n");
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500217 return -EBUSY;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500218 }
John Soni Josee175def2012-10-20 04:45:40 +0530219
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530220 rc = 0;
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530221 mcc_tag_status = phba->ctrl.mcc_tag_status[tag];
222 status = (mcc_tag_status & CQE_STATUS_MASK);
223 addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >>
John Soni Josee175def2012-10-20 04:45:40 +0530224 CQE_STATUS_ADDL_SHIFT);
225
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500226 if (mbx_cmd_mem) {
227 mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va;
John Soni Josee175def2012-10-20 04:45:40 +0530228 } else {
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530229 wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >>
John Soni Josee175def2012-10-20 04:45:40 +0530230 CQE_STATUS_WRB_SHIFT;
231 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500232 mbx_hdr = embedded_payload(temp_wrb);
John Soni Josee175def2012-10-20 04:45:40 +0530233
234 if (wrb)
235 *wrb = temp_wrb;
236 }
237
238 if (status || addl_status) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500239 beiscsi_log(phba, KERN_WARNING,
John Soni Josee175def2012-10-20 04:45:40 +0530240 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
241 BEISCSI_LOG_CONFIG,
242 "BC_%d : MBX Cmd Failed for "
243 "Subsys : %d Opcode : %d with "
244 "Status : %d and Extd_Status : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500245 mbx_hdr->subsystem,
246 mbx_hdr->opcode,
John Soni Josee175def2012-10-20 04:45:40 +0530247 status, addl_status);
Jitendra Bhivarecdde6682016-01-20 14:10:47 +0530248 rc = -EIO;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700249 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500250 mbx_resp_hdr = (struct be_cmd_resp_hdr *) mbx_hdr;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700251 beiscsi_log(phba, KERN_WARNING,
252 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
253 BEISCSI_LOG_CONFIG,
Masanari Iidad939be32015-02-27 23:52:31 +0900254 "BC_%d : Insufficient Buffer Error "
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700255 "Resp_Len : %d Actual_Resp_Len : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500256 mbx_resp_hdr->response_length,
257 mbx_resp_hdr->actual_resp_len);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700258 rc = -EAGAIN;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700259 }
John Soni Josee175def2012-10-20 04:45:40 +0530260 }
261
John Soni Josee175def2012-10-20 04:45:40 +0530262 free_mcc_tag(&phba->ctrl, tag);
John Soni Josee175def2012-10-20 04:45:40 +0530263 return rc;
264}
265
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530266static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
267{
268 if (compl->flags != 0) {
269 compl->flags = le32_to_cpu(compl->flags);
270 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
271 return true;
272 } else
273 return false;
274}
275
276static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
277{
278 compl->flags = 0;
279}
280
John Soni Josee175def2012-10-20 04:45:40 +0530281/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530282 * beiscsi_process_mbox_compl()- Check the MBX completion status
John Soni Josee175def2012-10-20 04:45:40 +0530283 * @ctrl: Function specific MBX data structure
284 * @compl: Completion status of MBX Command
285 *
286 * Check for the MBX completion status when BMBX method used
287 *
288 * return
289 * Success: Zero
290 * Failure: Non-Zero
291 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530292static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl,
293 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530294{
295 u16 compl_status, extd_status;
John Soni Josee175def2012-10-20 04:45:40 +0530296 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530297 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
John Soni Josee175def2012-10-20 04:45:40 +0530298 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700299 struct be_cmd_resp_hdr *resp_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530300
301 be_dws_le_to_cpu(compl, 4);
302
303 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
304 CQE_STATUS_COMPL_MASK;
305 if (compl_status != MCC_STATUS_SUCCESS) {
306 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
307 CQE_STATUS_EXTD_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530308
309 beiscsi_log(phba, KERN_ERR,
310 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530311 "BC_%d : error in cmd completion: "
312 "Subsystem : %d Opcode : %d "
313 "status(compl/extd)=%d/%d\n",
314 hdr->subsystem, hdr->opcode,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530315 compl_status, extd_status);
316
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700317 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
318 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
319 if (resp_hdr->response_length)
320 return 0;
321 }
Jitendra Bhivare23d7ccf12016-01-20 14:10:55 +0530322 return -EINVAL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530323 }
324 return 0;
325}
326
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530327static void beiscsi_process_async_link(struct beiscsi_hba *phba,
328 struct be_mcc_compl *compl)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530329{
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530330 struct be_async_event_link_state *evt;
331
332 evt = (struct be_async_event_link_state *)compl;
333
Jitendra Bhivare048084c2016-01-20 14:10:58 +0530334 phba->port_speed = evt->port_speed;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530335 /**
336 * Check logical link status in ASYNC event.
337 * This has been newly introduced in SKH-R Firmware 10.0.338.45.
338 **/
339 if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) {
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -0400340 phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT;
John Soni Jose3efde862015-04-25 08:16:57 +0530341 phba->get_boot = BE_GET_BOOT_RETRIES;
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530342 __beiscsi_log(phba, KERN_ERR,
343 "BC_%d : Link Up on Port %d tag 0x%x\n",
344 evt->physical_port, evt->event_tag);
345 } else {
346 phba->state = BE_ADAPTER_LINK_DOWN;
347 __beiscsi_log(phba, KERN_ERR,
348 "BC_%d : Link Down on Port %d tag 0x%x\n",
349 evt->physical_port, evt->event_tag);
350 iscsi_host_for_each_session(phba->shost,
351 beiscsi_fail_session);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530352 }
353}
354
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530355static char *beiscsi_port_misconf_event_msg[] = {
356 "Physical Link is functional.",
357 "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.",
358 "Optics of two types installed - Remove one optic or install matching pair of optics.",
359 "Incompatible optics - Replace with compatible optics for card to function.",
360 "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.",
361 "Uncertified optics - Replace with Avago Certified optics to enable link operation."
362};
363
364static void beiscsi_process_async_sli(struct beiscsi_hba *phba,
365 struct be_mcc_compl *compl)
366{
367 struct be_async_event_sli *async_sli;
368 u8 evt_type, state, old_state, le;
369 char *sev = KERN_WARNING;
370 char *msg = NULL;
371
372 evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT;
373 evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK;
374
375 /* processing only MISCONFIGURED physical port event */
376 if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED)
377 return;
378
379 async_sli = (struct be_async_event_sli *)compl;
380 state = async_sli->event_data1 >>
381 (phba->fw_config.phys_port * 8) & 0xff;
382 le = async_sli->event_data2 >>
383 (phba->fw_config.phys_port * 8) & 0xff;
384
385 old_state = phba->optic_state;
386 phba->optic_state = state;
387
388 if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) {
389 /* fw is reporting a state we don't know, log and return */
390 __beiscsi_log(phba, KERN_ERR,
391 "BC_%d : Port %c: Unrecognized optic state 0x%x\n",
392 phba->port_name, async_sli->event_data1);
393 return;
394 }
395
396 if (ASYNC_SLI_LINK_EFFECT_VALID(le)) {
397 /* log link effect for unqualified-4, uncertified-5 optics */
398 if (state > 3)
399 msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ?
400 " Link is non-operational." :
401 " Link is operational.";
402 /* 1 - info */
403 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1)
404 sev = KERN_INFO;
405 /* 2 - error */
406 if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2)
407 sev = KERN_ERR;
408 }
409
410 if (old_state != phba->optic_state)
411 __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n",
412 phba->port_name,
413 beiscsi_port_misconf_event_msg[state],
414 !msg ? "" : msg);
415}
416
417void beiscsi_process_async_event(struct beiscsi_hba *phba,
418 struct be_mcc_compl *compl)
419{
420 char *sev = KERN_INFO;
421 u8 evt_code;
422
423 /* interpret flags as an async trailer */
424 evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT;
425 evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK;
426 switch (evt_code) {
427 case ASYNC_EVENT_CODE_LINK_STATE:
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530428 beiscsi_process_async_link(phba, compl);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530429 break;
430 case ASYNC_EVENT_CODE_ISCSI:
431 phba->state |= BE_ADAPTER_CHECK_BOOT;
432 phba->get_boot = BE_GET_BOOT_RETRIES;
433 sev = KERN_ERR;
434 break;
435 case ASYNC_EVENT_CODE_SLI:
436 beiscsi_process_async_sli(phba, compl);
437 break;
438 default:
439 /* event not registered */
440 sev = KERN_ERR;
441 }
442
443 beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
Jitendra Bhivare9c4f8b02016-01-20 14:10:59 +0530444 "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n",
445 evt_code, compl->status, compl->flags);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530446}
447
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530448int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
449 struct be_mcc_compl *compl)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530450{
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530451 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
452 u16 compl_status, extd_status;
453 struct be_dma_mem *tag_mem;
454 unsigned int tag, wrb_idx;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530455
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530456 /**
457 * Just swap the status to host endian; mcc tag is opaquely copied
458 * from mcc_wrb
459 */
460 be_dws_le_to_cpu(compl, 4);
461 tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK);
462 wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT;
463
464 if (!test_bit(MCC_TAG_STATE_RUNNING,
465 &ctrl->ptag_state[tag].tag_state)) {
466 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX |
467 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
468 "BC_%d : MBX cmd completed but not posted\n");
469 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530470 }
471
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530472 if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) {
473 beiscsi_log(phba, KERN_WARNING,
474 BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
475 BEISCSI_LOG_CONFIG,
476 "BC_%d : MBX Completion for timeout Command from FW\n");
477 /**
478 * Check for the size before freeing resource.
479 * Only for non-embedded cmd, PCI resource is allocated.
480 **/
481 tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
482 if (tag_mem->size)
483 pci_free_consistent(ctrl->pdev, tag_mem->size,
484 tag_mem->va, tag_mem->dma);
485 free_mcc_tag(ctrl, tag);
486 return 0;
487 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530488
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530489 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
490 CQE_STATUS_COMPL_MASK;
491 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
492 CQE_STATUS_EXTD_MASK;
493 /* The ctrl.mcc_tag_status[tag] is filled with
494 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
495 * [7:0] = compl_status
496 */
497 ctrl->mcc_tag_status[tag] = CQE_VALID_MASK;
498 ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT);
499 ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) &
500 CQE_STATUS_ADDL_MASK;
501 ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK);
502
503 /* write ordering forced in wake_up_interruptible */
504 clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state);
505 wake_up_interruptible(&ctrl->mcc_wait[tag]);
506 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530507}
508
John Soni Josee175def2012-10-20 04:45:40 +0530509/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530510 * be_mcc_compl_poll()- Wait for MBX completion
John Soni Josee175def2012-10-20 04:45:40 +0530511 * @phba: driver private structure
512 *
513 * Wait till no more pending mcc requests are present
514 *
515 * return
516 * Success: 0
517 * Failure: Non-Zero
518 *
519 **/
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530520int be_mcc_compl_poll(struct beiscsi_hba *phba, unsigned int tag)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530521{
Jitendra Bhivare69fd6d72016-02-04 15:49:14 +0530522 struct be_ctrl_info *ctrl = &phba->ctrl;
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530523 int i;
524
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530525 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530526 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530527 return -EIO;
528
Jitendra Bhivare2e4e8f62016-02-04 15:49:11 +0530529 beiscsi_process_mcc_cq(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530530
Jitendra Bhivare69fd6d72016-02-04 15:49:14 +0530531 if (!test_bit(MCC_TAG_STATE_RUNNING,
532 &ctrl->ptag_state[tag].tag_state))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530533 break;
534 udelay(100);
535 }
Jitendra Bhivare69fd6d72016-02-04 15:49:14 +0530536
537 if (i < mcc_timeout)
538 return 0;
539
540 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
541 "BC_%d : FW Timed Out\n");
542 phba->fw_timeout = true;
543 beiscsi_ue_detect(phba);
544 return -EBUSY;
545}
546
547void be_mcc_notify(struct beiscsi_hba *phba, unsigned int tag)
548{
549 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
550 u32 val = 0;
551
552 set_bit(MCC_TAG_STATE_RUNNING, &phba->ctrl.ptag_state[tag].tag_state);
553 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
554 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
555 /* make request available for DMA */
556 wmb();
557 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530558}
559
John Soni Josee175def2012-10-20 04:45:40 +0530560/*
Jitendra Bhivare88840332016-02-04 15:49:12 +0530561 * be_mbox_db_ready_poll()- Check ready status
John Soni Josee175def2012-10-20 04:45:40 +0530562 * @ctrl: Function specific MBX data structure
563 *
564 * Check for the ready status of FW to send BMBX
565 * commands to adapter.
566 *
567 * return
568 * Success: 0
569 * Failure: Non-Zero
570 **/
Jitendra Bhivare88840332016-02-04 15:49:12 +0530571static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530572{
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530573 /* wait 30s for generic non-flash MBOX operation */
574#define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530575 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530576 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700577 unsigned long timeout;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530578 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700579
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530580 /*
581 * This BMBX busy wait path is used during init only.
582 * For the commands executed during init, 5s should suffice.
583 */
584 timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530585 do {
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530586 if (beiscsi_error(phba))
587 return -EIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530588
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530589 ready = ioread32(db);
590 if (ready == 0xffffffff)
591 return -EIO;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700592
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530593 ready &= MPU_MAILBOX_DB_RDY_MASK;
594 if (ready)
595 return 0;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700596
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530597 if (time_after(jiffies, timeout))
598 break;
Jitendra Bhivare9ec6f6b2016-01-20 14:10:49 +0530599 msleep(20);
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530600 } while (!ready);
601
602 beiscsi_log(phba, KERN_ERR,
603 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
604 "BC_%d : FW Timed Out\n");
605
606 phba->fw_timeout = true;
607 beiscsi_ue_detect(phba);
608
609 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530610}
611
John Soni Josee175def2012-10-20 04:45:40 +0530612/*
613 * be_mbox_notify: Notify adapter of new BMBX command
614 * @ctrl: Function specific MBX data structure
615 *
616 * Ring doorbell to inform adapter of a BMBX command
617 * to process
618 *
619 * return
620 * Success: 0
621 * Failure: Non-Zero
622 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530623int be_mbox_notify(struct be_ctrl_info *ctrl)
624{
625 int status;
626 u32 val = 0;
627 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
628 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
629 struct be_mcc_mailbox *mbox = mbox_mem->va;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530630
Jitendra Bhivare88840332016-02-04 15:49:12 +0530631 status = be_mbox_db_ready_poll(ctrl);
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700632 if (status)
633 return status;
634
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530635 val &= ~MPU_MAILBOX_DB_RDY_MASK;
636 val |= MPU_MAILBOX_DB_HI_MASK;
637 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
638 iowrite32(val, db);
639
Jitendra Bhivare88840332016-02-04 15:49:12 +0530640 status = be_mbox_db_ready_poll(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530641 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530642 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530643
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530644 val = 0;
645 val &= ~MPU_MAILBOX_DB_RDY_MASK;
646 val &= ~MPU_MAILBOX_DB_HI_MASK;
647 val |= (u32) (mbox_mem->dma >> 4) << 2;
648 iowrite32(val, db);
649
Jitendra Bhivare88840332016-02-04 15:49:12 +0530650 status = be_mbox_db_ready_poll(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530651 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530652 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530653
Jitendra Bhivare6ac999e2016-01-20 14:10:45 +0530654 /* RDY is set; small delay before CQE read. */
655 udelay(1);
656
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +0530657 status = beiscsi_process_mbox_compl(ctrl, &mbox->compl);
658 return status;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530659}
660
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530661void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
662 bool embedded, u8 sge_cnt)
663{
664 if (embedded)
665 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
666 else
667 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
668 MCC_WRB_SGE_CNT_SHIFT;
669 wrb->payload_length = payload_len;
670 be_dws_cpu_to_le(wrb, 8);
671}
672
673void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
674 u8 subsystem, u8 opcode, int cmd_len)
675{
676 req_hdr->opcode = opcode;
677 req_hdr->subsystem = subsystem;
678 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530679 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530680}
681
682static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
683 struct be_dma_mem *mem)
684{
685 int i, buf_pages;
686 u64 dma = (u64) mem->dma;
687
688 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
689 for (i = 0; i < buf_pages; i++) {
690 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
691 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
692 dma += PAGE_SIZE_4K;
693 }
694}
695
696static u32 eq_delay_to_mult(u32 usec_delay)
697{
698#define MAX_INTR_RATE 651042
699 const u32 round = 10;
700 u32 multiplier;
701
702 if (usec_delay == 0)
703 multiplier = 0;
704 else {
705 u32 interrupt_rate = 1000000 / usec_delay;
706 if (interrupt_rate == 0)
707 multiplier = 1023;
708 else {
709 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
710 multiplier /= interrupt_rate;
711 multiplier = (multiplier + round / 2) / round;
712 multiplier = min(multiplier, (u32) 1023);
713 }
714 }
715 return multiplier;
716}
717
718struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
719{
720 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
721}
722
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530723struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
724{
725 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
726 struct be_mcc_wrb *wrb;
727
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700728 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530729 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530730 memset(wrb, 0, sizeof(*wrb));
Jitendra Bhivare67296ad2016-02-04 15:49:10 +0530731 wrb->tag0 = (mccq->head << MCC_Q_WRB_IDX_SHIFT) & MCC_Q_WRB_IDX_MASK;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530732 queue_head_inc(mccq);
733 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530734 return wrb;
735}
736
737
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530738int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
739 struct be_queue_info *eq, int eq_delay)
740{
741 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
742 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
743 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
744 struct be_dma_mem *q_mem = &eq->dma_mem;
745 int status;
746
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530747 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530748 memset(wrb, 0, sizeof(*wrb));
749
750 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
751
752 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
753 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
754
755 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
756
757 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
758 PCI_FUNC(ctrl->pdev->devfn));
759 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
760 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
761 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
762 __ilog2_u32(eq->len / 256));
763 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
764 eq_delay_to_mult(eq_delay));
765 be_dws_cpu_to_le(req->context, sizeof(req->context));
766
767 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
768
769 status = be_mbox_notify(ctrl);
770 if (!status) {
771 eq->id = le16_to_cpu(resp->eq_id);
772 eq->created = true;
773 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530774 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530775 return status;
776}
777
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700778/**
779 * be_cmd_fw_initialize()- Initialize FW
780 * @ctrl: Pointer to function control structure
781 *
782 * Send FW initialize pattern for the function.
783 *
784 * return
785 * Success: 0
786 * Failure: Non-Zero value
787 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530788int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
789{
790 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530791 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530792 int status;
793 u8 *endian_check;
794
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530795 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530796 memset(wrb, 0, sizeof(*wrb));
797
798 endian_check = (u8 *) wrb;
799 *endian_check++ = 0xFF;
800 *endian_check++ = 0x12;
801 *endian_check++ = 0x34;
802 *endian_check++ = 0xFF;
803 *endian_check++ = 0xFF;
804 *endian_check++ = 0x56;
805 *endian_check++ = 0x78;
806 *endian_check++ = 0xFF;
807 be_dws_cpu_to_le(wrb, sizeof(*wrb));
808
809 status = be_mbox_notify(ctrl);
810 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530811 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
812 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530813
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530814 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530815 return status;
816}
817
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700818/**
819 * be_cmd_fw_uninit()- Uinitialize FW
820 * @ctrl: Pointer to function control structure
821 *
822 * Send FW uninitialize pattern for the function
823 *
824 * return
825 * Success: 0
826 * Failure: Non-Zero value
827 **/
828int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
829{
830 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
831 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
832 int status;
833 u8 *endian_check;
834
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530835 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700836 memset(wrb, 0, sizeof(*wrb));
837
838 endian_check = (u8 *) wrb;
839 *endian_check++ = 0xFF;
840 *endian_check++ = 0xAA;
841 *endian_check++ = 0xBB;
842 *endian_check++ = 0xFF;
843 *endian_check++ = 0xFF;
844 *endian_check++ = 0xCC;
845 *endian_check++ = 0xDD;
846 *endian_check = 0xFF;
847
848 be_dws_cpu_to_le(wrb, sizeof(*wrb));
849
850 status = be_mbox_notify(ctrl);
851 if (status)
852 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
853 "BC_%d : be_cmd_fw_uninit Failed\n");
854
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530855 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700856 return status;
857}
858
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530859int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
860 struct be_queue_info *cq, struct be_queue_info *eq,
861 bool sol_evts, bool no_delay, int coalesce_wm)
862{
863 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
864 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
865 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530866 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530867 struct be_dma_mem *q_mem = &cq->dma_mem;
868 void *ctxt = &req->context;
869 int status;
870
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530871 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530872 memset(wrb, 0, sizeof(*wrb));
873
874 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
875
876 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
877 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530878
879 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700880 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530881 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
882 ctxt, coalesce_wm);
883 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
884 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
885 __ilog2_u32(cq->len / 256));
886 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
887 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
888 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
889 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
890 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
891 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
892 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700893 } else {
894 req->hdr.version = MBX_CMD_VER2;
895 req->page_size = 1;
896 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
897 ctxt, coalesce_wm);
898 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
899 ctxt, no_delay);
900 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
901 __ilog2_u32(cq->len / 256));
902 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
903 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
904 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
905 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +0530906 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530907
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530908 be_dws_cpu_to_le(ctxt, sizeof(req->context));
909
910 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
911
912 status = be_mbox_notify(ctrl);
913 if (!status) {
914 cq->id = le16_to_cpu(resp->cq_id);
915 cq->created = true;
916 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530917 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
918 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
919 status);
920
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530921 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530922
923 return status;
924}
925
926static u32 be_encoded_q_len(int q_len)
927{
928 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
929 if (len_encoded == 16)
930 len_encoded = 0;
931 return len_encoded;
932}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530933
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530934int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530935 struct be_queue_info *mccq,
936 struct be_queue_info *cq)
937{
938 struct be_mcc_wrb *wrb;
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530939 struct be_cmd_req_mcc_create_ext *req;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530940 struct be_dma_mem *q_mem = &mccq->dma_mem;
941 struct be_ctrl_info *ctrl;
942 void *ctxt;
943 int status;
944
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530945 mutex_lock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530946 ctrl = &phba->ctrl;
947 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -0500948 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530949 req = embedded_payload(wrb);
950 ctxt = &req->context;
951
952 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
953
954 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530955 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530956
957 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +0530958 req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
959 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
960 req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530961
962 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
963 PCI_FUNC(phba->pcidev->devfn));
964 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
965 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
966 be_encoded_q_len(mccq->len));
967 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
968
969 be_dws_cpu_to_le(ctxt, sizeof(req->context));
970
971 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
972
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +0530973 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530974 if (!status) {
975 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
976 mccq->id = le16_to_cpu(resp->id);
977 mccq->created = true;
978 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530979 mutex_unlock(&phba->ctrl.mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530980
981 return status;
982}
983
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530984int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
985 int queue_type)
986{
987 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
988 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530989 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530990 u8 subsys = 0, opcode = 0;
991 int status;
992
John Soni Jose99bc5d52012-08-20 23:00:18 +0530993 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
994 "BC_%d : In beiscsi_cmd_q_destroy "
995 "queue_type : %d\n", queue_type);
996
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530997 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530998 memset(wrb, 0, sizeof(*wrb));
999 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1000
1001 switch (queue_type) {
1002 case QTYPE_EQ:
1003 subsys = CMD_SUBSYSTEM_COMMON;
1004 opcode = OPCODE_COMMON_EQ_DESTROY;
1005 break;
1006 case QTYPE_CQ:
1007 subsys = CMD_SUBSYSTEM_COMMON;
1008 opcode = OPCODE_COMMON_CQ_DESTROY;
1009 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301010 case QTYPE_MCCQ:
1011 subsys = CMD_SUBSYSTEM_COMMON;
1012 opcode = OPCODE_COMMON_MCC_DESTROY;
1013 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301014 case QTYPE_WRBQ:
1015 subsys = CMD_SUBSYSTEM_ISCSI;
1016 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1017 break;
1018 case QTYPE_DPDUQ:
1019 subsys = CMD_SUBSYSTEM_ISCSI;
1020 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1021 break;
1022 case QTYPE_SGL:
1023 subsys = CMD_SUBSYSTEM_ISCSI;
1024 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1025 break;
1026 default:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301027 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301028 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301029 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301030 }
1031 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1032 if (queue_type != QTYPE_SGL)
1033 req->id = cpu_to_le16(q->id);
1034
1035 status = be_mbox_notify(ctrl);
1036
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301037 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301038 return status;
1039}
1040
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001041/**
1042 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1043 * @ctrl: ptr to ctrl_info
1044 * @cq: Completion Queue
1045 * @dq: Default Queue
1046 * @lenght: ring size
1047 * @entry_size: size of each entry in DEFQ
1048 * @is_header: Header or Data DEFQ
1049 * @ulp_num: Bind to which ULP
1050 *
1051 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1052 * on this queue by the FW
1053 *
1054 * return
1055 * Success: 0
1056 * Failure: Non-Zero Value
1057 *
1058 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301059int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1060 struct be_queue_info *cq,
1061 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001062 int entry_size, uint8_t is_header,
1063 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301064{
1065 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1066 struct be_defq_create_req *req = embedded_payload(wrb);
1067 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001068 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301069 void *ctxt = &req->context;
1070 int status;
1071
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301072 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301073 memset(wrb, 0, sizeof(*wrb));
1074
1075 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1076
1077 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1078 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1079
1080 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001081 if (phba->fw_config.dual_ulp_aware) {
1082 req->ulp_num = ulp_num;
1083 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1084 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1085 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001086
1087 if (is_chip_be2_be3r(phba)) {
1088 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1089 rx_pdid, ctxt, 0);
1090 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1091 rx_pdid_valid, ctxt, 1);
1092 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1093 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1094 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1095 ring_size, ctxt,
1096 be_encoded_q_len(length /
1097 sizeof(struct phys_addr)));
1098 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1099 default_buffer_size, ctxt, entry_size);
1100 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1101 cq_id_recv, ctxt, cq->id);
1102 } else {
1103 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1104 rx_pdid, ctxt, 0);
1105 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1106 rx_pdid_valid, ctxt, 1);
1107 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1108 ring_size, ctxt,
1109 be_encoded_q_len(length /
1110 sizeof(struct phys_addr)));
1111 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1112 default_buffer_size, ctxt, entry_size);
1113 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1114 cq_id_recv, ctxt, cq->id);
1115 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301116
1117 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1118
1119 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1120
1121 status = be_mbox_notify(ctrl);
1122 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001123 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301124 struct be_defq_create_resp *resp = embedded_payload(wrb);
1125
1126 dq->id = le16_to_cpu(resp->id);
1127 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001128 if (is_header)
1129 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1130 else
1131 defq_ring = &phba->phwi_ctrlr->
1132 default_pdu_data[ulp_num];
1133
1134 defq_ring->id = dq->id;
1135
1136 if (!phba->fw_config.dual_ulp_aware) {
1137 defq_ring->ulp_num = BEISCSI_ULP0;
1138 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1139 } else {
1140 defq_ring->ulp_num = resp->ulp_num;
1141 defq_ring->doorbell_offset = resp->doorbell_offset;
1142 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301143 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301144 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301145
1146 return status;
1147}
1148
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001149/**
1150 * be_cmd_wrbq_create()- Create WRBQ
1151 * @ctrl: ptr to ctrl_info
1152 * @q_mem: memory details for the queue
1153 * @wrbq: queue info
1154 * @pwrb_context: ptr to wrb_context
1155 * @ulp_num: ULP on which the WRBQ is to be created
1156 *
1157 * Create WRBQ on the passed ULP_NUM.
1158 *
1159 **/
1160int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1161 struct be_dma_mem *q_mem,
1162 struct be_queue_info *wrbq,
1163 struct hwi_wrb_context *pwrb_context,
1164 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301165{
1166 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1167 struct be_wrbq_create_req *req = embedded_payload(wrb);
1168 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001169 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301170 int status;
1171
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301172 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301173 memset(wrb, 0, sizeof(*wrb));
1174
1175 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1176
1177 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1178 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1179 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001180
1181 if (phba->fw_config.dual_ulp_aware) {
1182 req->ulp_num = ulp_num;
1183 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1184 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1185 }
1186
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301187 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1188
1189 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301190 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301191 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301192 wrbq->created = true;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001193
1194 pwrb_context->cid = wrbq->id;
1195 if (!phba->fw_config.dual_ulp_aware) {
1196 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1197 pwrb_context->ulp_num = BEISCSI_ULP0;
1198 } else {
1199 pwrb_context->ulp_num = resp->ulp_num;
1200 pwrb_context->doorbell_offset = resp->doorbell_offset;
1201 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301202 }
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301203 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301204 return status;
1205}
1206
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001207int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1208 struct be_dma_mem *q_mem)
1209{
1210 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1211 struct be_post_template_pages_req *req = embedded_payload(wrb);
1212 int status;
1213
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301214 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001215
1216 memset(wrb, 0, sizeof(*wrb));
1217 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1218 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1219 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1220 sizeof(*req));
1221
1222 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1223 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1224 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1225
1226 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301227 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001228 return status;
1229}
1230
1231int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1232{
1233 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1234 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1235 int status;
1236
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301237 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001238
1239 memset(wrb, 0, sizeof(*wrb));
1240 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1241 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1242 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1243 sizeof(*req));
1244
1245 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1246
1247 status = be_mbox_notify(ctrl);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301248 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001249 return status;
1250}
1251
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301252int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1253 struct be_dma_mem *q_mem,
1254 u32 page_offset, u32 num_pages)
1255{
1256 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1257 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301258 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301259 int status;
1260 unsigned int curr_pages;
1261 u32 internal_page_offset = 0;
1262 u32 temp_num_pages = num_pages;
1263
1264 if (num_pages == 0xff)
1265 num_pages = 1;
1266
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301267 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301268 do {
1269 memset(wrb, 0, sizeof(*wrb));
1270 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1271 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1272 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1273 sizeof(*req));
1274 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1275 pages);
1276 req->num_pages = min(num_pages, curr_pages);
1277 req->page_offset = page_offset;
1278 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1279 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1280 internal_page_offset += req->num_pages;
1281 page_offset += req->num_pages;
1282 num_pages -= req->num_pages;
1283
1284 if (temp_num_pages == 0xff)
1285 req->num_pages = temp_num_pages;
1286
1287 status = be_mbox_notify(ctrl);
1288 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301289 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1290 "BC_%d : FW CMD to map iscsi frags failed.\n");
1291
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301292 goto error;
1293 }
1294 } while (num_pages > 0);
1295error:
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301296 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301297 if (status != 0)
1298 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1299 return status;
1300}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001301
1302int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1303{
1304 struct be_ctrl_info *ctrl = &phba->ctrl;
1305 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1306 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1307 int status;
1308
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301309 mutex_lock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001310
1311 req = embedded_payload(wrb);
1312 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1313 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1314 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
Jitendra Bhivarea264f5e2016-02-04 15:49:13 +05301315 status = be_mbox_notify(ctrl);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001316
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301317 mutex_unlock(&ctrl->mbox_lock);
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001318 return status;
1319}
John Soni Jose6f722382012-08-20 23:00:43 +05301320
1321/**
1322 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1323 * @phba: device priv structure instance
1324 * @vlan_tag: TAG to be set
1325 *
1326 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1327 *
1328 * returns
1329 * TAG for the MBX Cmd
1330 * **/
1331int be_cmd_set_vlan(struct beiscsi_hba *phba,
1332 uint16_t vlan_tag)
1333{
1334 unsigned int tag = 0;
1335 struct be_mcc_wrb *wrb;
1336 struct be_cmd_set_vlan_req *req;
1337 struct be_ctrl_info *ctrl = &phba->ctrl;
1338
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301339 if (mutex_lock_interruptible(&ctrl->mbox_lock))
1340 return 0;
John Soni Jose6f722382012-08-20 23:00:43 +05301341 tag = alloc_mcc_tag(phba);
1342 if (!tag) {
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301343 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301344 return tag;
1345 }
1346
1347 wrb = wrb_from_mccq(phba);
1348 req = embedded_payload(wrb);
1349 wrb->tag0 |= tag;
1350 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1351 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1352 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1353 sizeof(*req));
1354
1355 req->interface_hndl = phba->interface_handle;
1356 req->vlan_priority = vlan_tag;
1357
Jitendra Bhivarecdde6682016-01-20 14:10:47 +05301358 be_mcc_notify(phba, tag);
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +05301359 mutex_unlock(&ctrl->mbox_lock);
John Soni Jose6f722382012-08-20 23:00:43 +05301360
1361 return tag;
1362}