blob: 4f3c93a11c501722d77f490c86a1caf2cf6cf48f [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
John Soni Jose5faf17b2012-10-20 04:45:27 +05302 * Copyright (C) 2005 - 2012 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;
177 goto release_mcc_tag;
178 } else
179 rc = 0;
180
181 mcc_tag_response = phba->ctrl.mcc_numtag[tag];
182 status = (mcc_tag_response & CQE_STATUS_MASK);
183 addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
184 CQE_STATUS_ADDL_SHIFT);
185
186 if (cmd_hdr) {
187 ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
188 } else {
189 wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
190 CQE_STATUS_WRB_SHIFT;
191 temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
192 ioctl_hdr = embedded_payload(temp_wrb);
193
194 if (wrb)
195 *wrb = temp_wrb;
196 }
197
198 if (status || addl_status) {
199 beiscsi_log(phba, KERN_ERR,
200 BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
201 BEISCSI_LOG_CONFIG,
202 "BC_%d : MBX Cmd Failed for "
203 "Subsys : %d Opcode : %d with "
204 "Status : %d and Extd_Status : %d\n",
205 ioctl_hdr->subsystem,
206 ioctl_hdr->opcode,
207 status, addl_status);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700208
209 if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
210 ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
211 if (ioctl_resp_hdr->response_length)
212 goto release_mcc_tag;
213 }
John Soni Josee175def2012-10-20 04:45:40 +0530214 rc = -EAGAIN;
215 }
216
217release_mcc_tag:
218 /* Release the MCC entry */
219 free_mcc_tag(&phba->ctrl, tag);
220
221 return rc;
222}
223
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530224void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
225{
226 spin_lock(&ctrl->mbox_lock);
227 tag = tag & 0x000000FF;
228 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
229 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
230 ctrl->mcc_free_index = 0;
231 else
232 ctrl->mcc_free_index++;
233 ctrl->mcc_tag_available++;
234 spin_unlock(&ctrl->mbox_lock);
235}
236
237bool is_link_state_evt(u32 trailer)
238{
239 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
240 ASYNC_TRAILER_EVENT_CODE_MASK) ==
241 ASYNC_EVENT_CODE_LINK_STATE);
242}
243
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530244static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
245{
246 if (compl->flags != 0) {
247 compl->flags = le32_to_cpu(compl->flags);
248 WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
249 return true;
250 } else
251 return false;
252}
253
254static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
255{
256 compl->flags = 0;
257}
258
John Soni Josee175def2012-10-20 04:45:40 +0530259/*
260 * be_mcc_compl_process()- Check the MBX comapletion status
261 * @ctrl: Function specific MBX data structure
262 * @compl: Completion status of MBX Command
263 *
264 * Check for the MBX completion status when BMBX method used
265 *
266 * return
267 * Success: Zero
268 * Failure: Non-Zero
269 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530270static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
271 struct be_mcc_compl *compl)
272{
273 u16 compl_status, extd_status;
John Soni Josee175def2012-10-20 04:45:40 +0530274 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530275 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
John Soni Josee175def2012-10-20 04:45:40 +0530276 struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700277 struct be_cmd_resp_hdr *resp_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530278
279 be_dws_le_to_cpu(compl, 4);
280
281 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
282 CQE_STATUS_COMPL_MASK;
283 if (compl_status != MCC_STATUS_SUCCESS) {
284 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
285 CQE_STATUS_EXTD_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530286
287 beiscsi_log(phba, KERN_ERR,
288 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530289 "BC_%d : error in cmd completion: "
290 "Subsystem : %d Opcode : %d "
291 "status(compl/extd)=%d/%d\n",
292 hdr->subsystem, hdr->opcode,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530293 compl_status, extd_status);
294
Jayamohan Kallickala8081e32013-04-05 20:38:22 -0700295 if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
296 resp_hdr = (struct be_cmd_resp_hdr *) hdr;
297 if (resp_hdr->response_length)
298 return 0;
299 }
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530300 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530301 }
302 return 0;
303}
304
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530305int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
306 struct be_mcc_compl *compl)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530307{
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530308 u16 compl_status, extd_status;
309 unsigned short tag;
310
311 be_dws_le_to_cpu(compl, 4);
312
313 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
314 CQE_STATUS_COMPL_MASK;
315 /* The ctrl.mcc_numtag[tag] is filled with
316 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
317 * [7:0] = compl_status
318 */
319 tag = (compl->tag0 & 0x000000FF);
320 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
321 CQE_STATUS_EXTD_MASK;
322
323 ctrl->mcc_numtag[tag] = 0x80000000;
324 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
325 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
326 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
327 wake_up_interruptible(&ctrl->mcc_wait[tag]);
328 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530329}
330
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530331static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
332{
333 struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
334 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
335
336 if (be_mcc_compl_is_new(compl)) {
337 queue_tail_inc(mcc_cq);
338 return compl;
339 }
340 return NULL;
341}
342
343static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
344{
345 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
346}
347
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530348void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530349 struct be_async_event_link_state *evt)
350{
351 switch (evt->port_link_status) {
352 case ASYNC_EVENT_LINK_DOWN:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530353 beiscsi_log(phba, KERN_ERR,
354 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
355 "BC_%d : Link Down on Physical Port %d\n",
356 evt->physical_port);
357
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530358 phba->state |= BE_ADAPTER_LINK_DOWN;
Jayamohan Kallickalda7408c2010-01-05 05:11:23 +0530359 iscsi_host_for_each_session(phba->shost,
360 be2iscsi_fail_session);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530361 break;
362 case ASYNC_EVENT_LINK_UP:
363 phba->state = BE_ADAPTER_UP;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530364 beiscsi_log(phba, KERN_ERR,
365 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
366 "BC_%d : Link UP on Physical Port %d\n",
367 evt->physical_port);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530368 break;
369 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530370 beiscsi_log(phba, KERN_ERR,
371 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
372 "BC_%d : Unexpected Async Notification %d on"
373 "Physical Port %d\n",
374 evt->port_link_status,
375 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 Kallickal6733b392009-09-05 07:36:35 +0530493 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
John Soni Josee175def2012-10-20 04:45:40 +0530494 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700495 uint32_t wait = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530496 u32 ready;
497
498 do {
John Soni Jose7a158002012-10-20 04:45:51 +0530499
500 if (beiscsi_error(phba))
John Soni Josee175def2012-10-20 04:45:40 +0530501 return -EIO;
502
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530503 ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
504 if (ready)
505 break;
506
John Soni Josee175def2012-10-20 04:45:40 +0530507 if (wait > BEISCSI_HOST_MBX_TIMEOUT) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530508 beiscsi_log(phba, KERN_ERR,
509 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530510 "BC_%d : FW Timed Out\n");
511 phba->fw_timeout = true;
John Soni Jose7a158002012-10-20 04:45:51 +0530512 beiscsi_ue_detect(phba);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530513 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530514 }
515
John Soni Josee175def2012-10-20 04:45:40 +0530516 mdelay(1);
517 wait++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530518 } while (true);
519 return 0;
520}
521
John Soni Josee175def2012-10-20 04:45:40 +0530522/*
523 * be_mbox_notify: Notify adapter of new BMBX command
524 * @ctrl: Function specific MBX data structure
525 *
526 * Ring doorbell to inform adapter of a BMBX command
527 * to process
528 *
529 * return
530 * Success: 0
531 * Failure: Non-Zero
532 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530533int be_mbox_notify(struct be_ctrl_info *ctrl)
534{
535 int status;
536 u32 val = 0;
537 void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
538 struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
539 struct be_mcc_mailbox *mbox = mbox_mem->va;
540 struct be_mcc_compl *compl = &mbox->compl;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530541 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530542
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700543 status = be_mbox_db_ready_wait(ctrl);
544 if (status)
545 return status;
546
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530547 val &= ~MPU_MAILBOX_DB_RDY_MASK;
548 val |= MPU_MAILBOX_DB_HI_MASK;
549 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
550 iowrite32(val, db);
551
552 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530553 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530554 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530555
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530556 val = 0;
557 val &= ~MPU_MAILBOX_DB_RDY_MASK;
558 val &= ~MPU_MAILBOX_DB_HI_MASK;
559 val |= (u32) (mbox_mem->dma >> 4) << 2;
560 iowrite32(val, db);
561
562 status = be_mbox_db_ready_wait(ctrl);
John Soni Josee175def2012-10-20 04:45:40 +0530563 if (status)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530564 return status;
John Soni Josee175def2012-10-20 04:45:40 +0530565
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530566 if (be_mcc_compl_is_new(compl)) {
567 status = be_mcc_compl_process(ctrl, &mbox->compl);
568 be_mcc_compl_use(compl);
569 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530570 beiscsi_log(phba, KERN_ERR,
571 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
572 "BC_%d : After be_mcc_compl_process\n");
573
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530574 return status;
575 }
576 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530577 beiscsi_log(phba, KERN_ERR,
578 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
579 "BC_%d : Invalid Mailbox Completion\n");
580
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530581 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530582 }
583 return 0;
584}
585
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530586/*
587 * Insert the mailbox address into the doorbell in two steps
588 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
589 */
590static int be_mbox_notify_wait(struct beiscsi_hba *phba)
591{
592 int status;
593 u32 val = 0;
594 void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
595 struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
596 struct be_mcc_mailbox *mbox = mbox_mem->va;
597 struct be_mcc_compl *compl = &mbox->compl;
598 struct be_ctrl_info *ctrl = &phba->ctrl;
599
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -0700600 status = be_mbox_db_ready_wait(ctrl);
601 if (status)
602 return status;
603
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530604 val |= MPU_MAILBOX_DB_HI_MASK;
605 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
606 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
607 iowrite32(val, db);
608
609 /* wait for ready to be set */
610 status = be_mbox_db_ready_wait(ctrl);
611 if (status != 0)
612 return status;
613
614 val = 0;
615 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
616 val |= (u32)(mbox_mem->dma >> 4) << 2;
617 iowrite32(val, db);
618
619 status = be_mbox_db_ready_wait(ctrl);
620 if (status != 0)
621 return status;
622
623 /* A cq entry has been made now */
624 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)
628 return status;
629 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530630 beiscsi_log(phba, KERN_ERR,
631 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
632 "BC_%d : invalid mailbox completion\n");
633
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530634 return -EBUSY;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530635 }
636 return 0;
637}
638
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530639void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
640 bool embedded, u8 sge_cnt)
641{
642 if (embedded)
643 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
644 else
645 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
646 MCC_WRB_SGE_CNT_SHIFT;
647 wrb->payload_length = payload_len;
648 be_dws_cpu_to_le(wrb, 8);
649}
650
651void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
652 u8 subsystem, u8 opcode, int cmd_len)
653{
654 req_hdr->opcode = opcode;
655 req_hdr->subsystem = subsystem;
656 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
John Soni Josee175def2012-10-20 04:45:40 +0530657 req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530658}
659
660static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
661 struct be_dma_mem *mem)
662{
663 int i, buf_pages;
664 u64 dma = (u64) mem->dma;
665
666 buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
667 for (i = 0; i < buf_pages; i++) {
668 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
669 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
670 dma += PAGE_SIZE_4K;
671 }
672}
673
674static u32 eq_delay_to_mult(u32 usec_delay)
675{
676#define MAX_INTR_RATE 651042
677 const u32 round = 10;
678 u32 multiplier;
679
680 if (usec_delay == 0)
681 multiplier = 0;
682 else {
683 u32 interrupt_rate = 1000000 / usec_delay;
684 if (interrupt_rate == 0)
685 multiplier = 1023;
686 else {
687 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
688 multiplier /= interrupt_rate;
689 multiplier = (multiplier + round / 2) / round;
690 multiplier = min(multiplier, (u32) 1023);
691 }
692 }
693 return multiplier;
694}
695
696struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
697{
698 return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
699}
700
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530701struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
702{
703 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
704 struct be_mcc_wrb *wrb;
705
706 BUG_ON(atomic_read(&mccq->used) >= mccq->len);
707 wrb = queue_head_node(mccq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530708 memset(wrb, 0, sizeof(*wrb));
709 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530710 queue_head_inc(mccq);
711 atomic_inc(&mccq->used);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530712 return wrb;
713}
714
715
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530716int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
717 struct be_queue_info *eq, int eq_delay)
718{
719 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
720 struct be_cmd_req_eq_create *req = embedded_payload(wrb);
721 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
722 struct be_dma_mem *q_mem = &eq->dma_mem;
723 int status;
724
725 spin_lock(&ctrl->mbox_lock);
726 memset(wrb, 0, sizeof(*wrb));
727
728 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
729
730 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
731 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
732
733 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
734
735 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
736 PCI_FUNC(ctrl->pdev->devfn));
737 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
738 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
739 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
740 __ilog2_u32(eq->len / 256));
741 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
742 eq_delay_to_mult(eq_delay));
743 be_dws_cpu_to_le(req->context, sizeof(req->context));
744
745 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
746
747 status = be_mbox_notify(ctrl);
748 if (!status) {
749 eq->id = le16_to_cpu(resp->eq_id);
750 eq->created = true;
751 }
752 spin_unlock(&ctrl->mbox_lock);
753 return status;
754}
755
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700756/**
757 * be_cmd_fw_initialize()- Initialize FW
758 * @ctrl: Pointer to function control structure
759 *
760 * Send FW initialize pattern for the function.
761 *
762 * return
763 * Success: 0
764 * Failure: Non-Zero value
765 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530766int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
767{
768 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530769 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530770 int status;
771 u8 *endian_check;
772
773 spin_lock(&ctrl->mbox_lock);
774 memset(wrb, 0, sizeof(*wrb));
775
776 endian_check = (u8 *) wrb;
777 *endian_check++ = 0xFF;
778 *endian_check++ = 0x12;
779 *endian_check++ = 0x34;
780 *endian_check++ = 0xFF;
781 *endian_check++ = 0xFF;
782 *endian_check++ = 0x56;
783 *endian_check++ = 0x78;
784 *endian_check++ = 0xFF;
785 be_dws_cpu_to_le(wrb, sizeof(*wrb));
786
787 status = be_mbox_notify(ctrl);
788 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530789 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
790 "BC_%d : be_cmd_fw_initialize Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530791
792 spin_unlock(&ctrl->mbox_lock);
793 return status;
794}
795
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -0700796/**
797 * be_cmd_fw_uninit()- Uinitialize FW
798 * @ctrl: Pointer to function control structure
799 *
800 * Send FW uninitialize pattern for the function
801 *
802 * return
803 * Success: 0
804 * Failure: Non-Zero value
805 **/
806int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
807{
808 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
809 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
810 int status;
811 u8 *endian_check;
812
813 spin_lock(&ctrl->mbox_lock);
814 memset(wrb, 0, sizeof(*wrb));
815
816 endian_check = (u8 *) wrb;
817 *endian_check++ = 0xFF;
818 *endian_check++ = 0xAA;
819 *endian_check++ = 0xBB;
820 *endian_check++ = 0xFF;
821 *endian_check++ = 0xFF;
822 *endian_check++ = 0xCC;
823 *endian_check++ = 0xDD;
824 *endian_check = 0xFF;
825
826 be_dws_cpu_to_le(wrb, sizeof(*wrb));
827
828 status = be_mbox_notify(ctrl);
829 if (status)
830 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
831 "BC_%d : be_cmd_fw_uninit Failed\n");
832
833 spin_unlock(&ctrl->mbox_lock);
834 return status;
835}
836
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530837int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
838 struct be_queue_info *cq, struct be_queue_info *eq,
839 bool sol_evts, bool no_delay, int coalesce_wm)
840{
841 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
842 struct be_cmd_req_cq_create *req = embedded_payload(wrb);
843 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530844 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530845 struct be_dma_mem *q_mem = &cq->dma_mem;
846 void *ctxt = &req->context;
847 int status;
848
849 spin_lock(&ctrl->mbox_lock);
850 memset(wrb, 0, sizeof(*wrb));
851
852 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
853
854 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
855 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530856
857 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700858 if (is_chip_be2_be3r(phba)) {
John Soni Joseeaae5262012-10-20 04:43:44 +0530859 AMAP_SET_BITS(struct amap_cq_context, coalescwm,
860 ctxt, coalesce_wm);
861 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
862 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
863 __ilog2_u32(cq->len / 256));
864 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
865 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
866 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
867 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
868 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
869 AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
870 PCI_FUNC(ctrl->pdev->devfn));
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700871 } else {
872 req->hdr.version = MBX_CMD_VER2;
873 req->page_size = 1;
874 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
875 ctxt, coalesce_wm);
876 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
877 ctxt, no_delay);
878 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
879 __ilog2_u32(cq->len / 256));
880 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
881 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
882 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
883 AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
John Soni Joseeaae5262012-10-20 04:43:44 +0530884 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530885
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530886 be_dws_cpu_to_le(ctxt, sizeof(req->context));
887
888 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
889
890 status = be_mbox_notify(ctrl);
891 if (!status) {
892 cq->id = le16_to_cpu(resp->cq_id);
893 cq->created = true;
894 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530895 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
896 "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
897 status);
898
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530899 spin_unlock(&ctrl->mbox_lock);
900
901 return status;
902}
903
904static u32 be_encoded_q_len(int q_len)
905{
906 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
907 if (len_encoded == 16)
908 len_encoded = 0;
909 return len_encoded;
910}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530911
Jayamohan Kallickal35e66012009-10-23 11:53:49 +0530912int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530913 struct be_queue_info *mccq,
914 struct be_queue_info *cq)
915{
916 struct be_mcc_wrb *wrb;
917 struct be_cmd_req_mcc_create *req;
918 struct be_dma_mem *q_mem = &mccq->dma_mem;
919 struct be_ctrl_info *ctrl;
920 void *ctxt;
921 int status;
922
923 spin_lock(&phba->ctrl.mbox_lock);
924 ctrl = &phba->ctrl;
925 wrb = wrb_from_mbox(&ctrl->mbox_mem);
Jayamohan Kallickal37609762011-10-07 19:31:11 -0500926 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530927 req = embedded_payload(wrb);
928 ctxt = &req->context;
929
930 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
931
932 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
933 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
934
935 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
936
937 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
938 PCI_FUNC(phba->pcidev->devfn));
939 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
940 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
941 be_encoded_q_len(mccq->len));
942 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
943
944 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_wait(phba);
949 if (!status) {
950 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
951 mccq->id = le16_to_cpu(resp->id);
952 mccq->created = true;
953 }
954 spin_unlock(&phba->ctrl.mbox_lock);
955
956 return status;
957}
958
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530959int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
960 int queue_type)
961{
962 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
963 struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530964 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530965 u8 subsys = 0, opcode = 0;
966 int status;
967
John Soni Jose99bc5d52012-08-20 23:00:18 +0530968 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
969 "BC_%d : In beiscsi_cmd_q_destroy "
970 "queue_type : %d\n", queue_type);
971
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530972 spin_lock(&ctrl->mbox_lock);
973 memset(wrb, 0, sizeof(*wrb));
974 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
975
976 switch (queue_type) {
977 case QTYPE_EQ:
978 subsys = CMD_SUBSYSTEM_COMMON;
979 opcode = OPCODE_COMMON_EQ_DESTROY;
980 break;
981 case QTYPE_CQ:
982 subsys = CMD_SUBSYSTEM_COMMON;
983 opcode = OPCODE_COMMON_CQ_DESTROY;
984 break;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530985 case QTYPE_MCCQ:
986 subsys = CMD_SUBSYSTEM_COMMON;
987 opcode = OPCODE_COMMON_MCC_DESTROY;
988 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530989 case QTYPE_WRBQ:
990 subsys = CMD_SUBSYSTEM_ISCSI;
991 opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
992 break;
993 case QTYPE_DPDUQ:
994 subsys = CMD_SUBSYSTEM_ISCSI;
995 opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
996 break;
997 case QTYPE_SGL:
998 subsys = CMD_SUBSYSTEM_ISCSI;
999 opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
1000 break;
1001 default:
1002 spin_unlock(&ctrl->mbox_lock);
1003 BUG();
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301004 return -ENXIO;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301005 }
1006 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1007 if (queue_type != QTYPE_SGL)
1008 req->id = cpu_to_le16(q->id);
1009
1010 status = be_mbox_notify(ctrl);
1011
1012 spin_unlock(&ctrl->mbox_lock);
1013 return status;
1014}
1015
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301016int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
1017 struct be_queue_info *cq,
1018 struct be_queue_info *dq, int length,
1019 int entry_size)
1020{
1021 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1022 struct be_defq_create_req *req = embedded_payload(wrb);
1023 struct be_dma_mem *q_mem = &dq->dma_mem;
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001024 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301025 void *ctxt = &req->context;
1026 int status;
1027
1028 spin_lock(&ctrl->mbox_lock);
1029 memset(wrb, 0, sizeof(*wrb));
1030
1031 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1032
1033 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1034 OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
1035
1036 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
Jayamohan Kallickalef9e1b92013-04-05 20:38:27 -07001037
1038 if (is_chip_be2_be3r(phba)) {
1039 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1040 rx_pdid, ctxt, 0);
1041 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1042 rx_pdid_valid, ctxt, 1);
1043 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1044 pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
1045 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1046 ring_size, ctxt,
1047 be_encoded_q_len(length /
1048 sizeof(struct phys_addr)));
1049 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1050 default_buffer_size, ctxt, entry_size);
1051 AMAP_SET_BITS(struct amap_be_default_pdu_context,
1052 cq_id_recv, ctxt, cq->id);
1053 } else {
1054 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1055 rx_pdid, ctxt, 0);
1056 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1057 rx_pdid_valid, ctxt, 1);
1058 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1059 ring_size, ctxt,
1060 be_encoded_q_len(length /
1061 sizeof(struct phys_addr)));
1062 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1063 default_buffer_size, ctxt, entry_size);
1064 AMAP_SET_BITS(struct amap_default_pdu_context_ext,
1065 cq_id_recv, ctxt, cq->id);
1066 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301067
1068 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1069
1070 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1071
1072 status = be_mbox_notify(ctrl);
1073 if (!status) {
1074 struct be_defq_create_resp *resp = embedded_payload(wrb);
1075
1076 dq->id = le16_to_cpu(resp->id);
1077 dq->created = true;
1078 }
1079 spin_unlock(&ctrl->mbox_lock);
1080
1081 return status;
1082}
1083
1084int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
1085 struct be_queue_info *wrbq)
1086{
1087 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1088 struct be_wrbq_create_req *req = embedded_payload(wrb);
1089 struct be_wrbq_create_resp *resp = embedded_payload(wrb);
1090 int status;
1091
1092 spin_lock(&ctrl->mbox_lock);
1093 memset(wrb, 0, sizeof(*wrb));
1094
1095 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1096
1097 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1098 OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
1099 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1100 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1101
1102 status = be_mbox_notify(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301103 if (!status) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301104 wrbq->id = le16_to_cpu(resp->cid);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301105 wrbq->created = true;
1106 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301107 spin_unlock(&ctrl->mbox_lock);
1108 return status;
1109}
1110
1111int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
1112 struct be_dma_mem *q_mem,
1113 u32 page_offset, u32 num_pages)
1114{
1115 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1116 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301117 struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301118 int status;
1119 unsigned int curr_pages;
1120 u32 internal_page_offset = 0;
1121 u32 temp_num_pages = num_pages;
1122
1123 if (num_pages == 0xff)
1124 num_pages = 1;
1125
1126 spin_lock(&ctrl->mbox_lock);
1127 do {
1128 memset(wrb, 0, sizeof(*wrb));
1129 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1130 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1131 OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
1132 sizeof(*req));
1133 curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
1134 pages);
1135 req->num_pages = min(num_pages, curr_pages);
1136 req->page_offset = page_offset;
1137 be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
1138 q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
1139 internal_page_offset += req->num_pages;
1140 page_offset += req->num_pages;
1141 num_pages -= req->num_pages;
1142
1143 if (temp_num_pages == 0xff)
1144 req->num_pages = temp_num_pages;
1145
1146 status = be_mbox_notify(ctrl);
1147 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301148 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1149 "BC_%d : FW CMD to map iscsi frags failed.\n");
1150
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301151 goto error;
1152 }
1153 } while (num_pages > 0);
1154error:
1155 spin_unlock(&ctrl->mbox_lock);
1156 if (status != 0)
1157 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
1158 return status;
1159}
Jayamohan Kallickale5285862011-10-07 19:31:08 -05001160
1161int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
1162{
1163 struct be_ctrl_info *ctrl = &phba->ctrl;
1164 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1165 struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1166 int status;
1167
1168 spin_lock(&ctrl->mbox_lock);
1169
1170 req = embedded_payload(wrb);
1171 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1172 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1173 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1174 status = be_mbox_notify_wait(phba);
1175
1176 spin_unlock(&ctrl->mbox_lock);
1177 return status;
1178}
John Soni Jose6f722382012-08-20 23:00:43 +05301179
1180/**
1181 * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
1182 * @phba: device priv structure instance
1183 * @vlan_tag: TAG to be set
1184 *
1185 * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
1186 *
1187 * returns
1188 * TAG for the MBX Cmd
1189 * **/
1190int be_cmd_set_vlan(struct beiscsi_hba *phba,
1191 uint16_t vlan_tag)
1192{
1193 unsigned int tag = 0;
1194 struct be_mcc_wrb *wrb;
1195 struct be_cmd_set_vlan_req *req;
1196 struct be_ctrl_info *ctrl = &phba->ctrl;
1197
1198 spin_lock(&ctrl->mbox_lock);
1199 tag = alloc_mcc_tag(phba);
1200 if (!tag) {
1201 spin_unlock(&ctrl->mbox_lock);
1202 return tag;
1203 }
1204
1205 wrb = wrb_from_mccq(phba);
1206 req = embedded_payload(wrb);
1207 wrb->tag0 |= tag;
1208 be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
1209 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1210 OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
1211 sizeof(*req));
1212
1213 req->interface_hndl = phba->interface_handle;
1214 req->vlan_priority = vlan_tag;
1215
1216 be_mcc_notify(phba);
1217 spin_unlock(&ctrl->mbox_lock);
1218
1219 return tag;
1220}