]>
Commit | Line | Data |
---|---|---|
6733b39a | 1 | /** |
5faf17b4 | 2 | * Copyright (C) 2005 - 2012 Emulex |
6733b39a JK |
3 | * 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: | |
255fa9a3 | 11 | * linux-drivers@emulex.com |
6733b39a | 12 | * |
255fa9a3 JK |
13 | * Emulex |
14 | * 3333 Susan Street | |
15 | * Costa Mesa, CA 92626 | |
6733b39a JK |
16 | */ |
17 | ||
2177199d JSJ |
18 | #include <scsi/iscsi_proto.h> |
19 | ||
6733b39a JK |
20 | #include "be.h" |
21 | #include "be_mgmt.h" | |
22 | #include "be_main.h" | |
23 | ||
e9b91193 JK |
24 | int 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) { | |
99bc5d55 JSJ |
51 | printk(KERN_ERR DRV_NAME |
52 | " Soft Reset did not deassert\n"); | |
e9b91193 JK |
53 | return -EIO; |
54 | } | |
55 | pconline1 = BE2_MPU_IRAM_ONLINE; | |
56 | writel(pconline0, (void *)pci_online0_offset); | |
57 | writel(pconline1, (void *)pci_online1_offset); | |
58 | ||
1d8bc70a | 59 | sreset |= BE2_SET_RESET; |
e9b91193 JK |
60 | 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) { | |
99bc5d55 JSJ |
71 | printk(KERN_ERR DRV_NAME |
72 | " MPU Online Soft Reset did not deassert\n"); | |
e9b91193 JK |
73 | return -EIO; |
74 | } | |
75 | return 0; | |
76 | } | |
77 | ||
78 | int 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)) { | |
99bc5d55 JSJ |
98 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
99 | "BC_%d : Failed in be_chk_reset_complete" | |
100 | "status = 0x%x\n", status); | |
e9b91193 JK |
101 | return -EIO; |
102 | } | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
756d29c8 | 107 | void be_mcc_notify(struct beiscsi_hba *phba) |
bfead3b2 JK |
108 | { |
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 | ||
756d29c8 JK |
117 | unsigned int alloc_mcc_tag(struct beiscsi_hba *phba) |
118 | { | |
119 | unsigned int tag = 0; | |
756d29c8 | 120 | |
756d29c8 JK |
121 | 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; | |
756d29c8 JK |
125 | } |
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 | ||
e175defe JSJ |
136 | /* |
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 | **/ | |
149 | int 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; | |
a8081e34 | 158 | struct be_cmd_resp_hdr *ioctl_resp_hdr; |
e175defe JSJ |
159 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
160 | ||
7a158003 JSJ |
161 | if (beiscsi_error(phba)) |
162 | return -EIO; | |
163 | ||
e175defe JSJ |
164 | /* 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); | |
a8081e34 JK |
208 | |
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 | } | |
e175defe JSJ |
214 | rc = -EAGAIN; |
215 | } | |
216 | ||
217 | release_mcc_tag: | |
218 | /* Release the MCC entry */ | |
219 | free_mcc_tag(&phba->ctrl, tag); | |
220 | ||
221 | return rc; | |
222 | } | |
223 | ||
756d29c8 JK |
224 | void 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 | ||
237 | bool 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 | ||
6733b39a JK |
244 | static 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 | ||
254 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) | |
255 | { | |
256 | compl->flags = 0; | |
257 | } | |
258 | ||
e175defe JSJ |
259 | /* |
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 | **/ | |
6733b39a JK |
270 | static int be_mcc_compl_process(struct be_ctrl_info *ctrl, |
271 | struct be_mcc_compl *compl) | |
272 | { | |
273 | u16 compl_status, extd_status; | |
e175defe | 274 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
99bc5d55 | 275 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
e175defe | 276 | struct be_cmd_req_hdr *hdr = embedded_payload(wrb); |
a8081e34 | 277 | struct be_cmd_resp_hdr *resp_hdr; |
6733b39a JK |
278 | |
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; | |
99bc5d55 JSJ |
286 | |
287 | beiscsi_log(phba, KERN_ERR, | |
288 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
e175defe JSJ |
289 | "BC_%d : error in cmd completion: " |
290 | "Subsystem : %d Opcode : %d " | |
291 | "status(compl/extd)=%d/%d\n", | |
292 | hdr->subsystem, hdr->opcode, | |
99bc5d55 JSJ |
293 | compl_status, extd_status); |
294 | ||
a8081e34 JK |
295 | 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 | } | |
d3ad2bb3 | 300 | return -EBUSY; |
6733b39a JK |
301 | } |
302 | return 0; | |
303 | } | |
304 | ||
756d29c8 JK |
305 | int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl, |
306 | struct be_mcc_compl *compl) | |
6733b39a | 307 | { |
756d29c8 JK |
308 | 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; | |
bfead3b2 JK |
329 | } |
330 | ||
331 | static 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 | ||
343 | static 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 | ||
756d29c8 | 348 | void beiscsi_async_link_state_process(struct beiscsi_hba *phba, |
bfead3b2 JK |
349 | struct be_async_event_link_state *evt) |
350 | { | |
351 | switch (evt->port_link_status) { | |
352 | case ASYNC_EVENT_LINK_DOWN: | |
99bc5d55 JSJ |
353 | 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 | ||
bfead3b2 | 358 | phba->state |= BE_ADAPTER_LINK_DOWN; |
da7408c8 JK |
359 | iscsi_host_for_each_session(phba->shost, |
360 | be2iscsi_fail_session); | |
bfead3b2 JK |
361 | break; |
362 | case ASYNC_EVENT_LINK_UP: | |
363 | phba->state = BE_ADAPTER_UP; | |
99bc5d55 JSJ |
364 | 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); | |
bfead3b2 JK |
368 | break; |
369 | default: | |
99bc5d55 JSJ |
370 | 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); | |
bfead3b2 | 376 | } |
6733b39a JK |
377 | } |
378 | ||
bfead3b2 | 379 | static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm, |
6733b39a JK |
380 | 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; | |
bfead3b2 JK |
387 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
388 | } | |
389 | ||
390 | ||
35e66019 | 391 | int beiscsi_process_mcc(struct beiscsi_hba *phba) |
bfead3b2 JK |
392 | { |
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 */ | |
78b9fb6d JK |
401 | 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 | |
99bc5d55 JSJ |
406 | 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); | |
bfead3b2 | 411 | |
bfead3b2 JK |
412 | } 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 | ||
e175defe JSJ |
427 | /* |
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 | **/ | |
bfead3b2 JK |
438 | static int be_mcc_wait_compl(struct beiscsi_hba *phba) |
439 | { | |
bfead3b2 JK |
440 | int i, status; |
441 | for (i = 0; i < mcc_timeout; i++) { | |
7a158003 | 442 | if (beiscsi_error(phba)) |
e175defe JSJ |
443 | return -EIO; |
444 | ||
35e66019 | 445 | status = beiscsi_process_mcc(phba); |
bfead3b2 JK |
446 | 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) { | |
99bc5d55 JSJ |
454 | beiscsi_log(phba, KERN_ERR, |
455 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
e175defe JSJ |
456 | "BC_%d : FW Timed Out\n"); |
457 | phba->fw_timeout = true; | |
7a158003 | 458 | beiscsi_ue_detect(phba); |
d3ad2bb3 | 459 | return -EBUSY; |
bfead3b2 JK |
460 | } |
461 | return 0; | |
462 | } | |
463 | ||
e175defe JSJ |
464 | /* |
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 | **/ | |
bfead3b2 JK |
474 | int be_mcc_notify_wait(struct beiscsi_hba *phba) |
475 | { | |
476 | be_mcc_notify(phba); | |
477 | return be_mcc_wait_compl(phba); | |
6733b39a JK |
478 | } |
479 | ||
e175defe JSJ |
480 | /* |
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 | **/ | |
6733b39a JK |
491 | static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl) |
492 | { | |
6733b39a | 493 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
e175defe | 494 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
1e234bbb | 495 | uint32_t wait = 0; |
6733b39a JK |
496 | u32 ready; |
497 | ||
498 | do { | |
7a158003 JSJ |
499 | |
500 | if (beiscsi_error(phba)) | |
e175defe JSJ |
501 | return -EIO; |
502 | ||
6733b39a JK |
503 | ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK; |
504 | if (ready) | |
505 | break; | |
506 | ||
e175defe | 507 | if (wait > BEISCSI_HOST_MBX_TIMEOUT) { |
99bc5d55 JSJ |
508 | beiscsi_log(phba, KERN_ERR, |
509 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
e175defe JSJ |
510 | "BC_%d : FW Timed Out\n"); |
511 | phba->fw_timeout = true; | |
7a158003 | 512 | beiscsi_ue_detect(phba); |
d3ad2bb3 | 513 | return -EBUSY; |
6733b39a JK |
514 | } |
515 | ||
e175defe JSJ |
516 | mdelay(1); |
517 | wait++; | |
6733b39a JK |
518 | } while (true); |
519 | return 0; | |
520 | } | |
521 | ||
e175defe JSJ |
522 | /* |
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 | **/ | |
6733b39a JK |
533 | int 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; | |
99bc5d55 | 541 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a | 542 | |
1e234bbb JK |
543 | status = be_mbox_db_ready_wait(ctrl); |
544 | if (status) | |
545 | return status; | |
546 | ||
6733b39a JK |
547 | 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); | |
e175defe | 553 | if (status) |
6733b39a | 554 | return status; |
e175defe | 555 | |
6733b39a JK |
556 | 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); | |
e175defe | 563 | if (status) |
6733b39a | 564 | return status; |
e175defe | 565 | |
6733b39a JK |
566 | 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) { | |
99bc5d55 JSJ |
570 | beiscsi_log(phba, KERN_ERR, |
571 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
572 | "BC_%d : After be_mcc_compl_process\n"); | |
573 | ||
6733b39a JK |
574 | return status; |
575 | } | |
576 | } else { | |
99bc5d55 JSJ |
577 | beiscsi_log(phba, KERN_ERR, |
578 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
579 | "BC_%d : Invalid Mailbox Completion\n"); | |
580 | ||
d3ad2bb3 | 581 | return -EBUSY; |
6733b39a JK |
582 | } |
583 | return 0; | |
584 | } | |
585 | ||
bfead3b2 JK |
586 | /* |
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 | */ | |
590 | static 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 | ||
1e234bbb JK |
600 | status = be_mbox_db_ready_wait(ctrl); |
601 | if (status) | |
602 | return status; | |
603 | ||
bfead3b2 JK |
604 | 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 { | |
99bc5d55 JSJ |
630 | beiscsi_log(phba, KERN_ERR, |
631 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
632 | "BC_%d : invalid mailbox completion\n"); | |
633 | ||
d3ad2bb3 | 634 | return -EBUSY; |
bfead3b2 JK |
635 | } |
636 | return 0; | |
637 | } | |
638 | ||
6733b39a JK |
639 | void 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 | ||
651 | void 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)); | |
e175defe | 657 | req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT; |
6733b39a JK |
658 | } |
659 | ||
660 | static 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 | ||
674 | static 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 | ||
696 | struct 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 | ||
bfead3b2 JK |
701 | struct 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); | |
756d29c8 JK |
708 | memset(wrb, 0, sizeof(*wrb)); |
709 | wrb->tag0 = (mccq->head & 0x000000FF) << 16; | |
bfead3b2 JK |
710 | queue_head_inc(mccq); |
711 | atomic_inc(&mccq->used); | |
bfead3b2 JK |
712 | return wrb; |
713 | } | |
714 | ||
715 | ||
6733b39a JK |
716 | int 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 | ||
0283fbb1 JK |
756 | /** |
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 | **/ | |
6733b39a JK |
766 | int be_cmd_fw_initialize(struct be_ctrl_info *ctrl) |
767 | { | |
768 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); | |
99bc5d55 | 769 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a JK |
770 | 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) | |
99bc5d55 JSJ |
789 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
790 | "BC_%d : be_cmd_fw_initialize Failed\n"); | |
6733b39a JK |
791 | |
792 | spin_unlock(&ctrl->mbox_lock); | |
793 | return status; | |
794 | } | |
795 | ||
0283fbb1 JK |
796 | /** |
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 | **/ | |
806 | int 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 | ||
6733b39a JK |
837 | int 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); | |
99bc5d55 | 844 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a JK |
845 | 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)); | |
6733b39a JK |
856 | |
857 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); | |
2c9dfd36 | 858 | if (is_chip_be2_be3r(phba)) { |
eaae5267 JSJ |
859 | 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)); | |
2c9dfd36 JK |
871 | } 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); | |
eaae5267 | 884 | } |
6733b39a | 885 | |
6733b39a JK |
886 | 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 | |
99bc5d55 JSJ |
895 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
896 | "BC_%d : In be_cmd_cq_create, status=ox%08x\n", | |
897 | status); | |
898 | ||
6733b39a JK |
899 | spin_unlock(&ctrl->mbox_lock); |
900 | ||
901 | return status; | |
902 | } | |
903 | ||
904 | static 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 | } | |
bfead3b2 | 911 | |
35e66019 | 912 | int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba, |
bfead3b2 JK |
913 | 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); | |
37609766 | 926 | memset(wrb, 0, sizeof(*wrb)); |
bfead3b2 JK |
927 | 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 | ||
6733b39a JK |
959 | int 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); | |
99bc5d55 | 964 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a JK |
965 | u8 subsys = 0, opcode = 0; |
966 | int status; | |
967 | ||
99bc5d55 JSJ |
968 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
969 | "BC_%d : In beiscsi_cmd_q_destroy " | |
970 | "queue_type : %d\n", queue_type); | |
971 | ||
6733b39a JK |
972 | 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; | |
bfead3b2 JK |
985 | case QTYPE_MCCQ: |
986 | subsys = CMD_SUBSYSTEM_COMMON; | |
987 | opcode = OPCODE_COMMON_MCC_DESTROY; | |
988 | break; | |
6733b39a JK |
989 | 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(); | |
d3ad2bb3 | 1004 | return -ENXIO; |
6733b39a JK |
1005 | } |
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 | ||
6733b39a JK |
1016 | int 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; | |
ef9e1b9b | 1024 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a JK |
1025 | 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); | |
ef9e1b9b JK |
1037 | |
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 | } | |
6733b39a JK |
1067 | |
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 | ||
1084 | int 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); | |
bfead3b2 | 1103 | if (!status) { |
6733b39a | 1104 | wrbq->id = le16_to_cpu(resp->cid); |
bfead3b2 JK |
1105 | wrbq->created = true; |
1106 | } | |
6733b39a JK |
1107 | spin_unlock(&ctrl->mbox_lock); |
1108 | return status; | |
1109 | } | |
1110 | ||
1111 | int 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); | |
99bc5d55 | 1117 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
6733b39a JK |
1118 | 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) { | |
99bc5d55 JSJ |
1148 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
1149 | "BC_%d : FW CMD to map iscsi frags failed.\n"); | |
1150 | ||
6733b39a JK |
1151 | goto error; |
1152 | } | |
1153 | } while (num_pages > 0); | |
1154 | error: | |
1155 | spin_unlock(&ctrl->mbox_lock); | |
1156 | if (status != 0) | |
1157 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); | |
1158 | return status; | |
1159 | } | |
e5285860 JK |
1160 | |
1161 | int 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 | } | |
6f72238e JSJ |
1179 | |
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 | * **/ | |
1190 | int 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 | } |