blob: b77a327ecea946e7791d6927bea70c57e873a256 [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 Kallickal6733b392009-09-05 07:36:35 +053020#include "be.h"
21#include "be_mgmt.h"
22#include "be_main.h"
23
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
141 * @cmd_hdr: IOCTL Hdr for the MBX Cmd
142 *
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,
151 void *cmd_hdr)
152{
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;
157 struct be_cmd_req_hdr *ioctl_hdr;
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700158 struct be_cmd_resp_hdr *ioctl_resp_hdr;
John Soni Josee175def2012-10-20 04:45:40 +0530159 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
160
John Soni Jose7a158002012-10-20 04:45:51 +0530161 if (beiscsi_error(phba))
162 return -EIO;
163
John Soni Josee175def2012-10-20 04:45:40 +0530164 /* wait for the mccq completion */
165 rc = wait_event_interruptible_timeout(
166 phba->ctrl.mcc_wait[tag],
167 phba->ctrl.mcc_numtag[tag],
168 msecs_to_jiffies(
169 BEISCSI_HOST_MBX_TIMEOUT));
170
171 if (rc <= 0) {
172 beiscsi_log(phba, KERN_ERR,
173 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
174 BEISCSI_LOG_CONFIG,
175 "BC_%d : MBX Cmd Completion timed out\n");
176 rc = -EAGAIN;
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700177
178 /* decrement the mccq used count */
179 atomic_dec(&phba->ctrl.mcc_obj.q.used);
180
John Soni Josee175def2012-10-20 04:45:40 +0530181 goto release_mcc_tag;
182 } else
183 rc = 0;
184
185 mcc_tag_response = phba->ctrl.mcc_numtag[tag];
186 status = (mcc_tag_response & CQE_STATUS_MASK);
187 addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
188 CQE_STATUS_ADDL_SHIFT);
189
190 if (cmd_hdr) {
191 ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
192 } else {
193 wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
194 CQE_STATUS_WRB_SHIFT;
195 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
196 ioctl_hdr = embedded_payload(temp_wrb);
197
198 if (wrb)
199 *wrb = temp_wrb;
200 }
201
202 if (status || addl_status) {
203 beiscsi_log(phba, KERN_ERR,
204 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
205 BEISCSI_LOG_CONFIG,
206 "BC_%d : MBX Cmd Failed for "
207 "Subsys : %d Opcode : %d with "
208 "Status : %d and Extd_Status : %d\n",
209 ioctl_hdr->subsystem,
210 ioctl_hdr->opcode,
211 status, addl_status);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700212
213 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
214 ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
215 if (ioctl_resp_hdr->response_length)
216 goto release_mcc_tag;
217 }
John Soni Josee175def2012-10-20 04:45:40 +0530218 rc = -EAGAIN;
219 }
220
221release_mcc_tag:
222 /* Release the MCC entry */
223 free_mcc_tag(&phba->ctrl, tag);
224
225 return rc;
226}
227
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530228void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
229{
230 spin_lock(&ctrl->mbox_lock);
231 tag = tag & 0x000000FF;
232 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
233 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
234 ctrl->mcc_free_index = 0;
235 else
236 ctrl->mcc_free_index++;
237 ctrl->mcc_tag_available++;
238 spin_unlock(&ctrl->mbox_lock);
239}
240
241bool is_link_state_evt(u32 trailer)
242{
243 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
244 ASYNC_TRAILER_EVENT_CODE_MASK) ==
245 ASYNC_EVENT_CODE_LINK_STATE);
246}
247
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530248static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
249{
250 if (compl->flags != 0) {
251 compl->flags = le32_to_cpu(compl->flags);
252 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
253 return true;
254 } else
255 return false;
256}
257
258static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
259{
260 compl->flags = 0;
261}
262
John Soni Josee175def2012-10-20 04:45:40 +0530263/*
264 * be_mcc_compl_process()- Check the MBX comapletion status
265 * @ctrl: Function specific MBX data structure
266 * @compl: Completion status of MBX Command
267 *
268 * Check for the MBX completion status when BMBX method used
269 *
270 * return
271 * Success: Zero
272 * Failure: Non-Zero
273 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530274static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
275 struct be_mcc_compl *compl)
276{
277 u16 compl_status, extd_status;
John Soni Josee175def2012-10-20 04:45:40 +0530278 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530279 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
John Soni Josee175def2012-10-20 04:45:40 +0530280 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700281 struct be_cmd_resp_hdr *resp_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530282
283 be_dws_le_to_cpu(compl, 4);
284
285 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
286 CQE_STATUS_COMPL_MASK;
287 if (compl_status != MCC_STATUS_SUCCESS) {
288 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
289 CQE_STATUS_EXTD_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530290
291 beiscsi_log(phba, KERN_ERR,
292 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530293 "BC_%d : error in cmd completion: "
294 "Subsystem : %d Opcode : %d "
295 "status(compl/extd)=%d/%d\n",
296 hdr->subsystem, hdr->opcode,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530297 compl_status, extd_status);
298
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700299 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
300 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
301 if (resp_hdr->response_length)
302 return 0;
303 }
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530304 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530305 }
306 return 0;
307}
308
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530309int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
310 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530311{
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530312 u16 compl_status, extd_status;
313 unsigned short tag;
314
315 be_dws_le_to_cpu(compl, 4);
316
317 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
318 CQE_STATUS_COMPL_MASK;
319 /* The ctrl.mcc_numtag[tag] is filled with
320 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
321 * [7:0] = compl_status
322 */
323 tag = (compl->tag0 & 0x000000FF);
324 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
325 CQE_STATUS_EXTD_MASK;
326
327 ctrl->mcc_numtag[tag] = 0x80000000;
328 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
329 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
330 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
331 wake_up_interruptible(&ctrl->mcc_wait[tag]);
332 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530333}
334
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530335static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
336{
337 struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
338 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
339
340 if (be_mcc_compl_is_new(compl)) {
341 queue_tail_inc(mcc_cq);
342 return compl;
343 }
344 return NULL;
345}
346
347static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
348{
349 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
350}
351
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530352void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530353 struct be_async_event_link_state *evt)
354{
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700355 if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
356 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
357 (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
358 phba->state = BE_ADAPTER_LINK_DOWN;
359
John Soni Jose99bc5d52012-08-20 23:00:18 +0530360 beiscsi_log(phba, KERN_ERR,
361 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700362 "BC_%d : Link Down on Port %d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +0530363 evt->physical_port);
364
Jayamohan Kallickalda7408c2010-01-05 05:11:23 +0530365 iscsi_host_for_each_session(phba->shost,
366 be2iscsi_fail_session);
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700367 } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
368 ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
369 (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530370 phba->state = BE_ADAPTER_UP;
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700371
John Soni Jose99bc5d52012-08-20 23:00:18 +0530372 beiscsi_log(phba, KERN_ERR,
373 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
Jayamohan Kallickal6ea9b3b2013-04-05 20:38:30 -0700374 "BC_%d : Link UP on Port %d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +0530375 evt->physical_port);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530376 }
377}
378
379static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530380 u16 num_popped)
381{
382 u32 val = 0;
383 val |= qid & DB_CQ_RING_ID_MASK;
384 if (arm)
385 val |= 1 << DB_CQ_REARM_SHIFT;
386 val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530387 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
388}
389
390
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530391int beiscsi_process_mcc(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530392{
393 struct be_mcc_compl *compl;
394 int num = 0, status = 0;
395 struct be_ctrl_info *ctrl = &phba->ctrl;
396
397 spin_lock_bh(&phba->ctrl.mcc_cq_lock);
398 while ((compl = be_mcc_compl_get(phba))) {
399 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
400 /* Interpret flags as an async trailer */
Jayamohan Kallickal78b9fb62009-11-25 01:41:37 +0530401 if (is_link_state_evt(compl->flags))
402 /* Interpret compl as a async link evt */
403 beiscsi_async_link_state_process(phba,
404 (struct be_async_event_link_state *) compl);
405 else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530406 beiscsi_log(phba, KERN_ERR,
407 BEISCSI_LOG_CONFIG |
408 BEISCSI_LOG_MBOX,
409 "BC_%d : Unsupported Async Event, flags"
410 " = 0x%08x\n", compl->flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530411
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530412 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
413 status = be_mcc_compl_process(ctrl, compl);
414 atomic_dec(&phba->ctrl.mcc_obj.q.used);
415 }
416 be_mcc_compl_use(compl);
417 num++;
418 }
419
420 if (num)
421 beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
422
423 spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
424 return status;
425}
426
John Soni Josee175def2012-10-20 04:45:40 +0530427/*
428 * be_mcc_wait_compl()- Wait for MBX completion
429 * @phba: driver private structure
430 *
431 * Wait till no more pending mcc requests are present
432 *
433 * return
434 * Success: 0
435 * Failure: Non-Zero
436 *
437 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530438static int be_mcc_wait_compl(struct beiscsi_hba *phba)
439{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530440 int i, status;
441 for (i = 0; i < mcc_timeout; i++) {
John Soni Jose7a158002012-10-20 04:45:51 +0530442 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530443 return -EIO;
444
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530445 status = beiscsi_process_mcc(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530446 if (status)
447 return status;
448
449 if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
450 break;
451 udelay(100);
452 }
453 if (i == mcc_timeout) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530454 beiscsi_log(phba, KERN_ERR,
455 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530456 "BC_%d : FW Timed Out\n");
457 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530458 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530459 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530460 }
461 return 0;
462}
463
John Soni Josee175def2012-10-20 04:45:40 +0530464/*
465 * be_mcc_notify_wait()- Notify and wait for Compl
466 * @phba: driver private structure
467 *
468 * Notify MCC requests and wait for completion
469 *
470 * return
471 * Success: 0
472 * Failure: Non-Zero
473 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530474int be_mcc_notify_wait(struct beiscsi_hba *phba)
475{
476 be_mcc_notify(phba);
477 return be_mcc_wait_compl(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530478}
479
John Soni Josee175def2012-10-20 04:45:40 +0530480/*
481 * be_mbox_db_ready_wait()- Check ready status
482 * @ctrl: Function specific MBX data structure
483 *
484 * Check for the ready status of FW to send BMBX
485 * commands to adapter.
486 *
487 * return
488 * Success: 0
489 * Failure: Non-Zero
490 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530491static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
492{
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700493#define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530494 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530495 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700496 unsigned long timeout;
497 bool read_flag = false;
498 int ret = 0, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530499 u32 ready;
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700500 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q);
501
502 if (beiscsi_error(phba))
503 return -EIO;
504
505 timeout = jiffies + (HZ * 110);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530506
507 do {
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700508 for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) {
509 ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
510 if (ready) {
511 read_flag = true;
512 break;
513 }
514 mdelay(1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530515 }
516
Jayamohan Kallickal92665a62013-09-28 15:35:43 -0700517 if (!read_flag) {
518 wait_event_timeout(rdybit_check_q,
519 (read_flag != true),
520 HZ * 5);
521 }
522 } while ((time_before(jiffies, timeout)) && !read_flag);
523
524 if (!read_flag) {
525 beiscsi_log(phba, KERN_ERR,
526 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
527 "BC_%d : FW Timed Out\n");
528 phba->fw_timeout = true;
529 beiscsi_ue_detect(phba);
530 ret = -EBUSY;
531 }
532
533 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530534}
535
John Soni Josee175def2012-10-20 04:45:40 +0530536/*
537 * be_mbox_notify: Notify adapter of new BMBX command
538 * @ctrl: Function specific MBX data structure
539 *
540 * Ring doorbell to inform adapter of a BMBX command
541 * to process
542 *
543 * return
544 * Success: 0
545 * Failure: Non-Zero
546 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530547int be_mbox_notify(struct be_ctrl_info *ctrl)
548{
549 int status;
550 u32 val = 0;
551 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
552 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
553 struct be_mcc_mailbox *mbox = mbox_mem->va;
554 struct be_mcc_compl *compl = &mbox->compl;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530555 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530556
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700557 status = be_mbox_db_ready_wait(ctrl);
558 if (status)
559 return status;
560
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530561 val &= ~MPU_MAILBOX_DB_RDY_MASK;
562 val |= MPU_MAILBOX_DB_HI_MASK;
563 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
564 iowrite32(val, db);
565
566 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530567 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530568 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530569
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530570 val = 0;
571 val &= ~MPU_MAILBOX_DB_RDY_MASK;
572 val &= ~MPU_MAILBOX_DB_HI_MASK;
573 val |= (u32) (mbox_mem->dma >> 4) << 2;
574 iowrite32(val, db);
575
576 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530577 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530578 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530579
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530580 if (be_mcc_compl_is_new(compl)) {
581 status = be_mcc_compl_process(ctrl, &mbox->compl);
582 be_mcc_compl_use(compl);
583 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530584 beiscsi_log(phba, KERN_ERR,
585 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
586 "BC_%d : After be_mcc_compl_process\n");
587
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530588 return status;
589 }
590 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530591 beiscsi_log(phba, KERN_ERR,
592 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
593 "BC_%d : Invalid Mailbox Completion\n");
594
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530595 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530596 }
597 return 0;
598}
599
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530600/*
601 * Insert the mailbox address into the doorbell in two steps
602 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
603 */
604static int be_mbox_notify_wait(struct beiscsi_hba *phba)
605{
606 int status;
607 u32 val = 0;
608 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
609 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
610 struct be_mcc_mailbox *mbox = mbox_mem->va;
611 struct be_mcc_compl *compl = &mbox->compl;
612 struct be_ctrl_info *ctrl = &phba->ctrl;
613
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700614 status = be_mbox_db_ready_wait(ctrl);
615 if (status)
616 return status;
617
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530618 val |= MPU_MAILBOX_DB_HI_MASK;
619 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
620 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
621 iowrite32(val, db);
622
623 /* wait for ready to be set */
624 status = be_mbox_db_ready_wait(ctrl);
625 if (status != 0)
626 return status;
627
628 val = 0;
629 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
630 val |= (u32)(mbox_mem->dma >> 4) << 2;
631 iowrite32(val, db);
632
633 status = be_mbox_db_ready_wait(ctrl);
634 if (status != 0)
635 return status;
636
637 /* A cq entry has been made now */
638 if (be_mcc_compl_is_new(compl)) {
639 status = be_mcc_compl_process(ctrl, &mbox->compl);
640 be_mcc_compl_use(compl);
641 if (status)
642 return status;
643 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530644 beiscsi_log(phba, KERN_ERR,
645 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
646 "BC_%d : invalid mailbox completion\n");
647
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530648 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530649 }
650 return 0;
651}
652
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530653void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
654 bool embedded, u8 sge_cnt)
655{
656 if (embedded)
657 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
658 else
659 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
660 MCC_WRB_SGE_CNT_SHIFT;
661 wrb->payload_length = payload_len;
662 be_dws_cpu_to_le(wrb, 8);
663}
664
665void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
666 u8 subsystem, u8 opcode, int cmd_len)
667{
668 req_hdr->opcode = opcode;
669 req_hdr->subsystem = subsystem;
670 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530671 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530672}
673
674static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
675 struct be_dma_mem *mem)
676{
677 int i, buf_pages;
678 u64 dma = (u64) mem->dma;
679
680 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
681 for (i = 0; i < buf_pages; i++) {
682 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
683 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
684 dma += PAGE_SIZE_4K;
685 }
686}
687
688static u32 eq_delay_to_mult(u32 usec_delay)
689{
690#define MAX_INTR_RATE 651042
691 const u32 round = 10;
692 u32 multiplier;
693
694 if (usec_delay == 0)
695 multiplier = 0;
696 else {
697 u32 interrupt_rate = 1000000 / usec_delay;
698 if (interrupt_rate == 0)
699 multiplier = 1023;
700 else {
701 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
702 multiplier /= interrupt_rate;
703 multiplier = (multiplier + round / 2) / round;
704 multiplier = min(multiplier, (u32) 1023);
705 }
706 }
707 return multiplier;
708}
709
710struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
711{
712 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
713}
714
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530715struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
716{
717 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
718 struct be_mcc_wrb *wrb;
719
Jayamohan Kallickale074d202013-09-28 15:35:39 -0700720 WARN_ON(atomic_read(&mccq->used) >= mccq->len);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530721 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530722 memset(wrb, 0, sizeof(*wrb));
723 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530724 queue_head_inc(mccq);
725 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530726 return wrb;
727}
728
729
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530730int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
731 struct be_queue_info *eq, int eq_delay)
732{
733 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
734 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
735 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
736 struct be_dma_mem *q_mem = &eq->dma_mem;
737 int status;
738
739 spin_lock(&ctrl->mbox_lock);
740 memset(wrb, 0, sizeof(*wrb));
741
742 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
743
744 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
745 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
746
747 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
748
749 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
750 PCI_FUNC(ctrl->pdev->devfn));
751 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
752 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
753 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
754 __ilog2_u32(eq->len / 256));
755 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
756 eq_delay_to_mult(eq_delay));
757 be_dws_cpu_to_le(req->context, sizeof(req->context));
758
759 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
760
761 status = be_mbox_notify(ctrl);
762 if (!status) {
763 eq->id = le16_to_cpu(resp->eq_id);
764 eq->created = true;
765 }
766 spin_unlock(&ctrl->mbox_lock);
767 return status;
768}
769
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700770/**
771 * be_cmd_fw_initialize()- Initialize FW
772 * @ctrl: Pointer to function control structure
773 *
774 * Send FW initialize pattern for the function.
775 *
776 * return
777 * Success: 0
778 * Failure: Non-Zero value
779 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530780int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
781{
782 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530783 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530784 int status;
785 u8 *endian_check;
786
787 spin_lock(&ctrl->mbox_lock);
788 memset(wrb, 0, sizeof(*wrb));
789
790 endian_check = (u8 *) wrb;
791 *endian_check++ = 0xFF;
792 *endian_check++ = 0x12;
793 *endian_check++ = 0x34;
794 *endian_check++ = 0xFF;
795 *endian_check++ = 0xFF;
796 *endian_check++ = 0x56;
797 *endian_check++ = 0x78;
798 *endian_check++ = 0xFF;
799 be_dws_cpu_to_le(wrb, sizeof(*wrb));
800
801 status = be_mbox_notify(ctrl);
802 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530803 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
804 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530805
806 spin_unlock(&ctrl->mbox_lock);
807 return status;
808}
809
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700810/**
811 * be_cmd_fw_uninit()- Uinitialize FW
812 * @ctrl: Pointer to function control structure
813 *
814 * Send FW uninitialize pattern for the function
815 *
816 * return
817 * Success: 0
818 * Failure: Non-Zero value
819 **/
820int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
821{
822 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
823 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
824 int status;
825 u8 *endian_check;
826
827 spin_lock(&ctrl->mbox_lock);
828 memset(wrb, 0, sizeof(*wrb));
829
830 endian_check = (u8 *) wrb;
831 *endian_check++ = 0xFF;
832 *endian_check++ = 0xAA;
833 *endian_check++ = 0xBB;
834 *endian_check++ = 0xFF;
835 *endian_check++ = 0xFF;
836 *endian_check++ = 0xCC;
837 *endian_check++ = 0xDD;
838 *endian_check = 0xFF;
839
840 be_dws_cpu_to_le(wrb, sizeof(*wrb));
841
842 status = be_mbox_notify(ctrl);
843 if (status)
844 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
845 "BC_%d : be_cmd_fw_uninit Failed\n");
846
847 spin_unlock(&ctrl->mbox_lock);
848 return status;
849}
850
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530851int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
852 struct be_queue_info *cq, struct be_queue_info *eq,
853 bool sol_evts, bool no_delay, int coalesce_wm)
854{
855 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
856 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
857 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530858 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530859 struct be_dma_mem *q_mem = &cq->dma_mem;
860 void *ctxt = &req->context;
861 int status;
862
863 spin_lock(&ctrl->mbox_lock);
864 memset(wrb, 0, sizeof(*wrb));
865
866 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
867
868 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
869 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530870
871 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700872 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530873 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
874 ctxt, coalesce_wm);
875 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
876 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
877 __ilog2_u32(cq->len / 256));
878 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
879 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
880 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
881 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
882 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
883 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
884 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700885 } else {
886 req->hdr.version = MBX_CMD_VER2;
887 req->page_size = 1;
888 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
889 ctxt, coalesce_wm);
890 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
891 ctxt, no_delay);
892 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
893 __ilog2_u32(cq->len / 256));
894 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
895 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
896 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
897 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +0530898 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530899
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530900 be_dws_cpu_to_le(ctxt, sizeof(req->context));
901
902 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
903
904 status = be_mbox_notify(ctrl);
905 if (!status) {
906 cq->id = le16_to_cpu(resp->cq_id);
907 cq->created = true;
908 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530909 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
910 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
911 status);
912
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530913 spin_unlock(&ctrl->mbox_lock);
914
915 return status;
916}
917
918static u32 be_encoded_q_len(int q_len)
919{
920 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
921 if (len_encoded == 16)
922 len_encoded = 0;
923 return len_encoded;
924}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530925
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530926int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530927 struct be_queue_info *mccq,
928 struct be_queue_info *cq)
929{
930 struct be_mcc_wrb *wrb;
931 struct be_cmd_req_mcc_create *req;
932 struct be_dma_mem *q_mem = &mccq->dma_mem;
933 struct be_ctrl_info *ctrl;
934 void *ctxt;
935 int status;
936
937 spin_lock(&phba->ctrl.mbox_lock);
938 ctrl = &phba->ctrl;
939 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -0500940 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530941 req = embedded_payload(wrb);
942 ctxt = &req->context;
943
944 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
945
946 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
947 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
948
949 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
950
951 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
952 PCI_FUNC(phba->pcidev->devfn));
953 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
954 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
955 be_encoded_q_len(mccq->len));
956 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
957
958 be_dws_cpu_to_le(ctxt, sizeof(req->context));
959
960 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
961
962 status = be_mbox_notify_wait(phba);
963 if (!status) {
964 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
965 mccq->id = le16_to_cpu(resp->id);
966 mccq->created = true;
967 }
968 spin_unlock(&phba->ctrl.mbox_lock);
969
970 return status;
971}
972
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530973int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
974 int queue_type)
975{
976 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
977 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530978 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530979 u8 subsys = 0, opcode = 0;
980 int status;
981
John Soni Jose99bc5d52012-08-20 23:00:18 +0530982 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
983 "BC_%d : In beiscsi_cmd_q_destroy "
984 "queue_type : %d\n", queue_type);
985
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530986 spin_lock(&ctrl->mbox_lock);
987 memset(wrb, 0, sizeof(*wrb));
988 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
989
990 switch (queue_type) {
991 case QTYPE_EQ:
992 subsys = CMD_SUBSYSTEM_COMMON;
993 opcode = OPCODE_COMMON_EQ_DESTROY;
994 break;
995 case QTYPE_CQ:
996 subsys = CMD_SUBSYSTEM_COMMON;
997 opcode = OPCODE_COMMON_CQ_DESTROY;
998 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530999 case QTYPE_MCCQ:
1000 subsys = CMD_SUBSYSTEM_COMMON;
1001 opcode = OPCODE_COMMON_MCC_DESTROY;
1002 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301003 case QTYPE_WRBQ:
1004 subsys = CMD_SUBSYSTEM_ISCSI;
1005 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
1006 break;
1007 case QTYPE_DPDUQ:
1008 subsys = CMD_SUBSYSTEM_ISCSI;
1009 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
1010 break;
1011 case QTYPE_SGL:
1012 subsys = CMD_SUBSYSTEM_ISCSI;
1013 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1014 break;
1015 default:
1016 spin_unlock(&ctrl->mbox_lock);
1017 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301018 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301019 }
1020 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1021 if (queue_type != QTYPE_SGL)
1022 req->id = cpu_to_le16(q->id);
1023
1024 status = be_mbox_notify(ctrl);
1025
1026 spin_unlock(&ctrl->mbox_lock);
1027 return status;
1028}
1029
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001030/**
1031 * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
1032 * @ctrl: ptr to ctrl_info
1033 * @cq: Completion Queue
1034 * @dq: Default Queue
1035 * @lenght: ring size
1036 * @entry_size: size of each entry in DEFQ
1037 * @is_header: Header or Data DEFQ
1038 * @ulp_num: Bind to which ULP
1039 *
1040 * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
1041 * on this queue by the FW
1042 *
1043 * return
1044 * Success: 0
1045 * Failure: Non-Zero Value
1046 *
1047 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301048int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1049 struct be_queue_info *cq,
1050 struct be_queue_info *dq, int length,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001051 int entry_size, uint8_t is_header,
1052 uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301053{
1054 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1055 struct be_defq_create_req *req = embedded_payload(wrb);
1056 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001057 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301058 void *ctxt = &req->context;
1059 int status;
1060
1061 spin_lock(&ctrl->mbox_lock);
1062 memset(wrb, 0, sizeof(*wrb));
1063
1064 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1065
1066 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1067 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1068
1069 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001070 if (phba->fw_config.dual_ulp_aware) {
1071 req->ulp_num = ulp_num;
1072 req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
1073 req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
1074 }
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001075
1076 if (is_chip_be2_be3r(phba)) {
1077 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1078 rx_pdid, ctxt, 0);
1079 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1080 rx_pdid_valid, ctxt, 1);
1081 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1082 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1083 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1084 ring_size, ctxt,
1085 be_encoded_q_len(length /
1086 sizeof(struct phys_addr)));
1087 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1088 default_buffer_size, ctxt, entry_size);
1089 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1090 cq_id_recv, ctxt, cq->id);
1091 } else {
1092 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1093 rx_pdid, ctxt, 0);
1094 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1095 rx_pdid_valid, ctxt, 1);
1096 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1097 ring_size, ctxt,
1098 be_encoded_q_len(length /
1099 sizeof(struct phys_addr)));
1100 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1101 default_buffer_size, ctxt, entry_size);
1102 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1103 cq_id_recv, ctxt, cq->id);
1104 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301105
1106 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1107
1108 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1109
1110 status = be_mbox_notify(ctrl);
1111 if (!status) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001112 struct be_ring *defq_ring;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301113 struct be_defq_create_resp *resp = embedded_payload(wrb);
1114
1115 dq->id = le16_to_cpu(resp->id);
1116 dq->created = true;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001117 if (is_header)
1118 defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
1119 else
1120 defq_ring = &phba->phwi_ctrlr->
1121 default_pdu_data[ulp_num];
1122
1123 defq_ring->id = dq->id;
1124
1125 if (!phba->fw_config.dual_ulp_aware) {
1126 defq_ring->ulp_num = BEISCSI_ULP0;
1127 defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
1128 } else {
1129 defq_ring->ulp_num = resp->ulp_num;
1130 defq_ring->doorbell_offset = resp->doorbell_offset;
1131 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301132 }
1133 spin_unlock(&ctrl->mbox_lock);
1134
1135 return status;
1136}
1137
1138int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
1139 struct be_queue_info *wrbq)
1140{
1141 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1142 struct be_wrbq_create_req *req = embedded_payload(wrb);
1143 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
1144 int status;
1145
1146 spin_lock(&ctrl->mbox_lock);
1147 memset(wrb, 0, sizeof(*wrb));
1148
1149 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1150
1151 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1152 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1153 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1154 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1155
1156 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301157 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301158 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301159 wrbq->created = true;
1160 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301161 spin_unlock(&ctrl->mbox_lock);
1162 return status;
1163}
1164
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07001165int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
1166 struct be_dma_mem *q_mem)
1167{
1168 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1169 struct be_post_template_pages_req *req = embedded_payload(wrb);
1170 int status;
1171
1172 spin_lock(&ctrl->mbox_lock);
1173
1174 memset(wrb, 0, sizeof(*wrb));
1175 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1176 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1177 OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
1178 sizeof(*req));
1179
1180 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1181 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1182 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1183
1184 status = be_mbox_notify(ctrl);
1185 spin_unlock(&ctrl->mbox_lock);
1186 return status;
1187}
1188
1189int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
1190{
1191 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1192 struct be_remove_template_pages_req *req = embedded_payload(wrb);
1193 int status;
1194
1195 spin_lock(&ctrl->mbox_lock);
1196
1197 memset(wrb, 0, sizeof(*wrb));
1198 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1199 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1200 OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
1201 sizeof(*req));
1202
1203 req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
1204
1205 status = be_mbox_notify(ctrl);
1206 spin_unlock(&ctrl->mbox_lock);
1207 return status;
1208}
1209
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301210int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1211 struct be_dma_mem *q_mem,
1212 u32 page_offset, u32 num_pages)
1213{
1214 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1215 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301216 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301217 int status;
1218 unsigned int curr_pages;
1219 u32 internal_page_offset = 0;
1220 u32 temp_num_pages = num_pages;
1221
1222 if (num_pages == 0xff)
1223 num_pages = 1;
1224
1225 spin_lock(&ctrl->mbox_lock);
1226 do {
1227 memset(wrb, 0, sizeof(*wrb));
1228 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1229 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1230 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1231 sizeof(*req));
1232 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1233 pages);
1234 req->num_pages = min(num_pages, curr_pages);
1235 req->page_offset = page_offset;
1236 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1237 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1238 internal_page_offset += req->num_pages;
1239 page_offset += req->num_pages;
1240 num_pages -= req->num_pages;
1241
1242 if (temp_num_pages == 0xff)
1243 req->num_pages = temp_num_pages;
1244
1245 status = be_mbox_notify(ctrl);
1246 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301247 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1248 "BC_%d : FW CMD to map iscsi frags failed.\n");
1249
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301250 goto error;
1251 }
1252 } while (num_pages > 0);
1253error:
1254 spin_unlock(&ctrl->mbox_lock);
1255 if (status != 0)
1256 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1257 return status;
1258}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001259
1260int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1261{
1262 struct be_ctrl_info *ctrl = &phba->ctrl;
1263 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1264 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1265 int status;
1266
1267 spin_lock(&ctrl->mbox_lock);
1268
1269 req = embedded_payload(wrb);
1270 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1271 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1272 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1273 status = be_mbox_notify_wait(phba);
1274
1275 spin_unlock(&ctrl->mbox_lock);
1276 return status;
1277}
John Soni Jose6f722382012-08-20 23:00:43 +05301278
1279/**
1280 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1281 * @phba: device priv structure instance
1282 * @vlan_tag: TAG to be set
1283 *
1284 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1285 *
1286 * returns
1287 * TAG for the MBX Cmd
1288 * **/
1289int be_cmd_set_vlan(struct beiscsi_hba *phba,
1290 uint16_t vlan_tag)
1291{
1292 unsigned int tag = 0;
1293 struct be_mcc_wrb *wrb;
1294 struct be_cmd_set_vlan_req *req;
1295 struct be_ctrl_info *ctrl = &phba->ctrl;
1296
1297 spin_lock(&ctrl->mbox_lock);
1298 tag = alloc_mcc_tag(phba);
1299 if (!tag) {
1300 spin_unlock(&ctrl->mbox_lock);
1301 return tag;
1302 }
1303
1304 wrb = wrb_from_mccq(phba);
1305 req = embedded_payload(wrb);
1306 wrb->tag0 |= tag;
1307 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1308 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1309 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1310 sizeof(*req));
1311
1312 req->interface_hndl = phba->interface_handle;
1313 req->vlan_priority = vlan_tag;
1314
1315 be_mcc_notify(phba);
1316 spin_unlock(&ctrl->mbox_lock);
1317
1318 return tag;
1319}