blob: 86d91f31a6a32284dde6a6b3d9f22ef34de6ab5f [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal533c1652013-04-05 20:38:34 -07002 * Copyright (C) 2005 - 2013 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:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070011 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053012 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * Emulex
14 * 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 +0530107void be_mcc_notify(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530108{
109 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
110 u32 val = 0;
111
112 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
113 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
114 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
115}
116
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530117unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
118{
119 unsigned int tag = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530120
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530121 if (phba->ctrl.mcc_tag_available) {
122 tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
123 phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
124 phba->ctrl.mcc_numtag[tag] = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530125 }
126 if (tag) {
127 phba->ctrl.mcc_tag_available--;
128 if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
129 phba->ctrl.mcc_alloc_index = 0;
130 else
131 phba->ctrl.mcc_alloc_index++;
132 }
133 return tag;
134}
135
John Soni Josee175def2012-10-20 04:45:40 +0530136/*
137 * beiscsi_mccq_compl()- Wait for completion of MBX
138 * @phba: Driver private structure
139 * @tag: Tag for the MBX Command
140 * @wrb: the WRB used for the MBX Command
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500141 * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
John Soni Josee175def2012-10-20 04:45:40 +0530142 *
143 * Waits for MBX completion with the passed TAG.
144 *
145 * return
146 * Success: 0
147 * Failure: Non-Zero
148 **/
149int beiscsi_mccq_compl(struct beiscsi_hba *phba,
150 uint32_t tag, struct be_mcc_wrb **wrb,
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500151 struct be_dma_mem *mbx_cmd_mem)
John Soni Josee175def2012-10-20 04:45:40 +0530152{
153 int rc = 0;
154 uint32_t mcc_tag_response;
155 uint16_t status = 0, addl_status = 0, wrb_num = 0;
156 struct be_mcc_wrb *temp_wrb;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500157 struct be_cmd_req_hdr *mbx_hdr;
158 struct be_cmd_resp_hdr *mbx_resp_hdr;
John Soni Josee175def2012-10-20 04:45:40 +0530159 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
160
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700161 if (beiscsi_error(phba)) {
162 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500163 return -EPERM;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700164 }
John Soni Jose7a158002012-10-20 04:45:51 +0530165
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500166 /* Set MBX Tag state to Active */
167 spin_lock(&phba->ctrl.mbox_lock);
168 phba->ctrl.ptag_state[tag].tag_state = MCC_TAG_STATE_RUNNING;
169 spin_unlock(&phba->ctrl.mbox_lock);
170
John Soni Josee175def2012-10-20 04:45:40 +0530171 /* wait for the mccq completion */
172 rc = wait_event_interruptible_timeout(
173 phba->ctrl.mcc_wait[tag],
174 phba->ctrl.mcc_numtag[tag],
175 msecs_to_jiffies(
176 BEISCSI_HOST_MBX_TIMEOUT));
177
178 if (rc <= 0) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500179 struct be_dma_mem *tag_mem;
180 /* Set MBX Tag state to timeout */
181 spin_lock(&phba->ctrl.mbox_lock);
182 phba->ctrl.ptag_state[tag].tag_state = MCC_TAG_STATE_TIMEOUT;
183 spin_unlock(&phba->ctrl.mbox_lock);
184
185 /* Store resource addr to be freed later */
186 tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
187 if (mbx_cmd_mem) {
188 tag_mem->size = mbx_cmd_mem->size;
189 tag_mem->va = mbx_cmd_mem->va;
190 tag_mem->dma = mbx_cmd_mem->dma;
191 } else
192 tag_mem->size = 0;
193
John Soni Josee175def2012-10-20 04:45:40 +0530194 beiscsi_log(phba, KERN_ERR,
195 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
196 BEISCSI_LOG_CONFIG,
197 "BC_%d : MBX Cmd Completion timed out\n");
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500198 return -EBUSY;
199 } else {
John Soni Josee175def2012-10-20 04:45:40 +0530200 rc = 0;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500201 /* Set MBX Tag state to completed */
202 spin_lock(&phba->ctrl.mbox_lock);
203 phba->ctrl.ptag_state[tag].tag_state = MCC_TAG_STATE_COMPLETED;
204 spin_unlock(&phba->ctrl.mbox_lock);
205 }
John Soni Josee175def2012-10-20 04:45:40 +0530206
207 mcc_tag_response = phba->ctrl.mcc_numtag[tag];
208 status = (mcc_tag_response & CQE_STATUS_MASK);
209 addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
210 CQE_STATUS_ADDL_SHIFT);
211
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500212 if (mbx_cmd_mem) {
213 mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va;
John Soni Josee175def2012-10-20 04:45:40 +0530214 } else {
215 wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
216 CQE_STATUS_WRB_SHIFT;
217 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500218 mbx_hdr = embedded_payload(temp_wrb);
John Soni Josee175def2012-10-20 04:45:40 +0530219
220 if (wrb)
221 *wrb = temp_wrb;
222 }
223
224 if (status || addl_status) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500225 beiscsi_log(phba, KERN_WARNING,
John Soni Josee175def2012-10-20 04:45:40 +0530226 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
227 BEISCSI_LOG_CONFIG,
228 "BC_%d : MBX Cmd Failed for "
229 "Subsys : %d Opcode : %d with "
230 "Status : %d and Extd_Status : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500231 mbx_hdr->subsystem,
232 mbx_hdr->opcode,
John Soni Josee175def2012-10-20 04:45:40 +0530233 status, addl_status);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700234
235 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500236 mbx_resp_hdr = (struct be_cmd_resp_hdr *) mbx_hdr;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700237 beiscsi_log(phba, KERN_WARNING,
238 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
239 BEISCSI_LOG_CONFIG,
240 "BC_%d : Insufficent Buffer Error "
241 "Resp_Len : %d Actual_Resp_Len : %d\n",
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500242 mbx_resp_hdr->response_length,
243 mbx_resp_hdr->actual_resp_len);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700244
245 rc = -EAGAIN;
246 goto release_mcc_tag;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700247 }
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700248 rc = -EIO;
John Soni Josee175def2012-10-20 04:45:40 +0530249 }
250
251release_mcc_tag:
252 /* Release the MCC entry */
253 free_mcc_tag(&phba->ctrl, tag);
254
255 return rc;
256}
257
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530258void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
259{
260 spin_lock(&ctrl->mbox_lock);
261 tag = tag & 0x000000FF;
262 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
263 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
264 ctrl->mcc_free_index = 0;
265 else
266 ctrl->mcc_free_index++;
267 ctrl->mcc_tag_available++;
268 spin_unlock(&ctrl->mbox_lock);
269}
270
271bool is_link_state_evt(u32 trailer)
272{
273 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
274 ASYNC_TRAILER_EVENT_CODE_MASK) ==
275 ASYNC_EVENT_CODE_LINK_STATE);
276}
277
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530278static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
279{
280 if (compl->flags != 0) {
281 compl->flags = le32_to_cpu(compl->flags);
282 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
283 return true;
284 } else
285 return false;
286}
287
288static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
289{
290 compl->flags = 0;
291}
292
John Soni Josee175def2012-10-20 04:45:40 +0530293/*
294 * be_mcc_compl_process()- Check the MBX comapletion status
295 * @ctrl: Function specific MBX data structure
296 * @compl: Completion status of MBX Command
297 *
298 * Check for the MBX completion status when BMBX method used
299 *
300 * return
301 * Success: Zero
302 * Failure: Non-Zero
303 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530304static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
305 struct be_mcc_compl *compl)
306{
307 u16 compl_status, extd_status;
John Soni Josee175def2012-10-20 04:45:40 +0530308 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530309 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
John Soni Josee175def2012-10-20 04:45:40 +0530310 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700311 struct be_cmd_resp_hdr *resp_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530312
313 be_dws_le_to_cpu(compl, 4);
314
315 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
316 CQE_STATUS_COMPL_MASK;
317 if (compl_status != MCC_STATUS_SUCCESS) {
318 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
319 CQE_STATUS_EXTD_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530320
321 beiscsi_log(phba, KERN_ERR,
322 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530323 "BC_%d : error in cmd completion: "
324 "Subsystem : %d Opcode : %d "
325 "status(compl/extd)=%d/%d\n",
326 hdr->subsystem, hdr->opcode,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530327 compl_status, extd_status);
328
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700329 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
330 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
331 if (resp_hdr->response_length)
332 return 0;
333 }
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530334 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530335 }
336 return 0;
337}
338
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530339int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
340 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530341{
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500342 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530343 u16 compl_status, extd_status;
344 unsigned short tag;
345
346 be_dws_le_to_cpu(compl, 4);
347
348 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
349 CQE_STATUS_COMPL_MASK;
350 /* The ctrl.mcc_numtag[tag] is filled with
351 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
352 * [7:0] = compl_status
353 */
354 tag = (compl->tag0 & 0x000000FF);
355 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
356 CQE_STATUS_EXTD_MASK;
357
358 ctrl->mcc_numtag[tag] = 0x80000000;
359 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
360 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
361 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500362
363 if (ctrl->ptag_state[tag].tag_state == MCC_TAG_STATE_RUNNING) {
364 wake_up_interruptible(&ctrl->mcc_wait[tag]);
365 } else if (ctrl->ptag_state[tag].tag_state == MCC_TAG_STATE_TIMEOUT) {
366 struct be_dma_mem *tag_mem;
367 tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
368
369 beiscsi_log(phba, KERN_WARNING,
370 BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
371 BEISCSI_LOG_CONFIG,
372 "BC_%d : MBX Completion for timeout Command "
373 "from FW\n");
374 /* Check if memory needs to be freed */
375 if (tag_mem->size)
376 pci_free_consistent(ctrl->pdev, tag_mem->size,
377 tag_mem->va, tag_mem->dma);
378
379 /* Change tag state */
380 spin_lock(&phba->ctrl.mbox_lock);
381 ctrl->ptag_state[tag].tag_state = MCC_TAG_STATE_COMPLETED;
382 spin_unlock(&phba->ctrl.mbox_lock);
383
384 /* Free MCC Tag */
385 free_mcc_tag(ctrl, tag);
386 }
387
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530388 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530389}
390
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530391static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
392{
393 struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
394 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
395
396 if (be_mcc_compl_is_new(compl)) {
397 queue_tail_inc(mcc_cq);
398 return compl;
399 }
400 return NULL;
401}
402
403static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
404{
405 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
406}
407
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530408void 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,
422 be2iscsi_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 Kallickal3567f362013-09-28 15:35:58 -0700426 phba->state = BE_ADAPTER_LINK_UP;
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700427
John Soni Jose99bc5d52012-08-20 23:00:18 +0530428 beiscsi_log(phba, KERN_ERR,
429 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700430 "BC_%d : Link UP on Port %d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +0530431 evt->physical_port);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530432 }
433}
434
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530435int beiscsi_process_mcc(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530436{
437 struct be_mcc_compl *compl;
438 int num = 0, status = 0;
439 struct be_ctrl_info *ctrl = &phba->ctrl;
440
441 spin_lock_bh(&phba->ctrl.mcc_cq_lock);
442 while ((compl = be_mcc_compl_get(phba))) {
443 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
444 /* Interpret flags as an async trailer */
Jayamohan Kallickal78b9fb62009-11-25 01:41:37 +0530445 if (is_link_state_evt(compl->flags))
446 /* Interpret compl as a async link evt */
447 beiscsi_async_link_state_process(phba,
448 (struct be_async_event_link_state *) compl);
449 else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530450 beiscsi_log(phba, KERN_ERR,
451 BEISCSI_LOG_CONFIG |
452 BEISCSI_LOG_MBOX,
453 "BC_%d : Unsupported Async Event, flags"
454 " = 0x%08x\n", compl->flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530455
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530456 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
457 status = be_mcc_compl_process(ctrl, compl);
458 atomic_dec(&phba->ctrl.mcc_obj.q.used);
459 }
460 be_mcc_compl_use(compl);
461 num++;
462 }
463
464 if (num)
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -0500465 hwi_ring_cq_db(phba, phba->ctrl.mcc_obj.cq.id, num, 1, 0);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530466
467 spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
468 return status;
469}
470
John Soni Josee175def2012-10-20 04:45:40 +0530471/*
472 * be_mcc_wait_compl()- Wait for MBX completion
473 * @phba: driver private structure
474 *
475 * Wait till no more pending mcc requests are present
476 *
477 * return
478 * Success: 0
479 * Failure: Non-Zero
480 *
481 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530482static int be_mcc_wait_compl(struct beiscsi_hba *phba)
483{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530484 int i, status;
485 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530486 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530487 return -EIO;
488
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530489 status = beiscsi_process_mcc(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530490 if (status)
491 return status;
492
493 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
494 break;
495 udelay(100);
496 }
497 if (i == mcc_timeout) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530498 beiscsi_log(phba, KERN_ERR,
499 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530500 "BC_%d : FW Timed Out\n");
501 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530502 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530503 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530504 }
505 return 0;
506}
507
John Soni Josee175def2012-10-20 04:45:40 +0530508/*
509 * be_mcc_notify_wait()- Notify and wait for Compl
510 * @phba: driver private structure
511 *
512 * Notify MCC requests and wait for completion
513 *
514 * return
515 * Success: 0
516 * Failure: Non-Zero
517 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530518int be_mcc_notify_wait(struct beiscsi_hba *phba)
519{
520 be_mcc_notify(phba);
521 return be_mcc_wait_compl(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530522}
523
John Soni Josee175def2012-10-20 04:45:40 +0530524/*
525 * be_mbox_db_ready_wait()- Check ready status
526 * @ctrl: Function specific MBX data structure
527 *
528 * Check for the ready status of FW to send BMBX
529 * commands to adapter.
530 *
531 * return
532 * Success: 0
533 * Failure: Non-Zero
534 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530535static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
536{
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700537#define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530538 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530539 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700540 unsigned long timeout;
541 bool read_flag = false;
542 int ret = 0, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530543 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700544 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q);
545
546 if (beiscsi_error(phba))
547 return -EIO;
548
549 timeout = jiffies + (HZ * 110);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530550
551 do {
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700552 for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) {
553 ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
554 if (ready) {
555 read_flag = true;
556 break;
557 }
558 mdelay(1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530559 }
560
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700561 if (!read_flag) {
562 wait_event_timeout(rdybit_check_q,
563 (read_flag != true),
564 HZ * 5);
565 }
566 } while ((time_before(jiffies, timeout)) && !read_flag);
567
568 if (!read_flag) {
569 beiscsi_log(phba, KERN_ERR,
570 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
571 "BC_%d : FW Timed Out\n");
572 phba->fw_timeout = true;
573 beiscsi_ue_detect(phba);
574 ret = -EBUSY;
575 }
576
577 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530578}
579
John Soni Josee175def2012-10-20 04:45:40 +0530580/*
581 * be_mbox_notify: Notify adapter of new BMBX command
582 * @ctrl: Function specific MBX data structure
583 *
584 * Ring doorbell to inform adapter of a BMBX command
585 * to process
586 *
587 * return
588 * Success: 0
589 * Failure: Non-Zero
590 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530591int be_mbox_notify(struct be_ctrl_info *ctrl)
592{
593 int status;
594 u32 val = 0;
595 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
596 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
597 struct be_mcc_mailbox *mbox = mbox_mem->va;
598 struct be_mcc_compl *compl = &mbox->compl;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530599 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530600
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700601 status = be_mbox_db_ready_wait(ctrl);
602 if (status)
603 return status;
604
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530605 val &= ~MPU_MAILBOX_DB_RDY_MASK;
606 val |= MPU_MAILBOX_DB_HI_MASK;
607 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
608 iowrite32(val, db);
609
610 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530611 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530612 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530613
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530614 val = 0;
615 val &= ~MPU_MAILBOX_DB_RDY_MASK;
616 val &= ~MPU_MAILBOX_DB_HI_MASK;
617 val |= (u32) (mbox_mem->dma >> 4) << 2;
618 iowrite32(val, db);
619
620 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530621 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530622 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530623
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530624 if (be_mcc_compl_is_new(compl)) {
625 status = be_mcc_compl_process(ctrl, &mbox->compl);
626 be_mcc_compl_use(compl);
627 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530628 beiscsi_log(phba, KERN_ERR,
629 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
630 "BC_%d : After be_mcc_compl_process\n");
631
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530632 return status;
633 }
634 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530635 beiscsi_log(phba, KERN_ERR,
636 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
637 "BC_%d : Invalid Mailbox Completion\n");
638
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530639 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530640 }
641 return 0;
642}
643
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530644/*
645 * Insert the mailbox address into the doorbell in two steps
646 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
647 */
648static int be_mbox_notify_wait(struct beiscsi_hba *phba)
649{
650 int status;
651 u32 val = 0;
652 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
653 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
654 struct be_mcc_mailbox *mbox = mbox_mem->va;
655 struct be_mcc_compl *compl = &mbox->compl;
656 struct be_ctrl_info *ctrl = &phba->ctrl;
657
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700658 status = be_mbox_db_ready_wait(ctrl);
659 if (status)
660 return status;
661
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530662 val |= MPU_MAILBOX_DB_HI_MASK;
663 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
664 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
665 iowrite32(val, db);
666
667 /* wait for ready to be set */
668 status = be_mbox_db_ready_wait(ctrl);
669 if (status != 0)
670 return status;
671
672 val = 0;
673 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
674 val |= (u32)(mbox_mem->dma >> 4) << 2;
675 iowrite32(val, db);
676
677 status = be_mbox_db_ready_wait(ctrl);
678 if (status != 0)
679 return status;
680
681 /* A cq entry has been made now */
682 if (be_mcc_compl_is_new(compl)) {
683 status = be_mcc_compl_process(ctrl, &mbox->compl);
684 be_mcc_compl_use(compl);
685 if (status)
686 return status;
687 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530688 beiscsi_log(phba, KERN_ERR,
689 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
690 "BC_%d : invalid mailbox completion\n");
691
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530692 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530693 }
694 return 0;
695}
696
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530697void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
698 bool embedded, u8 sge_cnt)
699{
700 if (embedded)
701 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
702 else
703 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
704 MCC_WRB_SGE_CNT_SHIFT;
705 wrb->payload_length = payload_len;
706 be_dws_cpu_to_le(wrb, 8);
707}
708
709void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
710 u8 subsystem, u8 opcode, int cmd_len)
711{
712 req_hdr->opcode = opcode;
713 req_hdr->subsystem = subsystem;
714 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530715 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530716}
717
718static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
719 struct be_dma_mem *mem)
720{
721 int i, buf_pages;
722 u64 dma = (u64) mem->dma;
723
724 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
725 for (i = 0; i < buf_pages; i++) {
726 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
727 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
728 dma += PAGE_SIZE_4K;
729 }
730}
731
732static u32 eq_delay_to_mult(u32 usec_delay)
733{
734#define MAX_INTR_RATE 651042
735 const u32 round = 10;
736 u32 multiplier;
737
738 if (usec_delay == 0)
739 multiplier = 0;
740 else {
741 u32 interrupt_rate = 1000000 / usec_delay;
742 if (interrupt_rate == 0)
743 multiplier = 1023;
744 else {
745 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
746 multiplier /= interrupt_rate;
747 multiplier = (multiplier + round / 2) / round;
748 multiplier = min(multiplier, (u32) 1023);
749 }
750 }
751 return multiplier;
752}
753
754struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
755{
756 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
757}
758
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530759struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
760{
761 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
762 struct be_mcc_wrb *wrb;
763
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700764 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530765 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530766 memset(wrb, 0, sizeof(*wrb));
767 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530768 queue_head_inc(mccq);
769 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530770 return wrb;
771}
772
773
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530774int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
775 struct be_queue_info *eq, int eq_delay)
776{
777 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
778 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
779 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
780 struct be_dma_mem *q_mem = &eq->dma_mem;
781 int status;
782
783 spin_lock(&ctrl->mbox_lock);
784 memset(wrb, 0, sizeof(*wrb));
785
786 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
787
788 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
789 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
790
791 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
792
793 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
794 PCI_FUNC(ctrl->pdev->devfn));
795 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
796 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
797 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
798 __ilog2_u32(eq->len / 256));
799 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
800 eq_delay_to_mult(eq_delay));
801 be_dws_cpu_to_le(req->context, sizeof(req->context));
802
803 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
804
805 status = be_mbox_notify(ctrl);
806 if (!status) {
807 eq->id = le16_to_cpu(resp->eq_id);
808 eq->created = true;
809 }
810 spin_unlock(&ctrl->mbox_lock);
811 return status;
812}
813
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700814/**
815 * be_cmd_fw_initialize()- Initialize FW
816 * @ctrl: Pointer to function control structure
817 *
818 * Send FW initialize pattern for the function.
819 *
820 * return
821 * Success: 0
822 * Failure: Non-Zero value
823 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530824int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
825{
826 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530827 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530828 int status;
829 u8 *endian_check;
830
831 spin_lock(&ctrl->mbox_lock);
832 memset(wrb, 0, sizeof(*wrb));
833
834 endian_check = (u8 *) wrb;
835 *endian_check++ = 0xFF;
836 *endian_check++ = 0x12;
837 *endian_check++ = 0x34;
838 *endian_check++ = 0xFF;
839 *endian_check++ = 0xFF;
840 *endian_check++ = 0x56;
841 *endian_check++ = 0x78;
842 *endian_check++ = 0xFF;
843 be_dws_cpu_to_le(wrb, sizeof(*wrb));
844
845 status = be_mbox_notify(ctrl);
846 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530847 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
848 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530849
850 spin_unlock(&ctrl->mbox_lock);
851 return status;
852}
853
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700854/**
855 * be_cmd_fw_uninit()- Uinitialize FW
856 * @ctrl: Pointer to function control structure
857 *
858 * Send FW uninitialize pattern for the function
859 *
860 * return
861 * Success: 0
862 * Failure: Non-Zero value
863 **/
864int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
865{
866 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
867 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
868 int status;
869 u8 *endian_check;
870
871 spin_lock(&ctrl->mbox_lock);
872 memset(wrb, 0, sizeof(*wrb));
873
874 endian_check = (u8 *) wrb;
875 *endian_check++ = 0xFF;
876 *endian_check++ = 0xAA;
877 *endian_check++ = 0xBB;
878 *endian_check++ = 0xFF;
879 *endian_check++ = 0xFF;
880 *endian_check++ = 0xCC;
881 *endian_check++ = 0xDD;
882 *endian_check = 0xFF;
883
884 be_dws_cpu_to_le(wrb, sizeof(*wrb));
885
886 status = be_mbox_notify(ctrl);
887 if (status)
888 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
889 "BC_%d : be_cmd_fw_uninit Failed\n");
890
891 spin_unlock(&ctrl->mbox_lock);
892 return status;
893}
894
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530895int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
896 struct be_queue_info *cq, struct be_queue_info *eq,
897 bool sol_evts, bool no_delay, int coalesce_wm)
898{
899 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
900 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
901 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530902 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530903 struct be_dma_mem *q_mem = &cq->dma_mem;
904 void *ctxt = &req->context;
905 int status;
906
907 spin_lock(&ctrl->mbox_lock);
908 memset(wrb, 0, sizeof(*wrb));
909
910 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
911
912 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
913 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530914
915 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700916 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530917 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
918 ctxt, coalesce_wm);
919 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
920 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
921 __ilog2_u32(cq->len / 256));
922 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
923 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
924 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
925 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
926 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
927 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
928 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700929 } else {
930 req->hdr.version = MBX_CMD_VER2;
931 req->page_size = 1;
932 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
933 ctxt, coalesce_wm);
934 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
935 ctxt, no_delay);
936 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
937 __ilog2_u32(cq->len / 256));
938 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
939 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
940 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
941 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +0530942 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530943
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530944 be_dws_cpu_to_le(ctxt, sizeof(req->context));
945
946 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
947
948 status = be_mbox_notify(ctrl);
949 if (!status) {
950 cq->id = le16_to_cpu(resp->cq_id);
951 cq->created = true;
952 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530953 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
954 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
955 status);
956
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530957 spin_unlock(&ctrl->mbox_lock);
958
959 return status;
960}
961
962static u32 be_encoded_q_len(int q_len)
963{
964 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
965 if (len_encoded == 16)
966 len_encoded = 0;
967 return len_encoded;
968}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530969
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530970int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530971 struct be_queue_info *mccq,
972 struct be_queue_info *cq)
973{
974 struct be_mcc_wrb *wrb;
975 struct be_cmd_req_mcc_create *req;
976 struct be_dma_mem *q_mem = &mccq->dma_mem;
977 struct be_ctrl_info *ctrl;
978 void *ctxt;
979 int status;
980
981 spin_lock(&phba->ctrl.mbox_lock);
982 ctrl = &phba->ctrl;
983 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -0500984 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530985 req = embedded_payload(wrb);
986 ctxt = &req->context;
987
988 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
989
990 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
991 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
992
993 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
994
995 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
996 PCI_FUNC(phba->pcidev->devfn));
997 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
998 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
999 be_encoded_q_len(mccq->len));
1000 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
1001
1002 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1003
1004 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1005
1006 status = be_mbox_notify_wait(phba);
1007 if (!status) {
1008 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1009 mccq->id = le16_to_cpu(resp->id);
1010 mccq->created = true;
1011 }
1012 spin_unlock(&phba->ctrl.mbox_lock);
1013
1014 return status;
1015}
1016
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301017int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
1018 int queue_type)
1019{
1020 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1021 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301022 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301023 u8 subsys = 0, opcode = 0;
1024 int status;
1025
John Soni Jose99bc5d52012-08-20 23:00:18 +05301026 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
1027 "BC_%d : In beiscsi_cmd_q_destroy "
1028 "queue_type : %d\n", queue_type);
1029
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301030 spin_lock(&ctrl->mbox_lock);
1031 memset(wrb, 0, sizeof(*wrb));
1032 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1033
1034 switch (queue_type) {
1035 case QTYPE_EQ:
1036 subsys = CMD_SUBSYSTEM_COMMON;
1037 opcode = OPCODE_COMMON_EQ_DESTROY;
1038 break;
1039 case QTYPE_CQ:
1040 subsys = CMD_SUBSYSTEM_COMMON;
1041 opcode = OPCODE_COMMON_CQ_DESTROY;
1042 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301043 case QTYPE_MCCQ:
1044 subsys = CMD_SUBSYSTEM_COMMON;
1045 opcode = OPCODE_COMMON_MCC_DESTROY;
1046 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301047 case QTYPE_WRBQ:
1048 subsys = CMD_SUBSYSTEM_ISCSI;
1049 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1050 break;
1051 case QTYPE_DPDUQ:
1052 subsys = CMD_SUBSYSTEM_ISCSI;
1053 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1054 break;
1055 case QTYPE_SGL:
1056 subsys = CMD_SUBSYSTEM_ISCSI;
1057 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1058 break;
1059 default:
1060 spin_unlock(&ctrl->mbox_lock);
1061 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301062 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301063 }
1064 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1065 if (queue_type != QTYPE_SGL)
1066 req->id = cpu_to_le16(q->id);
1067
1068 status = be_mbox_notify(ctrl);
1069
1070 spin_unlock(&ctrl->mbox_lock);
1071 return status;
1072}
1073
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001074/**
1075 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1076 * @ctrl: ptr to ctrl_info
1077 * @cq: Completion Queue
1078 * @dq: Default Queue
1079 * @lenght: ring size
1080 * @entry_size: size of each entry in DEFQ
1081 * @is_header: Header or Data DEFQ
1082 * @ulp_num: Bind to which ULP
1083 *
1084 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1085 * on this queue by the FW
1086 *
1087 * return
1088 * Success: 0
1089 * Failure: Non-Zero Value
1090 *
1091 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301092int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1093 struct be_queue_info *cq,
1094 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001095 int entry_size, uint8_t is_header,
1096 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301097{
1098 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1099 struct be_defq_create_req *req = embedded_payload(wrb);
1100 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001101 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301102 void *ctxt = &req->context;
1103 int status;
1104
1105 spin_lock(&ctrl->mbox_lock);
1106 memset(wrb, 0, sizeof(*wrb));
1107
1108 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1109
1110 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1111 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1112
1113 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001114 if (phba->fw_config.dual_ulp_aware) {
1115 req->ulp_num = ulp_num;
1116 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1117 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1118 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001119
1120 if (is_chip_be2_be3r(phba)) {
1121 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1122 rx_pdid, ctxt, 0);
1123 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1124 rx_pdid_valid, ctxt, 1);
1125 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1126 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1127 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1128 ring_size, ctxt,
1129 be_encoded_q_len(length /
1130 sizeof(struct phys_addr)));
1131 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1132 default_buffer_size, ctxt, entry_size);
1133 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1134 cq_id_recv, ctxt, cq->id);
1135 } else {
1136 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1137 rx_pdid, ctxt, 0);
1138 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1139 rx_pdid_valid, ctxt, 1);
1140 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1141 ring_size, ctxt,
1142 be_encoded_q_len(length /
1143 sizeof(struct phys_addr)));
1144 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1145 default_buffer_size, ctxt, entry_size);
1146 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1147 cq_id_recv, ctxt, cq->id);
1148 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301149
1150 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1151
1152 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1153
1154 status = be_mbox_notify(ctrl);
1155 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001156 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301157 struct be_defq_create_resp *resp = embedded_payload(wrb);
1158
1159 dq->id = le16_to_cpu(resp->id);
1160 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001161 if (is_header)
1162 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1163 else
1164 defq_ring = &phba->phwi_ctrlr->
1165 default_pdu_data[ulp_num];
1166
1167 defq_ring->id = dq->id;
1168
1169 if (!phba->fw_config.dual_ulp_aware) {
1170 defq_ring->ulp_num = BEISCSI_ULP0;
1171 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1172 } else {
1173 defq_ring->ulp_num = resp->ulp_num;
1174 defq_ring->doorbell_offset = resp->doorbell_offset;
1175 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301176 }
1177 spin_unlock(&ctrl->mbox_lock);
1178
1179 return status;
1180}
1181
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001182/**
1183 * be_cmd_wrbq_create()- Create WRBQ
1184 * @ctrl: ptr to ctrl_info
1185 * @q_mem: memory details for the queue
1186 * @wrbq: queue info
1187 * @pwrb_context: ptr to wrb_context
1188 * @ulp_num: ULP on which the WRBQ is to be created
1189 *
1190 * Create WRBQ on the passed ULP_NUM.
1191 *
1192 **/
1193int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
1194 struct be_dma_mem *q_mem,
1195 struct be_queue_info *wrbq,
1196 struct hwi_wrb_context *pwrb_context,
1197 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301198{
1199 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1200 struct be_wrbq_create_req *req = embedded_payload(wrb);
1201 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001202 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301203 int status;
1204
1205 spin_lock(&ctrl->mbox_lock);
1206 memset(wrb, 0, sizeof(*wrb));
1207
1208 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1209
1210 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1211 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1212 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001213
1214 if (phba->fw_config.dual_ulp_aware) {
1215 req->ulp_num = ulp_num;
1216 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1217 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1218 }
1219
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301220 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1221
1222 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301223 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301224 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301225 wrbq->created = true;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07001226
1227 pwrb_context->cid = wrbq->id;
1228 if (!phba->fw_config.dual_ulp_aware) {
1229 pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
1230 pwrb_context->ulp_num = BEISCSI_ULP0;
1231 } else {
1232 pwrb_context->ulp_num = resp->ulp_num;
1233 pwrb_context->doorbell_offset = resp->doorbell_offset;
1234 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301235 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301236 spin_unlock(&ctrl->mbox_lock);
1237 return status;
1238}
1239
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001240int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1241 struct be_dma_mem *q_mem)
1242{
1243 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1244 struct be_post_template_pages_req *req = embedded_payload(wrb);
1245 int status;
1246
1247 spin_lock(&ctrl->mbox_lock);
1248
1249 memset(wrb, 0, sizeof(*wrb));
1250 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1251 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1252 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1253 sizeof(*req));
1254
1255 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1256 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1257 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1258
1259 status = be_mbox_notify(ctrl);
1260 spin_unlock(&ctrl->mbox_lock);
1261 return status;
1262}
1263
1264int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1265{
1266 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1267 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1268 int status;
1269
1270 spin_lock(&ctrl->mbox_lock);
1271
1272 memset(wrb, 0, sizeof(*wrb));
1273 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1274 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1275 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1276 sizeof(*req));
1277
1278 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1279
1280 status = be_mbox_notify(ctrl);
1281 spin_unlock(&ctrl->mbox_lock);
1282 return status;
1283}
1284
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301285int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1286 struct be_dma_mem *q_mem,
1287 u32 page_offset, u32 num_pages)
1288{
1289 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1290 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301291 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301292 int status;
1293 unsigned int curr_pages;
1294 u32 internal_page_offset = 0;
1295 u32 temp_num_pages = num_pages;
1296
1297 if (num_pages == 0xff)
1298 num_pages = 1;
1299
1300 spin_lock(&ctrl->mbox_lock);
1301 do {
1302 memset(wrb, 0, sizeof(*wrb));
1303 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1304 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1305 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1306 sizeof(*req));
1307 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1308 pages);
1309 req->num_pages = min(num_pages, curr_pages);
1310 req->page_offset = page_offset;
1311 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1312 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1313 internal_page_offset += req->num_pages;
1314 page_offset += req->num_pages;
1315 num_pages -= req->num_pages;
1316
1317 if (temp_num_pages == 0xff)
1318 req->num_pages = temp_num_pages;
1319
1320 status = be_mbox_notify(ctrl);
1321 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301322 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1323 "BC_%d : FW CMD to map iscsi frags failed.\n");
1324
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301325 goto error;
1326 }
1327 } while (num_pages > 0);
1328error:
1329 spin_unlock(&ctrl->mbox_lock);
1330 if (status != 0)
1331 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1332 return status;
1333}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001334
1335int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1336{
1337 struct be_ctrl_info *ctrl = &phba->ctrl;
1338 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1339 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1340 int status;
1341
1342 spin_lock(&ctrl->mbox_lock);
1343
1344 req = embedded_payload(wrb);
1345 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1346 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1347 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1348 status = be_mbox_notify_wait(phba);
1349
1350 spin_unlock(&ctrl->mbox_lock);
1351 return status;
1352}
John Soni Jose6f722382012-08-20 23:00:43 +05301353
1354/**
1355 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1356 * @phba: device priv structure instance
1357 * @vlan_tag: TAG to be set
1358 *
1359 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1360 *
1361 * returns
1362 * TAG for the MBX Cmd
1363 * **/
1364int be_cmd_set_vlan(struct beiscsi_hba *phba,
1365 uint16_t vlan_tag)
1366{
1367 unsigned int tag = 0;
1368 struct be_mcc_wrb *wrb;
1369 struct be_cmd_set_vlan_req *req;
1370 struct be_ctrl_info *ctrl = &phba->ctrl;
1371
1372 spin_lock(&ctrl->mbox_lock);
1373 tag = alloc_mcc_tag(phba);
1374 if (!tag) {
1375 spin_unlock(&ctrl->mbox_lock);
1376 return tag;
1377 }
1378
1379 wrb = wrb_from_mccq(phba);
1380 req = embedded_payload(wrb);
1381 wrb->tag0 |= tag;
1382 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1383 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1384 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1385 sizeof(*req));
1386
1387 req->interface_hndl = phba->interface_handle;
1388 req->vlan_priority = vlan_tag;
1389
1390 be_mcc_notify(phba);
1391 spin_unlock(&ctrl->mbox_lock);
1392
1393 return tag;
1394}