]>
Commit | Line | Data |
---|---|---|
9c915a8c AR |
1 | /* |
2 | * Linux MegaRAID driver for SAS based RAID controllers | |
3 | * | |
e399065b SS |
4 | * Copyright (c) 2009-2013 LSI Corporation |
5 | * Copyright (c) 2013-2014 Avago Technologies | |
9c915a8c AR |
6 | * |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * as published by the Free Software Foundation; either version 2 | |
10 | * of the License, or (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
e399065b | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
9c915a8c AR |
19 | * |
20 | * FILE: megaraid_sas_fusion.c | |
21 | * | |
e399065b | 22 | * Authors: Avago Technologies |
9c915a8c | 23 | * Sumant Patro |
e399065b SS |
24 | * Adam Radford |
25 | * Kashyap Desai <kashyap.desai@avagotech.com> | |
26 | * Sumit Saxena <sumit.saxena@avagotech.com> | |
9c915a8c | 27 | * |
e399065b | 28 | * Send feedback to: megaraidlinux.pdl@avagotech.com |
9c915a8c | 29 | * |
e399065b SS |
30 | * Mail to: Avago Technologies, 350 West Trimble Road, Building 90, |
31 | * San Jose, California 95131 | |
9c915a8c AR |
32 | */ |
33 | ||
34 | #include <linux/kernel.h> | |
35 | #include <linux/types.h> | |
36 | #include <linux/pci.h> | |
37 | #include <linux/list.h> | |
38 | #include <linux/moduleparam.h> | |
39 | #include <linux/module.h> | |
40 | #include <linux/spinlock.h> | |
41 | #include <linux/interrupt.h> | |
42 | #include <linux/delay.h> | |
9c915a8c AR |
43 | #include <linux/uio.h> |
44 | #include <linux/uaccess.h> | |
45 | #include <linux/fs.h> | |
46 | #include <linux/compat.h> | |
47 | #include <linux/blkdev.h> | |
48 | #include <linux/mutex.h> | |
49 | #include <linux/poll.h> | |
5fc499b6 | 50 | #include <linux/vmalloc.h> |
9c915a8c AR |
51 | |
52 | #include <scsi/scsi.h> | |
53 | #include <scsi/scsi_cmnd.h> | |
54 | #include <scsi/scsi_device.h> | |
55 | #include <scsi/scsi_host.h> | |
90dc9d98 | 56 | #include <scsi/scsi_dbg.h> |
5765c5b8 | 57 | #include <linux/dmi.h> |
9c915a8c AR |
58 | |
59 | #include "megaraid_sas_fusion.h" | |
60 | #include "megaraid_sas.h" | |
61 | ||
4026e9aa | 62 | |
9c915a8c AR |
63 | extern void megasas_free_cmds(struct megasas_instance *instance); |
64 | extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance | |
65 | *instance); | |
66 | extern void | |
67 | megasas_complete_cmd(struct megasas_instance *instance, | |
68 | struct megasas_cmd *cmd, u8 alt_status); | |
9c915a8c | 69 | int |
229fe47c AR |
70 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
71 | int seconds); | |
9c915a8c AR |
72 | |
73 | void | |
74 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd); | |
75 | int megasas_alloc_cmds(struct megasas_instance *instance); | |
76 | int | |
77 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs); | |
78 | int | |
79 | megasas_issue_polled(struct megasas_instance *instance, | |
80 | struct megasas_cmd *cmd); | |
53ef2bbd AR |
81 | void |
82 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance); | |
83 | ||
058a8fac | 84 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
9c915a8c AR |
85 | void megaraid_sas_kill_hba(struct megasas_instance *instance); |
86 | ||
87 | extern u32 megasas_dbg_lvl; | |
229fe47c AR |
88 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
89 | int initial); | |
c251a7be | 90 | void megasas_start_timer(struct megasas_instance *instance); |
229fe47c | 91 | extern struct megasas_mgmt_info megasas_mgmt_info; |
e3d178ca | 92 | extern unsigned int resetwaittime; |
308ec459 | 93 | extern unsigned int dual_qdepth_disable; |
179ac142 SS |
94 | static void megasas_free_rdpq_fusion(struct megasas_instance *instance); |
95 | static void megasas_free_reply_fusion(struct megasas_instance *instance); | |
e97e673c S |
96 | static inline |
97 | void megasas_configure_queue_sizes(struct megasas_instance *instance); | |
9c915a8c | 98 | |
107a60dd S |
99 | /** |
100 | * megasas_check_same_4gb_region - check if allocation | |
101 | * crosses same 4GB boundary or not | |
102 | * @instance - adapter's soft instance | |
103 | * start_addr - start address of DMA allocation | |
104 | * size - size of allocation in bytes | |
105 | * return - true : allocation does not cross same | |
106 | * 4GB boundary | |
107 | * false: allocation crosses same | |
108 | * 4GB boundary | |
109 | */ | |
110 | static inline bool megasas_check_same_4gb_region | |
111 | (struct megasas_instance *instance, dma_addr_t start_addr, size_t size) | |
112 | { | |
113 | dma_addr_t end_addr; | |
114 | ||
115 | end_addr = start_addr + size; | |
fc62b3fc | 116 | |
107a60dd S |
117 | if (upper_32_bits(start_addr) != upper_32_bits(end_addr)) { |
118 | dev_err(&instance->pdev->dev, | |
119 | "Failed to get same 4GB boundary: start_addr: 0x%llx end_addr: 0x%llx\n", | |
120 | (unsigned long long)start_addr, | |
121 | (unsigned long long)end_addr); | |
122 | return false; | |
123 | } | |
124 | ||
125 | return true; | |
126 | } | |
fc62b3fc | 127 | |
9c915a8c AR |
128 | /** |
129 | * megasas_enable_intr_fusion - Enables interrupts | |
130 | * @regs: MFI register set | |
131 | */ | |
132 | void | |
d46a3ad6 | 133 | megasas_enable_intr_fusion(struct megasas_instance *instance) |
9c915a8c | 134 | { |
d46a3ad6 SS |
135 | struct megasas_register_set __iomem *regs; |
136 | regs = instance->reg_set; | |
c2ced171 SS |
137 | |
138 | instance->mask_interrupts = 0; | |
6497b247 AR |
139 | /* For Thunderbolt/Invader also clear intr on enable */ |
140 | writel(~0, ®s->outbound_intr_status); | |
141 | readl(®s->outbound_intr_status); | |
142 | ||
9c915a8c AR |
143 | writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
144 | ||
145 | /* Dummy readl to force pci flush */ | |
146 | readl(®s->outbound_intr_mask); | |
147 | } | |
148 | ||
149 | /** | |
150 | * megasas_disable_intr_fusion - Disables interrupt | |
151 | * @regs: MFI register set | |
152 | */ | |
153 | void | |
d46a3ad6 | 154 | megasas_disable_intr_fusion(struct megasas_instance *instance) |
9c915a8c AR |
155 | { |
156 | u32 mask = 0xFFFFFFFF; | |
157 | u32 status; | |
d46a3ad6 SS |
158 | struct megasas_register_set __iomem *regs; |
159 | regs = instance->reg_set; | |
160 | instance->mask_interrupts = 1; | |
9c915a8c AR |
161 | |
162 | writel(mask, ®s->outbound_intr_mask); | |
163 | /* Dummy readl to force pci flush */ | |
164 | status = readl(®s->outbound_intr_mask); | |
165 | } | |
166 | ||
167 | int | |
168 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs) | |
169 | { | |
170 | u32 status; | |
171 | /* | |
172 | * Check if it is our interrupt | |
173 | */ | |
174 | status = readl(®s->outbound_intr_status); | |
175 | ||
176 | if (status & 1) { | |
177 | writel(status, ®s->outbound_intr_status); | |
178 | readl(®s->outbound_intr_status); | |
179 | return 1; | |
180 | } | |
181 | if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) | |
182 | return 0; | |
183 | ||
9c915a8c AR |
184 | return 1; |
185 | } | |
186 | ||
187 | /** | |
188 | * megasas_get_cmd_fusion - Get a command from the free pool | |
189 | * @instance: Adapter soft state | |
190 | * | |
4026e9aa | 191 | * Returns a blk_tag indexed mpt frame |
9c915a8c | 192 | */ |
4026e9aa SS |
193 | inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance |
194 | *instance, u32 blk_tag) | |
9c915a8c | 195 | { |
4026e9aa | 196 | struct fusion_context *fusion; |
9c915a8c | 197 | |
4026e9aa SS |
198 | fusion = instance->ctrl_context; |
199 | return fusion->cmd_list[blk_tag]; | |
9c915a8c AR |
200 | } |
201 | ||
202 | /** | |
203 | * megasas_return_cmd_fusion - Return a cmd to free command pool | |
204 | * @instance: Adapter soft state | |
205 | * @cmd: Command packet to be returned to free command pool | |
206 | */ | |
90dc9d98 SS |
207 | inline void megasas_return_cmd_fusion(struct megasas_instance *instance, |
208 | struct megasas_cmd_fusion *cmd) | |
9c915a8c | 209 | { |
9c915a8c | 210 | cmd->scmd = NULL; |
8bf7c65d S |
211 | memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); |
212 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; | |
213 | cmd->cmd_completed = false; | |
90dc9d98 SS |
214 | } |
215 | ||
216 | /** | |
01d7f03b | 217 | * megasas_fire_cmd_fusion - Sends command to the FW |
45b8a35e | 218 | * @instance: Adapter soft state |
2ff925cb | 219 | * @req_desc: 64bit Request descriptor |
45b8a35e | 220 | * |
2ff925cb | 221 | * Perform PCI Write. |
90dc9d98 | 222 | */ |
45b8a35e | 223 | |
01d7f03b CH |
224 | static void |
225 | megasas_fire_cmd_fusion(struct megasas_instance *instance, | |
45b8a35e | 226 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc) |
90dc9d98 | 227 | { |
45b8a35e | 228 | #if defined(writeq) && defined(CONFIG_64BIT) |
2ff925cb S |
229 | u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) | |
230 | le32_to_cpu(req_desc->u.low)); | |
45b8a35e | 231 | |
2ff925cb | 232 | writeq(req_data, &instance->reg_set->inbound_low_queue_port); |
45b8a35e | 233 | #else |
2ff925cb S |
234 | unsigned long flags; |
235 | spin_lock_irqsave(&instance->hba_lock, flags); | |
236 | writel(le32_to_cpu(req_desc->u.low), | |
237 | &instance->reg_set->inbound_low_queue_port); | |
238 | writel(le32_to_cpu(req_desc->u.high), | |
239 | &instance->reg_set->inbound_high_queue_port); | |
240 | mmiowb(); | |
241 | spin_unlock_irqrestore(&instance->hba_lock, flags); | |
01d7f03b | 242 | #endif |
9c915a8c AR |
243 | } |
244 | ||
308ec459 SS |
245 | /** |
246 | * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here | |
247 | * @instance: Adapter soft state | |
248 | * fw_boot_context: Whether this function called during probe or after OCR | |
249 | * | |
250 | * This function is only for fusion controllers. | |
251 | * Update host can queue, if firmware downgrade max supported firmware commands. | |
252 | * Firmware upgrade case will be skiped because underlying firmware has | |
253 | * more resource than exposed to the OS. | |
254 | * | |
255 | */ | |
256 | static void | |
257 | megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_context) | |
258 | { | |
259 | u16 cur_max_fw_cmds = 0; | |
260 | u16 ldio_threshold = 0; | |
261 | struct megasas_register_set __iomem *reg_set; | |
262 | ||
263 | reg_set = instance->reg_set; | |
264 | ||
9581ebeb | 265 | /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */ |
f369a315 | 266 | if (instance->adapter_type < VENTURA_SERIES) |
9581ebeb SC |
267 | cur_max_fw_cmds = |
268 | readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF; | |
308ec459 SS |
269 | |
270 | if (dual_qdepth_disable || !cur_max_fw_cmds) | |
271 | cur_max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; | |
272 | else | |
273 | ldio_threshold = | |
274 | (instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS; | |
275 | ||
276 | dev_info(&instance->pdev->dev, | |
b5c5d0ad | 277 | "Current firmware supports maximum commands: %d\t LDIO threshold: %d\n", |
e97e673c | 278 | cur_max_fw_cmds, ldio_threshold); |
308ec459 SS |
279 | |
280 | if (fw_boot_context == OCR_CONTEXT) { | |
281 | cur_max_fw_cmds = cur_max_fw_cmds - 1; | |
013aec66 | 282 | if (cur_max_fw_cmds < instance->max_fw_cmds) { |
308ec459 SS |
283 | instance->cur_can_queue = |
284 | cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS + | |
285 | MEGASAS_FUSION_IOCTL_CMDS); | |
286 | instance->host->can_queue = instance->cur_can_queue; | |
287 | instance->ldio_threshold = ldio_threshold; | |
288 | } | |
289 | } else { | |
290 | instance->max_fw_cmds = cur_max_fw_cmds; | |
291 | instance->ldio_threshold = ldio_threshold; | |
292 | ||
c3e385a1 SS |
293 | if (reset_devices) |
294 | instance->max_fw_cmds = min(instance->max_fw_cmds, | |
295 | (u16)MEGASAS_KDUMP_QUEUE_DEPTH); | |
308ec459 SS |
296 | /* |
297 | * Reduce the max supported cmds by 1. This is to ensure that the | |
298 | * reply_q_sz (1 more than the max cmd that driver may send) | |
299 | * does not exceed max cmds that the FW can support | |
300 | */ | |
301 | instance->max_fw_cmds = instance->max_fw_cmds-1; | |
308ec459 SS |
302 | } |
303 | } | |
9c915a8c | 304 | /** |
179ac142 SS |
305 | * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool |
306 | * @instance: Adapter soft state | |
9c915a8c | 307 | */ |
179ac142 SS |
308 | void |
309 | megasas_free_cmds_fusion(struct megasas_instance *instance) | |
9c915a8c AR |
310 | { |
311 | int i; | |
312 | struct fusion_context *fusion = instance->ctrl_context; | |
9c915a8c AR |
313 | struct megasas_cmd_fusion *cmd; |
314 | ||
107a60dd S |
315 | if (fusion->sense) |
316 | dma_pool_free(fusion->sense_dma_pool, fusion->sense, | |
317 | fusion->sense_phys_addr); | |
318 | ||
319 | /* SG */ | |
320 | if (fusion->cmd_list) { | |
321 | for (i = 0; i < instance->max_mpt_cmds; i++) { | |
322 | cmd = fusion->cmd_list[i]; | |
323 | if (cmd) { | |
324 | if (cmd->sg_frame) | |
325 | dma_pool_free(fusion->sg_dma_pool, | |
326 | cmd->sg_frame, | |
327 | cmd->sg_frame_phys_addr); | |
328 | } | |
329 | kfree(cmd); | |
179ac142 | 330 | } |
107a60dd | 331 | kfree(fusion->cmd_list); |
9c915a8c AR |
332 | } |
333 | ||
179ac142 | 334 | if (fusion->sg_dma_pool) { |
fc69d86d | 335 | dma_pool_destroy(fusion->sg_dma_pool); |
179ac142 SS |
336 | fusion->sg_dma_pool = NULL; |
337 | } | |
338 | if (fusion->sense_dma_pool) { | |
fc69d86d | 339 | dma_pool_destroy(fusion->sense_dma_pool); |
179ac142 SS |
340 | fusion->sense_dma_pool = NULL; |
341 | } | |
9c915a8c | 342 | |
9c915a8c | 343 | |
179ac142 SS |
344 | /* Reply Frame, Desc*/ |
345 | if (instance->is_rdpq) | |
346 | megasas_free_rdpq_fusion(instance); | |
347 | else | |
348 | megasas_free_reply_fusion(instance); | |
9c915a8c | 349 | |
179ac142 | 350 | /* Request Frame, Desc*/ |
9c915a8c | 351 | if (fusion->req_frames_desc) |
179ac142 SS |
352 | dma_free_coherent(&instance->pdev->dev, |
353 | fusion->request_alloc_sz, fusion->req_frames_desc, | |
354 | fusion->req_frames_desc_phys); | |
355 | if (fusion->io_request_frames) | |
fc69d86d | 356 | dma_pool_free(fusion->io_request_frames_pool, |
179ac142 SS |
357 | fusion->io_request_frames, |
358 | fusion->io_request_frames_phys); | |
359 | if (fusion->io_request_frames_pool) { | |
fc69d86d | 360 | dma_pool_destroy(fusion->io_request_frames_pool); |
179ac142 | 361 | fusion->io_request_frames_pool = NULL; |
9c915a8c | 362 | } |
9c915a8c AR |
363 | } |
364 | ||
365 | /** | |
179ac142 | 366 | * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames |
9c915a8c AR |
367 | * @instance: Adapter soft state |
368 | * | |
369 | */ | |
179ac142 | 370 | static int megasas_create_sg_sense_fusion(struct megasas_instance *instance) |
9c915a8c AR |
371 | { |
372 | int i; | |
50b7f5a2 | 373 | u16 max_cmd; |
9c915a8c AR |
374 | struct fusion_context *fusion; |
375 | struct megasas_cmd_fusion *cmd; | |
107a60dd S |
376 | int sense_sz; |
377 | u32 offset; | |
9c915a8c AR |
378 | |
379 | fusion = instance->ctrl_context; | |
380 | max_cmd = instance->max_fw_cmds; | |
107a60dd | 381 | sense_sz = instance->max_mpt_cmds * SCSI_SENSE_BUFFERSIZE; |
9c915a8c | 382 | |
179ac142 | 383 | fusion->sg_dma_pool = |
fc69d86d | 384 | dma_pool_create("mr_sg", &instance->pdev->dev, |
15dd0381 S |
385 | instance->max_chain_frame_sz, |
386 | MR_DEFAULT_NVME_PAGE_SIZE, 0); | |
179ac142 SS |
387 | /* SCSI_SENSE_BUFFERSIZE = 96 bytes */ |
388 | fusion->sense_dma_pool = | |
fc69d86d | 389 | dma_pool_create("mr_sense", &instance->pdev->dev, |
107a60dd | 390 | sense_sz, 64, 0); |
9c915a8c | 391 | |
179ac142 SS |
392 | if (!fusion->sense_dma_pool || !fusion->sg_dma_pool) { |
393 | dev_err(&instance->pdev->dev, | |
394 | "Failed from %s %d\n", __func__, __LINE__); | |
9c915a8c AR |
395 | return -ENOMEM; |
396 | } | |
397 | ||
107a60dd S |
398 | fusion->sense = dma_pool_alloc(fusion->sense_dma_pool, |
399 | GFP_KERNEL, &fusion->sense_phys_addr); | |
400 | if (!fusion->sense) { | |
401 | dev_err(&instance->pdev->dev, | |
402 | "failed from %s %d\n", __func__, __LINE__); | |
403 | return -ENOMEM; | |
404 | } | |
405 | ||
406 | /* sense buffer, request frame and reply desc pool requires to be in | |
407 | * same 4 gb region. Below function will check this. | |
408 | * In case of failure, new pci pool will be created with updated | |
409 | * alignment. | |
410 | * Older allocation and pool will be destroyed. | |
411 | * Alignment will be used such a way that next allocation if success, | |
412 | * will always meet same 4gb region requirement. | |
413 | * Actual requirement is not alignment, but we need start and end of | |
414 | * DMA address must have same upper 32 bit address. | |
415 | */ | |
416 | ||
417 | if (!megasas_check_same_4gb_region(instance, fusion->sense_phys_addr, | |
418 | sense_sz)) { | |
419 | dma_pool_free(fusion->sense_dma_pool, fusion->sense, | |
420 | fusion->sense_phys_addr); | |
421 | fusion->sense = NULL; | |
422 | dma_pool_destroy(fusion->sense_dma_pool); | |
423 | ||
424 | fusion->sense_dma_pool = | |
425 | dma_pool_create("mr_sense_align", &instance->pdev->dev, | |
426 | sense_sz, roundup_pow_of_two(sense_sz), | |
427 | 0); | |
428 | if (!fusion->sense_dma_pool) { | |
429 | dev_err(&instance->pdev->dev, | |
430 | "Failed from %s %d\n", __func__, __LINE__); | |
431 | return -ENOMEM; | |
432 | } | |
433 | fusion->sense = dma_pool_alloc(fusion->sense_dma_pool, | |
434 | GFP_KERNEL, | |
435 | &fusion->sense_phys_addr); | |
436 | if (!fusion->sense) { | |
437 | dev_err(&instance->pdev->dev, | |
438 | "failed from %s %d\n", __func__, __LINE__); | |
439 | return -ENOMEM; | |
440 | } | |
441 | } | |
442 | ||
9c915a8c AR |
443 | /* |
444 | * Allocate and attach a frame to each of the commands in cmd_list | |
445 | */ | |
446 | for (i = 0; i < max_cmd; i++) { | |
9c915a8c | 447 | cmd = fusion->cmd_list[i]; |
fc69d86d | 448 | cmd->sg_frame = dma_pool_alloc(fusion->sg_dma_pool, |
179ac142 | 449 | GFP_KERNEL, &cmd->sg_frame_phys_addr); |
9c915a8c | 450 | |
107a60dd S |
451 | offset = SCSI_SENSE_BUFFERSIZE * i; |
452 | cmd->sense = (u8 *)fusion->sense + offset; | |
453 | cmd->sense_phys_addr = fusion->sense_phys_addr + offset; | |
454 | ||
455 | if (!cmd->sg_frame) { | |
179ac142 SS |
456 | dev_err(&instance->pdev->dev, |
457 | "Failed from %s %d\n", __func__, __LINE__); | |
9c915a8c AR |
458 | return -ENOMEM; |
459 | } | |
460 | } | |
69c337c0 SC |
461 | |
462 | /* create sense buffer for the raid 1/10 fp */ | |
463 | for (i = max_cmd; i < instance->max_mpt_cmds; i++) { | |
464 | cmd = fusion->cmd_list[i]; | |
107a60dd S |
465 | offset = SCSI_SENSE_BUFFERSIZE * i; |
466 | cmd->sense = (u8 *)fusion->sense + offset; | |
467 | cmd->sense_phys_addr = fusion->sense_phys_addr + offset; | |
468 | ||
69c337c0 SC |
469 | } |
470 | ||
9c915a8c AR |
471 | return 0; |
472 | } | |
473 | ||
9c915a8c | 474 | int |
179ac142 | 475 | megasas_alloc_cmdlist_fusion(struct megasas_instance *instance) |
9c915a8c | 476 | { |
70c54e21 | 477 | u32 max_mpt_cmd, i, j; |
9c915a8c | 478 | struct fusion_context *fusion; |
9c915a8c AR |
479 | |
480 | fusion = instance->ctrl_context; | |
481 | ||
69c337c0 | 482 | max_mpt_cmd = instance->max_mpt_cmds; |
9c915a8c | 483 | |
179ac142 SS |
484 | /* |
485 | * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers. | |
486 | * Allocate the dynamic array first and then allocate individual | |
487 | * commands. | |
488 | */ | |
69c337c0 SC |
489 | fusion->cmd_list = |
490 | kzalloc(sizeof(struct megasas_cmd_fusion *) * max_mpt_cmd, | |
491 | GFP_KERNEL); | |
179ac142 SS |
492 | if (!fusion->cmd_list) { |
493 | dev_err(&instance->pdev->dev, | |
494 | "Failed from %s %d\n", __func__, __LINE__); | |
495 | return -ENOMEM; | |
496 | } | |
497 | ||
69c337c0 | 498 | for (i = 0; i < max_mpt_cmd; i++) { |
179ac142 SS |
499 | fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion), |
500 | GFP_KERNEL); | |
501 | if (!fusion->cmd_list[i]) { | |
70c54e21 SW |
502 | for (j = 0; j < i; j++) |
503 | kfree(fusion->cmd_list[j]); | |
504 | kfree(fusion->cmd_list); | |
179ac142 SS |
505 | dev_err(&instance->pdev->dev, |
506 | "Failed from %s %d\n", __func__, __LINE__); | |
507 | return -ENOMEM; | |
508 | } | |
509 | } | |
70c54e21 | 510 | |
179ac142 SS |
511 | return 0; |
512 | } | |
513 | int | |
514 | megasas_alloc_request_fusion(struct megasas_instance *instance) | |
515 | { | |
516 | struct fusion_context *fusion; | |
517 | ||
518 | fusion = instance->ctrl_context; | |
519 | ||
e97e673c | 520 | retry_alloc: |
179ac142 | 521 | fusion->io_request_frames_pool = |
fc69d86d | 522 | dma_pool_create("mr_ioreq", &instance->pdev->dev, |
179ac142 SS |
523 | fusion->io_frames_alloc_sz, 16, 0); |
524 | ||
525 | if (!fusion->io_request_frames_pool) { | |
526 | dev_err(&instance->pdev->dev, | |
527 | "Failed from %s %d\n", __func__, __LINE__); | |
528 | return -ENOMEM; | |
529 | } | |
530 | ||
531 | fusion->io_request_frames = | |
fc69d86d | 532 | dma_pool_alloc(fusion->io_request_frames_pool, |
179ac142 SS |
533 | GFP_KERNEL, &fusion->io_request_frames_phys); |
534 | if (!fusion->io_request_frames) { | |
e97e673c S |
535 | if (instance->max_fw_cmds >= (MEGASAS_REDUCE_QD_COUNT * 2)) { |
536 | instance->max_fw_cmds -= MEGASAS_REDUCE_QD_COUNT; | |
537 | dma_pool_destroy(fusion->io_request_frames_pool); | |
538 | megasas_configure_queue_sizes(instance); | |
539 | goto retry_alloc; | |
540 | } else { | |
541 | dev_err(&instance->pdev->dev, | |
542 | "Failed from %s %d\n", __func__, __LINE__); | |
543 | return -ENOMEM; | |
544 | } | |
545 | } | |
546 | ||
107a60dd S |
547 | if (!megasas_check_same_4gb_region(instance, |
548 | fusion->io_request_frames_phys, | |
549 | fusion->io_frames_alloc_sz)) { | |
550 | dma_pool_free(fusion->io_request_frames_pool, | |
551 | fusion->io_request_frames, | |
552 | fusion->io_request_frames_phys); | |
553 | fusion->io_request_frames = NULL; | |
554 | dma_pool_destroy(fusion->io_request_frames_pool); | |
555 | ||
556 | fusion->io_request_frames_pool = | |
557 | dma_pool_create("mr_ioreq_align", | |
558 | &instance->pdev->dev, | |
559 | fusion->io_frames_alloc_sz, | |
560 | roundup_pow_of_two(fusion->io_frames_alloc_sz), | |
561 | 0); | |
562 | ||
563 | if (!fusion->io_request_frames_pool) { | |
564 | dev_err(&instance->pdev->dev, | |
565 | "Failed from %s %d\n", __func__, __LINE__); | |
566 | return -ENOMEM; | |
567 | } | |
568 | ||
569 | fusion->io_request_frames = | |
570 | dma_pool_alloc(fusion->io_request_frames_pool, | |
571 | GFP_KERNEL, | |
572 | &fusion->io_request_frames_phys); | |
573 | ||
574 | if (!fusion->io_request_frames) { | |
575 | dev_err(&instance->pdev->dev, | |
576 | "Failed from %s %d\n", __func__, __LINE__); | |
577 | return -ENOMEM; | |
578 | } | |
579 | } | |
580 | ||
e97e673c S |
581 | fusion->req_frames_desc = |
582 | dma_alloc_coherent(&instance->pdev->dev, | |
583 | fusion->request_alloc_sz, | |
584 | &fusion->req_frames_desc_phys, GFP_KERNEL); | |
585 | if (!fusion->req_frames_desc) { | |
179ac142 SS |
586 | dev_err(&instance->pdev->dev, |
587 | "Failed from %s %d\n", __func__, __LINE__); | |
588 | return -ENOMEM; | |
589 | } | |
e97e673c | 590 | |
179ac142 SS |
591 | return 0; |
592 | } | |
593 | ||
594 | int | |
595 | megasas_alloc_reply_fusion(struct megasas_instance *instance) | |
596 | { | |
597 | int i, count; | |
598 | struct fusion_context *fusion; | |
599 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; | |
600 | fusion = instance->ctrl_context; | |
601 | ||
c8e858fe | 602 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
9c915a8c | 603 | fusion->reply_frames_desc_pool = |
fc69d86d | 604 | dma_pool_create("mr_reply", &instance->pdev->dev, |
c8e858fe | 605 | fusion->reply_alloc_sz * count, 16, 0); |
9c915a8c AR |
606 | |
607 | if (!fusion->reply_frames_desc_pool) { | |
179ac142 SS |
608 | dev_err(&instance->pdev->dev, |
609 | "Failed from %s %d\n", __func__, __LINE__); | |
610 | return -ENOMEM; | |
9c915a8c AR |
611 | } |
612 | ||
179ac142 | 613 | fusion->reply_frames_desc[0] = |
fc69d86d | 614 | dma_pool_alloc(fusion->reply_frames_desc_pool, |
179ac142 SS |
615 | GFP_KERNEL, &fusion->reply_frames_desc_phys[0]); |
616 | if (!fusion->reply_frames_desc[0]) { | |
617 | dev_err(&instance->pdev->dev, | |
618 | "Failed from %s %d\n", __func__, __LINE__); | |
619 | return -ENOMEM; | |
9c915a8c | 620 | } |
107a60dd S |
621 | |
622 | if (!megasas_check_same_4gb_region(instance, | |
623 | fusion->reply_frames_desc_phys[0], | |
624 | (fusion->reply_alloc_sz * count))) { | |
625 | dma_pool_free(fusion->reply_frames_desc_pool, | |
626 | fusion->reply_frames_desc[0], | |
627 | fusion->reply_frames_desc_phys[0]); | |
628 | fusion->reply_frames_desc[0] = NULL; | |
629 | dma_pool_destroy(fusion->reply_frames_desc_pool); | |
630 | ||
631 | fusion->reply_frames_desc_pool = | |
632 | dma_pool_create("mr_reply_align", | |
633 | &instance->pdev->dev, | |
634 | fusion->reply_alloc_sz * count, | |
635 | roundup_pow_of_two(fusion->reply_alloc_sz * count), | |
636 | 0); | |
637 | ||
638 | if (!fusion->reply_frames_desc_pool) { | |
639 | dev_err(&instance->pdev->dev, | |
640 | "Failed from %s %d\n", __func__, __LINE__); | |
641 | return -ENOMEM; | |
642 | } | |
643 | ||
644 | fusion->reply_frames_desc[0] = | |
645 | dma_pool_alloc(fusion->reply_frames_desc_pool, | |
646 | GFP_KERNEL, | |
647 | &fusion->reply_frames_desc_phys[0]); | |
648 | ||
649 | if (!fusion->reply_frames_desc[0]) { | |
650 | dev_err(&instance->pdev->dev, | |
651 | "Failed from %s %d\n", __func__, __LINE__); | |
652 | return -ENOMEM; | |
653 | } | |
654 | } | |
655 | ||
179ac142 | 656 | reply_desc = fusion->reply_frames_desc[0]; |
c8e858fe | 657 | for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++) |
c6f5bf81 | 658 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
9c915a8c | 659 | |
179ac142 SS |
660 | /* This is not a rdpq mode, but driver still populate |
661 | * reply_frame_desc array to use same msix index in ISR path. | |
662 | */ | |
663 | for (i = 0; i < (count - 1); i++) | |
664 | fusion->reply_frames_desc[i + 1] = | |
665 | fusion->reply_frames_desc[i] + | |
666 | (fusion->reply_alloc_sz)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION); | |
9c915a8c | 667 | |
179ac142 SS |
668 | return 0; |
669 | } | |
9c915a8c | 670 | |
179ac142 SS |
671 | int |
672 | megasas_alloc_rdpq_fusion(struct megasas_instance *instance) | |
673 | { | |
107a60dd | 674 | int i, j, k, msix_count; |
179ac142 SS |
675 | struct fusion_context *fusion; |
676 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; | |
107a60dd S |
677 | union MPI2_REPLY_DESCRIPTORS_UNION *rdpq_chunk_virt[RDPQ_MAX_CHUNK_COUNT]; |
678 | dma_addr_t rdpq_chunk_phys[RDPQ_MAX_CHUNK_COUNT]; | |
679 | u8 dma_alloc_count, abs_index; | |
680 | u32 chunk_size, array_size, offset; | |
179ac142 SS |
681 | |
682 | fusion = instance->ctrl_context; | |
107a60dd S |
683 | chunk_size = fusion->reply_alloc_sz * RDPQ_MAX_INDEX_IN_ONE_CHUNK; |
684 | array_size = sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * | |
685 | MAX_MSIX_QUEUES_FUSION; | |
179ac142 | 686 | |
107a60dd S |
687 | fusion->rdpq_virt = pci_alloc_consistent(instance->pdev, array_size, |
688 | &fusion->rdpq_phys); | |
179ac142 SS |
689 | if (!fusion->rdpq_virt) { |
690 | dev_err(&instance->pdev->dev, | |
691 | "Failed from %s %d\n", __func__, __LINE__); | |
692 | return -ENOMEM; | |
9c915a8c AR |
693 | } |
694 | ||
107a60dd S |
695 | memset(fusion->rdpq_virt, 0, array_size); |
696 | msix_count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; | |
697 | ||
fc69d86d RP |
698 | fusion->reply_frames_desc_pool = dma_pool_create("mr_rdpq", |
699 | &instance->pdev->dev, | |
107a60dd S |
700 | chunk_size, 16, 0); |
701 | fusion->reply_frames_desc_pool_align = | |
702 | dma_pool_create("mr_rdpq_align", | |
703 | &instance->pdev->dev, | |
704 | chunk_size, | |
705 | roundup_pow_of_two(chunk_size), | |
706 | 0); | |
707 | ||
708 | if (!fusion->reply_frames_desc_pool || | |
709 | !fusion->reply_frames_desc_pool_align) { | |
179ac142 SS |
710 | dev_err(&instance->pdev->dev, |
711 | "Failed from %s %d\n", __func__, __LINE__); | |
712 | return -ENOMEM; | |
9c915a8c AR |
713 | } |
714 | ||
107a60dd S |
715 | /* |
716 | * For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and | |
717 | * VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should be | |
718 | * within 4GB boundary and also reply queues in a set must have same | |
719 | * upper 32-bits in their memory address. so here driver is allocating the | |
720 | * DMA'able memory for reply queues according. Driver uses limitation of | |
721 | * VENTURA_SERIES to manage INVADER_SERIES as well. | |
722 | */ | |
723 | dma_alloc_count = DIV_ROUND_UP(msix_count, RDPQ_MAX_INDEX_IN_ONE_CHUNK); | |
724 | ||
725 | for (i = 0; i < dma_alloc_count; i++) { | |
726 | rdpq_chunk_virt[i] = | |
727 | dma_pool_alloc(fusion->reply_frames_desc_pool, | |
728 | GFP_KERNEL, &rdpq_chunk_phys[i]); | |
729 | if (!rdpq_chunk_virt[i]) { | |
179ac142 SS |
730 | dev_err(&instance->pdev->dev, |
731 | "Failed from %s %d\n", __func__, __LINE__); | |
732 | return -ENOMEM; | |
733 | } | |
107a60dd S |
734 | /* reply desc pool requires to be in same 4 gb region. |
735 | * Below function will check this. | |
736 | * In case of failure, new pci pool will be created with updated | |
737 | * alignment. | |
738 | * For RDPQ buffers, driver always allocate two separate pci pool. | |
739 | * Alignment will be used such a way that next allocation if | |
740 | * success, will always meet same 4gb region requirement. | |
741 | * rdpq_tracker keep track of each buffer's physical, | |
742 | * virtual address and pci pool descriptor. It will help driver | |
743 | * while freeing the resources. | |
744 | * | |
745 | */ | |
746 | if (!megasas_check_same_4gb_region(instance, rdpq_chunk_phys[i], | |
747 | chunk_size)) { | |
748 | dma_pool_free(fusion->reply_frames_desc_pool, | |
749 | rdpq_chunk_virt[i], | |
750 | rdpq_chunk_phys[i]); | |
9c915a8c | 751 | |
107a60dd S |
752 | rdpq_chunk_virt[i] = |
753 | dma_pool_alloc(fusion->reply_frames_desc_pool_align, | |
754 | GFP_KERNEL, &rdpq_chunk_phys[i]); | |
755 | if (!rdpq_chunk_virt[i]) { | |
756 | dev_err(&instance->pdev->dev, | |
757 | "Failed from %s %d\n", | |
758 | __func__, __LINE__); | |
759 | return -ENOMEM; | |
760 | } | |
761 | fusion->rdpq_tracker[i].dma_pool_ptr = | |
762 | fusion->reply_frames_desc_pool_align; | |
763 | } else { | |
764 | fusion->rdpq_tracker[i].dma_pool_ptr = | |
765 | fusion->reply_frames_desc_pool; | |
766 | } | |
179ac142 | 767 | |
107a60dd S |
768 | fusion->rdpq_tracker[i].pool_entry_phys = rdpq_chunk_phys[i]; |
769 | fusion->rdpq_tracker[i].pool_entry_virt = rdpq_chunk_virt[i]; | |
9c915a8c | 770 | } |
107a60dd S |
771 | |
772 | for (k = 0; k < dma_alloc_count; k++) { | |
773 | for (i = 0; i < RDPQ_MAX_INDEX_IN_ONE_CHUNK; i++) { | |
774 | abs_index = (k * RDPQ_MAX_INDEX_IN_ONE_CHUNK) + i; | |
775 | ||
776 | if (abs_index == msix_count) | |
777 | break; | |
778 | offset = fusion->reply_alloc_sz * i; | |
779 | fusion->rdpq_virt[abs_index].RDPQBaseAddress = | |
780 | cpu_to_le64(rdpq_chunk_phys[k] + offset); | |
781 | fusion->reply_frames_desc_phys[abs_index] = | |
782 | rdpq_chunk_phys[k] + offset; | |
783 | fusion->reply_frames_desc[abs_index] = | |
784 | (union MPI2_REPLY_DESCRIPTORS_UNION *)((u8 *)rdpq_chunk_virt[k] + offset); | |
785 | ||
786 | reply_desc = fusion->reply_frames_desc[abs_index]; | |
787 | for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++) | |
788 | reply_desc->Words = ULLONG_MAX; | |
789 | } | |
790 | } | |
791 | ||
179ac142 SS |
792 | return 0; |
793 | } | |
9c915a8c | 794 | |
179ac142 SS |
795 | static void |
796 | megasas_free_rdpq_fusion(struct megasas_instance *instance) { | |
9c915a8c | 797 | |
179ac142 SS |
798 | int i; |
799 | struct fusion_context *fusion; | |
9c915a8c | 800 | |
179ac142 SS |
801 | fusion = instance->ctrl_context; |
802 | ||
107a60dd S |
803 | for (i = 0; i < RDPQ_MAX_CHUNK_COUNT; i++) { |
804 | if (fusion->rdpq_tracker[i].pool_entry_virt) | |
805 | dma_pool_free(fusion->rdpq_tracker[i].dma_pool_ptr, | |
806 | fusion->rdpq_tracker[i].pool_entry_virt, | |
807 | fusion->rdpq_tracker[i].pool_entry_phys); | |
808 | ||
9c915a8c AR |
809 | } |
810 | ||
179ac142 | 811 | if (fusion->reply_frames_desc_pool) |
fc69d86d | 812 | dma_pool_destroy(fusion->reply_frames_desc_pool); |
107a60dd S |
813 | if (fusion->reply_frames_desc_pool_align) |
814 | dma_pool_destroy(fusion->reply_frames_desc_pool_align); | |
179ac142 SS |
815 | |
816 | if (fusion->rdpq_virt) | |
817 | pci_free_consistent(instance->pdev, | |
818 | sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION, | |
819 | fusion->rdpq_virt, fusion->rdpq_phys); | |
820 | } | |
821 | ||
822 | static void | |
823 | megasas_free_reply_fusion(struct megasas_instance *instance) { | |
824 | ||
825 | struct fusion_context *fusion; | |
826 | ||
827 | fusion = instance->ctrl_context; | |
828 | ||
829 | if (fusion->reply_frames_desc[0]) | |
fc69d86d | 830 | dma_pool_free(fusion->reply_frames_desc_pool, |
179ac142 SS |
831 | fusion->reply_frames_desc[0], |
832 | fusion->reply_frames_desc_phys[0]); | |
833 | ||
834 | if (fusion->reply_frames_desc_pool) | |
fc69d86d | 835 | dma_pool_destroy(fusion->reply_frames_desc_pool); |
179ac142 SS |
836 | |
837 | } | |
838 | ||
839 | ||
840 | /** | |
841 | * megasas_alloc_cmds_fusion - Allocates the command packets | |
842 | * @instance: Adapter soft state | |
843 | * | |
844 | * | |
845 | * Each frame has a 32-bit field called context. This context is used to get | |
846 | * back the megasas_cmd_fusion from the frame when a frame gets completed | |
847 | * In this driver, the 32 bit values are the indices into an array cmd_list. | |
848 | * This array is used only to look up the megasas_cmd_fusion given the context. | |
849 | * The free commands themselves are maintained in a linked list called cmd_pool. | |
850 | * | |
851 | * cmds are formed in the io_request and sg_frame members of the | |
852 | * megasas_cmd_fusion. The context field is used to get a request descriptor | |
853 | * and is used as SMID of the cmd. | |
854 | * SMID value range is from 1 to max_fw_cmds. | |
855 | */ | |
856 | int | |
857 | megasas_alloc_cmds_fusion(struct megasas_instance *instance) | |
858 | { | |
859 | int i; | |
860 | struct fusion_context *fusion; | |
861 | struct megasas_cmd_fusion *cmd; | |
862 | u32 offset; | |
863 | dma_addr_t io_req_base_phys; | |
864 | u8 *io_req_base; | |
865 | ||
866 | ||
867 | fusion = instance->ctrl_context; | |
868 | ||
179ac142 SS |
869 | if (megasas_alloc_request_fusion(instance)) |
870 | goto fail_exit; | |
871 | ||
872 | if (instance->is_rdpq) { | |
873 | if (megasas_alloc_rdpq_fusion(instance)) | |
874 | goto fail_exit; | |
875 | } else | |
876 | if (megasas_alloc_reply_fusion(instance)) | |
877 | goto fail_exit; | |
878 | ||
e97e673c S |
879 | if (megasas_alloc_cmdlist_fusion(instance)) |
880 | goto fail_exit; | |
881 | ||
882 | dev_info(&instance->pdev->dev, "Configured max firmware commands: %d\n", | |
883 | instance->max_fw_cmds); | |
179ac142 SS |
884 | |
885 | /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */ | |
886 | io_req_base = fusion->io_request_frames + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; | |
887 | io_req_base_phys = fusion->io_request_frames_phys + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; | |
9c915a8c AR |
888 | |
889 | /* | |
890 | * Add all the commands to command pool (fusion->cmd_pool) | |
891 | */ | |
892 | ||
893 | /* SMID 0 is reserved. Set SMID/index from 1 */ | |
69c337c0 | 894 | for (i = 0; i < instance->max_mpt_cmds; i++) { |
9c915a8c AR |
895 | cmd = fusion->cmd_list[i]; |
896 | offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i; | |
897 | memset(cmd, 0, sizeof(struct megasas_cmd_fusion)); | |
898 | cmd->index = i + 1; | |
899 | cmd->scmd = NULL; | |
69c337c0 SC |
900 | cmd->sync_cmd_idx = |
901 | (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ? | |
4026e9aa SS |
902 | (i - instance->max_scsi_cmds) : |
903 | (u32)ULONG_MAX; /* Set to Invalid */ | |
9c915a8c AR |
904 | cmd->instance = instance; |
905 | cmd->io_request = | |
906 | (struct MPI2_RAID_SCSI_IO_REQUEST *) | |
907 | (io_req_base + offset); | |
908 | memset(cmd->io_request, 0, | |
909 | sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); | |
910 | cmd->io_request_phys_addr = io_req_base_phys + offset; | |
8bf7c65d | 911 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
9c915a8c AR |
912 | } |
913 | ||
179ac142 SS |
914 | if (megasas_create_sg_sense_fusion(instance)) |
915 | goto fail_exit; | |
9c915a8c AR |
916 | |
917 | return 0; | |
918 | ||
179ac142 SS |
919 | fail_exit: |
920 | megasas_free_cmds_fusion(instance); | |
9c915a8c AR |
921 | return -ENOMEM; |
922 | } | |
923 | ||
924 | /** | |
925 | * wait_and_poll - Issues a polling command | |
926 | * @instance: Adapter soft state | |
927 | * @cmd: Command packet to be issued | |
928 | * | |
929 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. | |
930 | */ | |
931 | int | |
229fe47c AR |
932 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
933 | int seconds) | |
9c915a8c AR |
934 | { |
935 | int i; | |
936 | struct megasas_header *frame_hdr = &cmd->frame->hdr; | |
90dc9d98 | 937 | struct fusion_context *fusion; |
9c915a8c | 938 | |
229fe47c | 939 | u32 msecs = seconds * 1000; |
9c915a8c | 940 | |
90dc9d98 | 941 | fusion = instance->ctrl_context; |
9c915a8c AR |
942 | /* |
943 | * Wait for cmd_status to change | |
944 | */ | |
945 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) { | |
946 | rmb(); | |
947 | msleep(20); | |
948 | } | |
949 | ||
6d40afbc SS |
950 | if (frame_hdr->cmd_status == MFI_STAT_INVALID_STATUS) |
951 | return DCMD_TIMEOUT; | |
952 | else if (frame_hdr->cmd_status == MFI_STAT_OK) | |
953 | return DCMD_SUCCESS; | |
954 | else | |
955 | return DCMD_FAILED; | |
9c915a8c AR |
956 | } |
957 | ||
958 | /** | |
959 | * megasas_ioc_init_fusion - Initializes the FW | |
960 | * @instance: Adapter soft state | |
961 | * | |
962 | * Issues the IOC Init cmd | |
963 | */ | |
964 | int | |
965 | megasas_ioc_init_fusion(struct megasas_instance *instance) | |
966 | { | |
967 | struct megasas_init_frame *init_frame; | |
179ac142 | 968 | struct MPI2_IOC_INIT_REQUEST *IOCInitMessage = NULL; |
9c915a8c | 969 | dma_addr_t ioc_init_handle; |
9c915a8c | 970 | struct megasas_cmd *cmd; |
179ac142 | 971 | u8 ret, cur_rdpq_mode; |
9c915a8c | 972 | struct fusion_context *fusion; |
c77a9bd8 | 973 | union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc; |
9c915a8c AR |
974 | int i; |
975 | struct megasas_header *frame_hdr; | |
5765c5b8 | 976 | const char *sys_info; |
4dbbe3ce | 977 | MFI_CAPABILITIES *drv_ops; |
179ac142 | 978 | u32 scratch_pad_2; |
b99fc202 | 979 | struct timeval tv; |
107a60dd | 980 | bool cur_fw_64bit_dma_capable; |
9c915a8c AR |
981 | |
982 | fusion = instance->ctrl_context; | |
983 | ||
9b3d028f S |
984 | ioc_init_handle = fusion->ioc_init_request_phys; |
985 | IOCInitMessage = fusion->ioc_init_request; | |
9c915a8c | 986 | |
b9637d14 | 987 | cmd = fusion->ioc_init_cmd; |
9c915a8c | 988 | |
179ac142 SS |
989 | scratch_pad_2 = readl |
990 | (&instance->reg_set->outbound_scratch_pad_2); | |
991 | ||
992 | cur_rdpq_mode = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? 1 : 0; | |
993 | ||
107a60dd S |
994 | if (instance->adapter_type == INVADER_SERIES) { |
995 | cur_fw_64bit_dma_capable = | |
996 | (scratch_pad_2 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET) ? true : false; | |
997 | ||
998 | if (instance->consistent_mask_64bit && !cur_fw_64bit_dma_capable) { | |
999 | dev_err(&instance->pdev->dev, "Driver was operating on 64bit " | |
1000 | "DMA mask, but upcoming FW does not support 64bit DMA mask\n"); | |
1001 | megaraid_sas_kill_hba(instance); | |
1002 | ret = 1; | |
1003 | goto fail_fw_init; | |
1004 | } | |
1005 | } | |
1006 | ||
179ac142 SS |
1007 | if (instance->is_rdpq && !cur_rdpq_mode) { |
1008 | dev_err(&instance->pdev->dev, "Firmware downgrade *NOT SUPPORTED*" | |
1009 | " from RDPQ mode to non RDPQ mode\n"); | |
1010 | ret = 1; | |
1011 | goto fail_fw_init; | |
1012 | } | |
1013 | ||
d0fc91d6 KD |
1014 | instance->fw_sync_cache_support = (scratch_pad_2 & |
1015 | MR_CAN_HANDLE_SYNC_CACHE_OFFSET) ? 1 : 0; | |
1016 | dev_info(&instance->pdev->dev, "FW supports sync cache\t: %s\n", | |
1017 | instance->fw_sync_cache_support ? "Yes" : "No"); | |
1018 | ||
9c915a8c AR |
1019 | memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST)); |
1020 | ||
1021 | IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT; | |
1022 | IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER; | |
94cd65dd SS |
1023 | IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION); |
1024 | IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); | |
1025 | IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4); | |
1026 | ||
1027 | IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth); | |
179ac142 SS |
1028 | IOCInitMessage->ReplyDescriptorPostQueueAddress = instance->is_rdpq ? |
1029 | cpu_to_le64(fusion->rdpq_phys) : | |
1030 | cpu_to_le64(fusion->reply_frames_desc_phys[0]); | |
1031 | IOCInitMessage->MsgFlags = instance->is_rdpq ? | |
1032 | MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0; | |
94cd65dd | 1033 | IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys); |
107a60dd | 1034 | IOCInitMessage->SenseBufferAddressHigh = cpu_to_le32(upper_32_bits(fusion->sense_phys_addr)); |
5738f996 | 1035 | IOCInitMessage->HostMSIxVectors = instance->msix_vectors; |
15dd0381 | 1036 | IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT; |
b99fc202 S |
1037 | |
1038 | do_gettimeofday(&tv); | |
1039 | /* Convert to milliseconds as per FW requirement */ | |
1040 | IOCInitMessage->TimeStamp = cpu_to_le64((tv.tv_sec * 1000) + | |
1041 | (tv.tv_usec / 1000)); | |
1042 | ||
9c915a8c AR |
1043 | init_frame = (struct megasas_init_frame *)cmd->frame; |
1044 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); | |
1045 | ||
1046 | frame_hdr = &cmd->frame->hdr; | |
9c915a8c | 1047 | frame_hdr->cmd_status = 0xFF; |
48433bd7 CH |
1048 | frame_hdr->flags = cpu_to_le16( |
1049 | le16_to_cpu(frame_hdr->flags) | | |
1050 | MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); | |
9c915a8c AR |
1051 | |
1052 | init_frame->cmd = MFI_CMD_INIT; | |
1053 | init_frame->cmd_status = 0xFF; | |
1054 | ||
4dbbe3ce | 1055 | drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations); |
1056 | ||
d46a3ad6 | 1057 | /* driver support Extended MSIX */ |
c365178f | 1058 | if (instance->adapter_type >= INVADER_SERIES) |
4dbbe3ce | 1059 | drv_ops->mfi_capabilities.support_additional_msix = 1; |
21c9e160 | 1060 | /* driver supports HA / Remote LUN over Fast Path interface */ |
4dbbe3ce | 1061 | drv_ops->mfi_capabilities.support_fp_remote_lun = 1; |
1062 | ||
1063 | drv_ops->mfi_capabilities.support_max_255lds = 1; | |
1064 | drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1; | |
1065 | drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1; | |
1066 | ||
bd5f9484 | 1067 | if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN) |
1068 | drv_ops->mfi_capabilities.support_ext_io_size = 1; | |
1069 | ||
8f05024c | 1070 | drv_ops->mfi_capabilities.support_fp_rlbypass = 1; |
308ec459 SS |
1071 | if (!dual_qdepth_disable) |
1072 | drv_ops->mfi_capabilities.support_ext_queue_depth = 1; | |
8f05024c | 1073 | |
52b62ac7 | 1074 | drv_ops->mfi_capabilities.support_qd_throttling = 1; |
ede7c3ce | 1075 | drv_ops->mfi_capabilities.support_pd_map_target_id = 1; |
107a60dd S |
1076 | |
1077 | if (instance->consistent_mask_64bit) | |
1078 | drv_ops->mfi_capabilities.support_64bit_mode = 1; | |
1079 | ||
94cd65dd SS |
1080 | /* Convert capability to LE32 */ |
1081 | cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities); | |
21c9e160 | 1082 | |
5765c5b8 SS |
1083 | sys_info = dmi_get_system_info(DMI_PRODUCT_UUID); |
1084 | if (instance->system_info_buf && sys_info) { | |
1085 | memcpy(instance->system_info_buf->systemId, sys_info, | |
1086 | strlen(sys_info) > 64 ? 64 : strlen(sys_info)); | |
1087 | instance->system_info_buf->systemIdLength = | |
1088 | strlen(sys_info) > 64 ? 64 : strlen(sys_info); | |
107a60dd S |
1089 | init_frame->system_info_lo = cpu_to_le32(lower_32_bits(instance->system_info_h)); |
1090 | init_frame->system_info_hi = cpu_to_le32(upper_32_bits(instance->system_info_h)); | |
5765c5b8 SS |
1091 | } |
1092 | ||
fdc5a97c HR |
1093 | init_frame->queue_info_new_phys_addr_hi = |
1094 | cpu_to_le32(upper_32_bits(ioc_init_handle)); | |
1095 | init_frame->queue_info_new_phys_addr_lo = | |
1096 | cpu_to_le32(lower_32_bits(ioc_init_handle)); | |
94cd65dd | 1097 | init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST)); |
9c915a8c | 1098 | |
200aed58 SS |
1099 | req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr)); |
1100 | req_desc.u.high = cpu_to_le32(upper_32_bits(cmd->frame_phys_addr)); | |
c77a9bd8 | 1101 | req_desc.MFAIo.RequestFlags = |
9c915a8c | 1102 | (MEGASAS_REQ_DESCRIPT_FLAGS_MFA << |
200aed58 | 1103 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
9c915a8c AR |
1104 | |
1105 | /* | |
1106 | * disable the intr before firing the init frame | |
1107 | */ | |
d46a3ad6 | 1108 | instance->instancet->disable_intr(instance); |
9c915a8c AR |
1109 | |
1110 | for (i = 0; i < (10 * 1000); i += 20) { | |
1111 | if (readl(&instance->reg_set->doorbell) & 1) | |
1112 | msleep(20); | |
1113 | else | |
1114 | break; | |
1115 | } | |
1116 | ||
2ff925cb | 1117 | megasas_fire_cmd_fusion(instance, &req_desc); |
9c915a8c | 1118 | |
229fe47c | 1119 | wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS); |
9c915a8c AR |
1120 | |
1121 | frame_hdr = &cmd->frame->hdr; | |
1122 | if (frame_hdr->cmd_status != 0) { | |
1123 | ret = 1; | |
1124 | goto fail_fw_init; | |
1125 | } | |
9c915a8c | 1126 | |
b78a4d54 | 1127 | return 0; |
9c915a8c AR |
1128 | |
1129 | fail_fw_init: | |
2d2c2331 | 1130 | dev_err(&instance->pdev->dev, |
b78a4d54 VL |
1131 | "Init cmd return status FAILED for SCSI host %d\n", |
1132 | instance->host->host_no); | |
2d2c2331 | 1133 | |
9c915a8c AR |
1134 | return ret; |
1135 | } | |
1136 | ||
3761cb4c | 1137 | /** |
1138 | * megasas_sync_pd_seq_num - JBOD SEQ MAP | |
1139 | * @instance: Adapter soft state | |
1140 | * @pend: set to 1, if it is pended jbod map. | |
1141 | * | |
1142 | * Issue Jbod map to the firmware. If it is pended command, | |
1143 | * issue command and return. If it is first instance of jbod map | |
1144 | * issue and receive command. | |
1145 | */ | |
1146 | int | |
1147 | megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { | |
1148 | int ret = 0; | |
1149 | u32 pd_seq_map_sz; | |
1150 | struct megasas_cmd *cmd; | |
1151 | struct megasas_dcmd_frame *dcmd; | |
1152 | struct fusion_context *fusion = instance->ctrl_context; | |
1153 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; | |
1154 | dma_addr_t pd_seq_h; | |
1155 | ||
1156 | pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)]; | |
1157 | pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)]; | |
1158 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + | |
1159 | (sizeof(struct MR_PD_CFG_SEQ) * | |
1160 | (MAX_PHYSICAL_DEVICES - 1)); | |
1161 | ||
1162 | cmd = megasas_get_cmd(instance); | |
1163 | if (!cmd) { | |
1164 | dev_err(&instance->pdev->dev, | |
1165 | "Could not get mfi cmd. Fail from %s %d\n", | |
1166 | __func__, __LINE__); | |
1167 | return -ENOMEM; | |
1168 | } | |
1169 | ||
1170 | dcmd = &cmd->frame->dcmd; | |
1171 | ||
1172 | memset(pd_sync, 0, pd_seq_map_sz); | |
1173 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
107a60dd S |
1174 | |
1175 | if (pend) { | |
1176 | dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG; | |
1177 | dcmd->flags = MFI_FRAME_DIR_WRITE; | |
1178 | instance->jbod_seq_cmd = cmd; | |
1179 | } else { | |
1180 | dcmd->flags = MFI_FRAME_DIR_READ; | |
1181 | } | |
1182 | ||
3761cb4c | 1183 | dcmd->cmd = MFI_CMD_DCMD; |
1184 | dcmd->cmd_status = 0xFF; | |
1185 | dcmd->sge_count = 1; | |
1186 | dcmd->timeout = 0; | |
1187 | dcmd->pad_0 = 0; | |
1188 | dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz); | |
1189 | dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO); | |
107a60dd S |
1190 | |
1191 | megasas_set_dma_settings(instance, dcmd, pd_seq_h, pd_seq_map_sz); | |
3761cb4c | 1192 | |
1193 | if (pend) { | |
3761cb4c | 1194 | instance->instancet->issue_dcmd(instance, cmd); |
1195 | return 0; | |
1196 | } | |
1197 | ||
3761cb4c | 1198 | /* Below code is only for non pended DCMD */ |
55fecaec | 1199 | if (!instance->mask_interrupts) |
6d40afbc SS |
1200 | ret = megasas_issue_blocked_cmd(instance, cmd, |
1201 | MFI_IO_TIMEOUT_SECS); | |
3761cb4c | 1202 | else |
1203 | ret = megasas_issue_polled(instance, cmd); | |
1204 | ||
1205 | if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) { | |
1206 | dev_warn(&instance->pdev->dev, | |
1207 | "driver supports max %d JBOD, but FW reports %d\n", | |
1208 | MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count)); | |
1209 | ret = -EINVAL; | |
1210 | } | |
1211 | ||
55fecaec | 1212 | if (ret == DCMD_TIMEOUT) |
6d40afbc SS |
1213 | megaraid_sas_kill_hba(instance); |
1214 | ||
1215 | if (ret == DCMD_SUCCESS) | |
3761cb4c | 1216 | instance->pd_seq_map_id++; |
1217 | ||
1218 | megasas_return_cmd(instance, cmd); | |
1219 | return ret; | |
1220 | } | |
1221 | ||
9c915a8c AR |
1222 | /* |
1223 | * megasas_get_ld_map_info - Returns FW's ld_map structure | |
1224 | * @instance: Adapter soft state | |
1225 | * @pend: Pend the command or not | |
1226 | * Issues an internal command (DCMD) to get the FW's controller PD | |
1227 | * list structure. This information is mainly used to find out SYSTEM | |
1228 | * supported by the FW. | |
51087a86 SS |
1229 | * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO |
1230 | * dcmd.mbox.b[0] - number of LDs being sync'd | |
1231 | * dcmd.mbox.b[1] - 0 - complete command immediately. | |
1232 | * - 1 - pend till config change | |
1233 | * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP | |
1234 | * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and | |
1235 | * uses extended struct MR_FW_RAID_MAP_EXT | |
9c915a8c AR |
1236 | */ |
1237 | static int | |
1238 | megasas_get_ld_map_info(struct megasas_instance *instance) | |
1239 | { | |
1240 | int ret = 0; | |
1241 | struct megasas_cmd *cmd; | |
1242 | struct megasas_dcmd_frame *dcmd; | |
51087a86 | 1243 | void *ci; |
9c915a8c AR |
1244 | dma_addr_t ci_h = 0; |
1245 | u32 size_map_info; | |
1246 | struct fusion_context *fusion; | |
1247 | ||
1248 | cmd = megasas_get_cmd(instance); | |
1249 | ||
1250 | if (!cmd) { | |
1be18254 | 1251 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n"); |
9c915a8c AR |
1252 | return -ENOMEM; |
1253 | } | |
1254 | ||
1255 | fusion = instance->ctrl_context; | |
1256 | ||
1257 | if (!fusion) { | |
1258 | megasas_return_cmd(instance, cmd); | |
2f8bdfa8 | 1259 | return -ENXIO; |
9c915a8c AR |
1260 | } |
1261 | ||
1262 | dcmd = &cmd->frame->dcmd; | |
1263 | ||
51087a86 | 1264 | size_map_info = fusion->current_map_sz; |
9c915a8c | 1265 | |
51087a86 | 1266 | ci = (void *) fusion->ld_map[(instance->map_id & 1)]; |
9c915a8c AR |
1267 | ci_h = fusion->ld_map_phys[(instance->map_id & 1)]; |
1268 | ||
1269 | if (!ci) { | |
1be18254 | 1270 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n"); |
9c915a8c AR |
1271 | megasas_return_cmd(instance, cmd); |
1272 | return -ENOMEM; | |
1273 | } | |
1274 | ||
51087a86 | 1275 | memset(ci, 0, fusion->max_map_sz); |
9c915a8c | 1276 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
9c915a8c AR |
1277 | dcmd->cmd = MFI_CMD_DCMD; |
1278 | dcmd->cmd_status = 0xFF; | |
1279 | dcmd->sge_count = 1; | |
107a60dd | 1280 | dcmd->flags = MFI_FRAME_DIR_READ; |
9c915a8c AR |
1281 | dcmd->timeout = 0; |
1282 | dcmd->pad_0 = 0; | |
94cd65dd SS |
1283 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
1284 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); | |
9c915a8c | 1285 | |
107a60dd | 1286 | megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info); |
9c915a8c | 1287 | |
55fecaec | 1288 | if (!instance->mask_interrupts) |
90dc9d98 | 1289 | ret = megasas_issue_blocked_cmd(instance, cmd, |
6d40afbc | 1290 | MFI_IO_TIMEOUT_SECS); |
90dc9d98 SS |
1291 | else |
1292 | ret = megasas_issue_polled(instance, cmd); | |
9c915a8c | 1293 | |
55fecaec | 1294 | if (ret == DCMD_TIMEOUT) |
6d40afbc SS |
1295 | megaraid_sas_kill_hba(instance); |
1296 | ||
4026e9aa | 1297 | megasas_return_cmd(instance, cmd); |
9c915a8c AR |
1298 | |
1299 | return ret; | |
1300 | } | |
1301 | ||
1302 | u8 | |
1303 | megasas_get_map_info(struct megasas_instance *instance) | |
1304 | { | |
1305 | struct fusion_context *fusion = instance->ctrl_context; | |
1306 | ||
1307 | fusion->fast_path_io = 0; | |
1308 | if (!megasas_get_ld_map_info(instance)) { | |
bc93d425 | 1309 | if (MR_ValidateMapInfo(instance)) { |
9c915a8c AR |
1310 | fusion->fast_path_io = 1; |
1311 | return 0; | |
1312 | } | |
1313 | } | |
1314 | return 1; | |
1315 | } | |
1316 | ||
1317 | /* | |
1318 | * megasas_sync_map_info - Returns FW's ld_map structure | |
1319 | * @instance: Adapter soft state | |
1320 | * | |
1321 | * Issues an internal command (DCMD) to get the FW's controller PD | |
1322 | * list structure. This information is mainly used to find out SYSTEM | |
1323 | * supported by the FW. | |
1324 | */ | |
1325 | int | |
1326 | megasas_sync_map_info(struct megasas_instance *instance) | |
1327 | { | |
f4fc2093 | 1328 | int i; |
9c915a8c AR |
1329 | struct megasas_cmd *cmd; |
1330 | struct megasas_dcmd_frame *dcmd; | |
d2d0358b S |
1331 | u16 num_lds; |
1332 | u32 size_sync_info; | |
9c915a8c AR |
1333 | struct fusion_context *fusion; |
1334 | struct MR_LD_TARGET_SYNC *ci = NULL; | |
51087a86 | 1335 | struct MR_DRV_RAID_MAP_ALL *map; |
9c915a8c AR |
1336 | struct MR_LD_RAID *raid; |
1337 | struct MR_LD_TARGET_SYNC *ld_sync; | |
1338 | dma_addr_t ci_h = 0; | |
1339 | u32 size_map_info; | |
1340 | ||
1341 | cmd = megasas_get_cmd(instance); | |
1342 | ||
1343 | if (!cmd) { | |
1be18254 | 1344 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n"); |
9c915a8c AR |
1345 | return -ENOMEM; |
1346 | } | |
1347 | ||
1348 | fusion = instance->ctrl_context; | |
1349 | ||
1350 | if (!fusion) { | |
1351 | megasas_return_cmd(instance, cmd); | |
1352 | return 1; | |
1353 | } | |
1354 | ||
51087a86 | 1355 | map = fusion->ld_drv_map[instance->map_id & 1]; |
9c915a8c | 1356 | |
6e755ddc | 1357 | num_lds = le16_to_cpu(map->raidMap.ldCount); |
9c915a8c AR |
1358 | |
1359 | dcmd = &cmd->frame->dcmd; | |
1360 | ||
1361 | size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds; | |
1362 | ||
1363 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
1364 | ||
1365 | ci = (struct MR_LD_TARGET_SYNC *) | |
1366 | fusion->ld_map[(instance->map_id - 1) & 1]; | |
51087a86 | 1367 | memset(ci, 0, fusion->max_map_sz); |
9c915a8c AR |
1368 | |
1369 | ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1]; | |
1370 | ||
1371 | ld_sync = (struct MR_LD_TARGET_SYNC *)ci; | |
1372 | ||
1373 | for (i = 0; i < num_lds; i++, ld_sync++) { | |
1374 | raid = MR_LdRaidGet(i, map); | |
1375 | ld_sync->targetId = MR_GetLDTgtId(i, map); | |
1376 | ld_sync->seqNum = raid->seqNum; | |
1377 | } | |
1378 | ||
51087a86 | 1379 | size_map_info = fusion->current_map_sz; |
9c915a8c AR |
1380 | |
1381 | dcmd->cmd = MFI_CMD_DCMD; | |
1382 | dcmd->cmd_status = 0xFF; | |
1383 | dcmd->sge_count = 1; | |
107a60dd | 1384 | dcmd->flags = MFI_FRAME_DIR_WRITE; |
9c915a8c AR |
1385 | dcmd->timeout = 0; |
1386 | dcmd->pad_0 = 0; | |
94cd65dd | 1387 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
9c915a8c AR |
1388 | dcmd->mbox.b[0] = num_lds; |
1389 | dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG; | |
94cd65dd | 1390 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
107a60dd S |
1391 | |
1392 | megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info); | |
9c915a8c AR |
1393 | |
1394 | instance->map_update_cmd = cmd; | |
1395 | ||
1396 | instance->instancet->issue_dcmd(instance, cmd); | |
1397 | ||
f4fc2093 | 1398 | return 0; |
9c915a8c AR |
1399 | } |
1400 | ||
39b72c3c SS |
1401 | /* |
1402 | * meagasas_display_intel_branding - Display branding string | |
1403 | * @instance: per adapter object | |
1404 | * | |
1405 | * Return nothing. | |
1406 | */ | |
1407 | static void | |
1408 | megasas_display_intel_branding(struct megasas_instance *instance) | |
1409 | { | |
1410 | if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) | |
1411 | return; | |
1412 | ||
1413 | switch (instance->pdev->device) { | |
1414 | case PCI_DEVICE_ID_LSI_INVADER: | |
1415 | switch (instance->pdev->subsystem_device) { | |
1416 | case MEGARAID_INTEL_RS3DC080_SSDID: | |
1417 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1418 | instance->host->host_no, | |
1419 | MEGARAID_INTEL_RS3DC080_BRANDING); | |
1420 | break; | |
1421 | case MEGARAID_INTEL_RS3DC040_SSDID: | |
1422 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1423 | instance->host->host_no, | |
1424 | MEGARAID_INTEL_RS3DC040_BRANDING); | |
1425 | break; | |
1426 | case MEGARAID_INTEL_RS3SC008_SSDID: | |
1427 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1428 | instance->host->host_no, | |
1429 | MEGARAID_INTEL_RS3SC008_BRANDING); | |
1430 | break; | |
1431 | case MEGARAID_INTEL_RS3MC044_SSDID: | |
1432 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1433 | instance->host->host_no, | |
1434 | MEGARAID_INTEL_RS3MC044_BRANDING); | |
1435 | break; | |
1436 | default: | |
1437 | break; | |
1438 | } | |
1439 | break; | |
1440 | case PCI_DEVICE_ID_LSI_FURY: | |
1441 | switch (instance->pdev->subsystem_device) { | |
1442 | case MEGARAID_INTEL_RS3WC080_SSDID: | |
1443 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1444 | instance->host->host_no, | |
1445 | MEGARAID_INTEL_RS3WC080_BRANDING); | |
1446 | break; | |
1447 | case MEGARAID_INTEL_RS3WC040_SSDID: | |
1448 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1449 | instance->host->host_no, | |
1450 | MEGARAID_INTEL_RS3WC040_BRANDING); | |
1451 | break; | |
1452 | default: | |
1453 | break; | |
1454 | } | |
1455 | break; | |
7364d34b | 1456 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
1457 | case PCI_DEVICE_ID_LSI_CUTLASS_53: | |
1458 | switch (instance->pdev->subsystem_device) { | |
1459 | case MEGARAID_INTEL_RMS3BC160_SSDID: | |
1460 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", | |
1461 | instance->host->host_no, | |
1462 | MEGARAID_INTEL_RMS3BC160_BRANDING); | |
1463 | break; | |
1464 | default: | |
1465 | break; | |
1466 | } | |
1467 | break; | |
39b72c3c SS |
1468 | default: |
1469 | break; | |
1470 | } | |
1471 | } | |
1472 | ||
def3e8df S |
1473 | /** |
1474 | * megasas_allocate_raid_maps - Allocate memory for RAID maps | |
1475 | * @instance: Adapter soft state | |
1476 | * | |
1477 | * return: if success: return 0 | |
1478 | * failed: return -ENOMEM | |
1479 | */ | |
1480 | static inline int megasas_allocate_raid_maps(struct megasas_instance *instance) | |
1481 | { | |
1482 | struct fusion_context *fusion; | |
1483 | int i = 0; | |
1484 | ||
1485 | fusion = instance->ctrl_context; | |
1486 | ||
1487 | fusion->drv_map_pages = get_order(fusion->drv_map_sz); | |
1488 | ||
1489 | for (i = 0; i < 2; i++) { | |
1490 | fusion->ld_map[i] = NULL; | |
1491 | ||
1492 | fusion->ld_drv_map[i] = (void *) | |
1493 | __get_free_pages(__GFP_ZERO | GFP_KERNEL, | |
1494 | fusion->drv_map_pages); | |
1495 | ||
1496 | if (!fusion->ld_drv_map[i]) { | |
1497 | fusion->ld_drv_map[i] = vzalloc(fusion->drv_map_sz); | |
1498 | ||
1499 | if (!fusion->ld_drv_map[i]) { | |
1500 | dev_err(&instance->pdev->dev, | |
1501 | "Could not allocate memory for local map" | |
1502 | " size requested: %d\n", | |
1503 | fusion->drv_map_sz); | |
1504 | goto ld_drv_map_alloc_fail; | |
1505 | } | |
1506 | } | |
1507 | } | |
1508 | ||
1509 | for (i = 0; i < 2; i++) { | |
1510 | fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev, | |
1511 | fusion->max_map_sz, | |
1512 | &fusion->ld_map_phys[i], | |
1513 | GFP_KERNEL); | |
1514 | if (!fusion->ld_map[i]) { | |
1515 | dev_err(&instance->pdev->dev, | |
1516 | "Could not allocate memory for map info %s:%d\n", | |
1517 | __func__, __LINE__); | |
1518 | goto ld_map_alloc_fail; | |
1519 | } | |
1520 | } | |
1521 | ||
1522 | return 0; | |
1523 | ||
1524 | ld_map_alloc_fail: | |
1525 | for (i = 0; i < 2; i++) { | |
1526 | if (fusion->ld_map[i]) | |
1527 | dma_free_coherent(&instance->pdev->dev, | |
1528 | fusion->max_map_sz, | |
1529 | fusion->ld_map[i], | |
1530 | fusion->ld_map_phys[i]); | |
1531 | } | |
1532 | ||
1533 | ld_drv_map_alloc_fail: | |
1534 | for (i = 0; i < 2; i++) { | |
1535 | if (fusion->ld_drv_map[i]) { | |
1536 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) | |
1537 | vfree(fusion->ld_drv_map[i]); | |
1538 | else | |
1539 | free_pages((ulong)fusion->ld_drv_map[i], | |
1540 | fusion->drv_map_pages); | |
1541 | } | |
1542 | } | |
1543 | ||
1544 | return -ENOMEM; | |
1545 | } | |
1546 | ||
e97e673c S |
1547 | /** |
1548 | * megasas_configure_queue_sizes - Calculate size of request desc queue, | |
1549 | * reply desc queue, | |
1550 | * IO request frame queue, set can_queue. | |
1551 | * @instance: Adapter soft state | |
1552 | * @return: void | |
1553 | */ | |
1554 | static inline | |
1555 | void megasas_configure_queue_sizes(struct megasas_instance *instance) | |
1556 | { | |
1557 | struct fusion_context *fusion; | |
1558 | u16 max_cmd; | |
1559 | ||
1560 | fusion = instance->ctrl_context; | |
1561 | max_cmd = instance->max_fw_cmds; | |
1562 | ||
1563 | if (instance->adapter_type == VENTURA_SERIES) | |
1564 | instance->max_mpt_cmds = instance->max_fw_cmds * RAID_1_PEER_CMDS; | |
1565 | else | |
1566 | instance->max_mpt_cmds = instance->max_fw_cmds; | |
1567 | ||
1568 | instance->max_scsi_cmds = instance->max_fw_cmds - | |
1569 | (MEGASAS_FUSION_INTERNAL_CMDS + | |
1570 | MEGASAS_FUSION_IOCTL_CMDS); | |
1571 | instance->cur_can_queue = instance->max_scsi_cmds; | |
1572 | instance->host->can_queue = instance->cur_can_queue; | |
1573 | ||
1574 | fusion->reply_q_depth = 2 * ((max_cmd + 1 + 15) / 16) * 16; | |
1575 | ||
1576 | fusion->request_alloc_sz = sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * | |
1577 | instance->max_mpt_cmds; | |
1578 | fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) * | |
1579 | (fusion->reply_q_depth); | |
1580 | fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE + | |
1581 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE | |
1582 | * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */ | |
1583 | } | |
1584 | ||
b9637d14 S |
1585 | static int megasas_alloc_ioc_init_frame(struct megasas_instance *instance) |
1586 | { | |
1587 | struct fusion_context *fusion; | |
1588 | struct megasas_cmd *cmd; | |
1589 | ||
1590 | fusion = instance->ctrl_context; | |
1591 | ||
1592 | cmd = kmalloc(sizeof(struct megasas_cmd), GFP_KERNEL); | |
1593 | ||
1594 | if (!cmd) { | |
1595 | dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n", | |
1596 | __func__, __LINE__); | |
1597 | return -ENOMEM; | |
1598 | } | |
1599 | ||
1600 | cmd->frame = dma_alloc_coherent(&instance->pdev->dev, | |
1601 | IOC_INIT_FRAME_SIZE, | |
1602 | &cmd->frame_phys_addr, GFP_KERNEL); | |
1603 | ||
1604 | if (!cmd->frame) { | |
1605 | dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n", | |
1606 | __func__, __LINE__); | |
1607 | kfree(cmd); | |
1608 | return -ENOMEM; | |
1609 | } | |
1610 | ||
1611 | fusion->ioc_init_cmd = cmd; | |
1612 | return 0; | |
1613 | } | |
1614 | ||
1615 | /** | |
1616 | * megasas_free_ioc_init_cmd - Free IOC INIT command frame | |
1617 | * @instance: Adapter soft state | |
1618 | */ | |
1619 | static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance) | |
1620 | { | |
1621 | struct fusion_context *fusion; | |
1622 | ||
1623 | fusion = instance->ctrl_context; | |
1624 | ||
1625 | if (fusion->ioc_init_cmd && fusion->ioc_init_cmd->frame) | |
1626 | dma_free_coherent(&instance->pdev->dev, | |
1627 | IOC_INIT_FRAME_SIZE, | |
1628 | fusion->ioc_init_cmd->frame, | |
1629 | fusion->ioc_init_cmd->frame_phys_addr); | |
1630 | ||
1631 | if (fusion->ioc_init_cmd) | |
1632 | kfree(fusion->ioc_init_cmd); | |
1633 | } | |
1634 | ||
9c915a8c AR |
1635 | /** |
1636 | * megasas_init_adapter_fusion - Initializes the FW | |
1637 | * @instance: Adapter soft state | |
1638 | * | |
1639 | * This is the main function for initializing firmware. | |
1640 | */ | |
1641 | u32 | |
1642 | megasas_init_adapter_fusion(struct megasas_instance *instance) | |
1643 | { | |
1644 | struct megasas_register_set __iomem *reg_set; | |
1645 | struct fusion_context *fusion; | |
50b7f5a2 | 1646 | u32 scratch_pad_2; |
c8e858fe | 1647 | int i = 0, count; |
9c915a8c AR |
1648 | |
1649 | fusion = instance->ctrl_context; | |
1650 | ||
1651 | reg_set = instance->reg_set; | |
1652 | ||
308ec459 | 1653 | megasas_fusion_update_can_queue(instance, PROBE_CONTEXT); |
9c915a8c | 1654 | |
ae09a6c1 SS |
1655 | /* |
1656 | * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames | |
1657 | */ | |
1658 | instance->max_mfi_cmds = | |
1659 | MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS; | |
9c915a8c | 1660 | |
e97e673c | 1661 | megasas_configure_queue_sizes(instance); |
9c915a8c | 1662 | |
bd5f9484 | 1663 | scratch_pad_2 = readl(&instance->reg_set->outbound_scratch_pad_2); |
1664 | /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set, | |
1665 | * Firmware support extended IO chain frame which is 4 times more than | |
1666 | * legacy Firmware. | |
1667 | * Legacy Firmware - Frame size is (8 * 128) = 1K | |
1668 | * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K | |
1669 | */ | |
1670 | if (scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK) | |
1671 | instance->max_chain_frame_sz = | |
1672 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> | |
1673 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO; | |
1674 | else | |
1675 | instance->max_chain_frame_sz = | |
1676 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> | |
1677 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO; | |
1678 | ||
1679 | if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) { | |
1680 | dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n", | |
1681 | instance->max_chain_frame_sz, | |
1682 | MEGASAS_CHAIN_FRAME_SZ_MIN); | |
1683 | instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN; | |
1684 | } | |
1685 | ||
9c915a8c | 1686 | fusion->max_sge_in_main_msg = |
bd5f9484 | 1687 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE |
1688 | - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16; | |
9c915a8c AR |
1689 | |
1690 | fusion->max_sge_in_chain = | |
bd5f9484 | 1691 | instance->max_chain_frame_sz |
1692 | / sizeof(union MPI2_SGE_IO_UNION); | |
9c915a8c | 1693 | |
bd5f9484 | 1694 | instance->max_num_sge = |
1695 | rounddown_pow_of_two(fusion->max_sge_in_main_msg | |
1696 | + fusion->max_sge_in_chain - 2); | |
9c915a8c AR |
1697 | |
1698 | /* Used for pass thru MFI frame (DCMD) */ | |
1699 | fusion->chain_offset_mfi_pthru = | |
1700 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16; | |
1701 | ||
1702 | fusion->chain_offset_io_request = | |
1703 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - | |
1704 | sizeof(union MPI2_SGE_IO_UNION))/16; | |
1705 | ||
c8e858fe AR |
1706 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
1707 | for (i = 0 ; i < count; i++) | |
1708 | fusion->last_reply_idx[i] = 0; | |
9c915a8c | 1709 | |
f26ac3a1 | 1710 | /* |
ec779595 | 1711 | * For fusion adapters, 3 commands for IOCTL and 8 commands |
f26ac3a1 SS |
1712 | * for driver's internal DCMDs. |
1713 | */ | |
1714 | instance->max_scsi_cmds = instance->max_fw_cmds - | |
1715 | (MEGASAS_FUSION_INTERNAL_CMDS + | |
1716 | MEGASAS_FUSION_IOCTL_CMDS); | |
1717 | sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS); | |
1718 | ||
b9637d14 S |
1719 | if (megasas_alloc_ioc_init_frame(instance)) |
1720 | return 1; | |
1721 | ||
9c915a8c AR |
1722 | /* |
1723 | * Allocate memory for descriptors | |
1724 | * Create a pool of commands | |
1725 | */ | |
1726 | if (megasas_alloc_cmds(instance)) | |
1727 | goto fail_alloc_mfi_cmds; | |
1728 | if (megasas_alloc_cmds_fusion(instance)) | |
1729 | goto fail_alloc_cmds; | |
1730 | ||
1731 | if (megasas_ioc_init_fusion(instance)) | |
1732 | goto fail_ioc_init; | |
1733 | ||
39b72c3c | 1734 | megasas_display_intel_branding(instance); |
d009b576 | 1735 | if (megasas_get_ctrl_info(instance)) { |
51087a86 SS |
1736 | dev_err(&instance->pdev->dev, |
1737 | "Could not get controller info. Fail from %s %d\n", | |
1738 | __func__, __LINE__); | |
1739 | goto fail_ioc_init; | |
1740 | } | |
1741 | ||
9c915a8c | 1742 | instance->flag_ieee = 1; |
a48ba0ec | 1743 | instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT; |
51087a86 | 1744 | fusion->fast_path_io = 0; |
9c915a8c | 1745 | |
def3e8df S |
1746 | if (megasas_allocate_raid_maps(instance)) |
1747 | goto fail_ioc_init; | |
9c915a8c AR |
1748 | |
1749 | if (!megasas_get_map_info(instance)) | |
1750 | megasas_sync_map_info(instance); | |
1751 | ||
1752 | return 0; | |
1753 | ||
9c915a8c | 1754 | fail_ioc_init: |
eb1b1237 AR |
1755 | megasas_free_cmds_fusion(instance); |
1756 | fail_alloc_cmds: | |
1757 | megasas_free_cmds(instance); | |
1758 | fail_alloc_mfi_cmds: | |
b9637d14 | 1759 | megasas_free_ioc_init_cmd(instance); |
9c915a8c AR |
1760 | return 1; |
1761 | } | |
1762 | ||
9c915a8c AR |
1763 | /** |
1764 | * map_cmd_status - Maps FW cmd status to OS cmd status | |
1765 | * @cmd : Pointer to cmd | |
1766 | * @status : status of cmd returned by FW | |
1767 | * @ext_status : ext status of cmd returned by FW | |
1768 | */ | |
1769 | ||
1770 | void | |
69c337c0 | 1771 | map_cmd_status(struct fusion_context *fusion, |
41064f1b S |
1772 | struct scsi_cmnd *scmd, u8 status, u8 ext_status, |
1773 | u32 data_length, u8 *sense) | |
9c915a8c | 1774 | { |
def0eab3 | 1775 | u8 cmd_type; |
31d9a57b | 1776 | int resid; |
9c915a8c | 1777 | |
def0eab3 | 1778 | cmd_type = megasas_cmd_type(scmd); |
9c915a8c AR |
1779 | switch (status) { |
1780 | ||
1781 | case MFI_STAT_OK: | |
69c337c0 | 1782 | scmd->result = DID_OK << 16; |
9c915a8c AR |
1783 | break; |
1784 | ||
1785 | case MFI_STAT_SCSI_IO_FAILED: | |
1786 | case MFI_STAT_LD_INIT_IN_PROGRESS: | |
69c337c0 | 1787 | scmd->result = (DID_ERROR << 16) | ext_status; |
9c915a8c AR |
1788 | break; |
1789 | ||
1790 | case MFI_STAT_SCSI_DONE_WITH_ERROR: | |
1791 | ||
69c337c0 | 1792 | scmd->result = (DID_OK << 16) | ext_status; |
9c915a8c | 1793 | if (ext_status == SAM_STAT_CHECK_CONDITION) { |
69c337c0 | 1794 | memset(scmd->sense_buffer, 0, |
9c915a8c | 1795 | SCSI_SENSE_BUFFERSIZE); |
69c337c0 | 1796 | memcpy(scmd->sense_buffer, sense, |
9c915a8c | 1797 | SCSI_SENSE_BUFFERSIZE); |
69c337c0 | 1798 | scmd->result |= DRIVER_SENSE << 24; |
9c915a8c | 1799 | } |
31d9a57b S |
1800 | |
1801 | /* | |
1802 | * If the IO request is partially completed, then MR FW will | |
1803 | * update "io_request->DataLength" field with actual number of | |
1804 | * bytes transferred.Driver will set residual bytes count in | |
1805 | * SCSI command structure. | |
1806 | */ | |
1807 | resid = (scsi_bufflen(scmd) - data_length); | |
1808 | scsi_set_resid(scmd, resid); | |
def0eab3 S |
1809 | |
1810 | if (resid && | |
1811 | ((cmd_type == READ_WRITE_LDIO) || | |
1812 | (cmd_type == READ_WRITE_SYSPDIO))) | |
1813 | scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len" | |
1814 | " requested/completed 0x%x/0x%x\n", | |
1815 | status, scsi_bufflen(scmd), data_length); | |
9c915a8c AR |
1816 | break; |
1817 | ||
1818 | case MFI_STAT_LD_OFFLINE: | |
1819 | case MFI_STAT_DEVICE_NOT_FOUND: | |
69c337c0 | 1820 | scmd->result = DID_BAD_TARGET << 16; |
9c915a8c | 1821 | break; |
36807e67 | 1822 | case MFI_STAT_CONFIG_SEQ_MISMATCH: |
69c337c0 | 1823 | scmd->result = DID_IMM_RETRY << 16; |
36807e67 | 1824 | break; |
9c915a8c | 1825 | default: |
69c337c0 | 1826 | scmd->result = DID_ERROR << 16; |
9c915a8c AR |
1827 | break; |
1828 | } | |
1829 | } | |
1830 | ||
33203bc4 S |
1831 | /** |
1832 | * megasas_is_prp_possible - | |
1833 | * Checks if native NVMe PRPs can be built for the IO | |
1834 | * | |
1835 | * @instance: Adapter soft state | |
1836 | * @scmd: SCSI command from the mid-layer | |
1837 | * @sge_count: scatter gather element count. | |
1838 | * | |
1839 | * Returns: true: PRPs can be built | |
1840 | * false: IEEE SGLs needs to be built | |
1841 | */ | |
1842 | static bool | |
1843 | megasas_is_prp_possible(struct megasas_instance *instance, | |
1844 | struct scsi_cmnd *scmd, int sge_count) | |
1845 | { | |
1846 | struct fusion_context *fusion; | |
1847 | int i; | |
1848 | u32 data_length = 0; | |
1849 | struct scatterlist *sg_scmd; | |
1850 | bool build_prp = false; | |
1851 | u32 mr_nvme_pg_size; | |
1852 | ||
1853 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, | |
1854 | MR_DEFAULT_NVME_PAGE_SIZE); | |
1855 | fusion = instance->ctrl_context; | |
1856 | data_length = scsi_bufflen(scmd); | |
1857 | sg_scmd = scsi_sglist(scmd); | |
1858 | ||
1859 | /* | |
1860 | * NVMe uses one PRP for each page (or part of a page) | |
1861 | * look at the data length - if 4 pages or less then IEEE is OK | |
1862 | * if > 5 pages then we need to build a native SGL | |
1863 | * if > 4 and <= 5 pages, then check physical address of 1st SG entry | |
1864 | * if this first size in the page is >= the residual beyond 4 pages | |
1865 | * then use IEEE, otherwise use native SGL | |
1866 | */ | |
1867 | ||
1868 | if (data_length > (mr_nvme_pg_size * 5)) { | |
1869 | build_prp = true; | |
1870 | } else if ((data_length > (mr_nvme_pg_size * 4)) && | |
1871 | (data_length <= (mr_nvme_pg_size * 5))) { | |
1872 | /* check if 1st SG entry size is < residual beyond 4 pages */ | |
1873 | if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4))) | |
1874 | build_prp = true; | |
1875 | } | |
1876 | ||
1877 | /* | |
1878 | * Below code detects gaps/holes in IO data buffers. | |
1879 | * What does holes/gaps mean? | |
1880 | * Any SGE except first one in a SGL starts at non NVME page size | |
1881 | * aligned address OR Any SGE except last one in a SGL ends at | |
1882 | * non NVME page size boundary. | |
1883 | * | |
1884 | * Driver has already informed block layer by setting boundary rules for | |
1885 | * bio merging done at NVME page size boundary calling kernel API | |
1886 | * blk_queue_virt_boundary inside slave_config. | |
1887 | * Still there is possibility of IO coming with holes to driver because of | |
1888 | * IO merging done by IO scheduler. | |
1889 | * | |
1890 | * With SCSI BLK MQ enabled, there will be no IO with holes as there is no | |
1891 | * IO scheduling so no IO merging. | |
1892 | * | |
1893 | * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and | |
1894 | * then sending IOs with holes. | |
1895 | * | |
1896 | * Though driver can request block layer to disable IO merging by calling- | |
1897 | * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but | |
1898 | * user may tune sysfs parameter- nomerges again to 0 or 1. | |
1899 | * | |
1900 | * If in future IO scheduling is enabled with SCSI BLK MQ, | |
1901 | * this algorithm to detect holes will be required in driver | |
1902 | * for SCSI BLK MQ enabled case as well. | |
1903 | * | |
1904 | * | |
1905 | */ | |
1906 | scsi_for_each_sg(scmd, sg_scmd, sge_count, i) { | |
1907 | if ((i != 0) && (i != (sge_count - 1))) { | |
1908 | if (mega_mod64(sg_dma_len(sg_scmd), mr_nvme_pg_size) || | |
1909 | mega_mod64(sg_dma_address(sg_scmd), | |
1910 | mr_nvme_pg_size)) { | |
1911 | build_prp = false; | |
1912 | atomic_inc(&instance->sge_holes_type1); | |
1913 | break; | |
1914 | } | |
1915 | } | |
1916 | ||
1917 | if ((sge_count > 1) && (i == 0)) { | |
1918 | if ((mega_mod64((sg_dma_address(sg_scmd) + | |
1919 | sg_dma_len(sg_scmd)), | |
1920 | mr_nvme_pg_size))) { | |
1921 | build_prp = false; | |
1922 | atomic_inc(&instance->sge_holes_type2); | |
1923 | break; | |
1924 | } | |
1925 | } | |
1926 | ||
1927 | if ((sge_count > 1) && (i == (sge_count - 1))) { | |
1928 | if (mega_mod64(sg_dma_address(sg_scmd), | |
1929 | mr_nvme_pg_size)) { | |
1930 | build_prp = false; | |
1931 | atomic_inc(&instance->sge_holes_type3); | |
1932 | break; | |
1933 | } | |
1934 | } | |
1935 | } | |
1936 | ||
1937 | return build_prp; | |
1938 | } | |
1939 | ||
1940 | /** | |
1941 | * megasas_make_prp_nvme - | |
1942 | * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only | |
1943 | * | |
1944 | * @instance: Adapter soft state | |
1945 | * @scmd: SCSI command from the mid-layer | |
1946 | * @sgl_ptr: SGL to be filled in | |
1947 | * @cmd: Fusion command frame | |
1948 | * @sge_count: scatter gather element count. | |
1949 | * | |
1950 | * Returns: true: PRPs are built | |
1951 | * false: IEEE SGLs needs to be built | |
1952 | */ | |
1953 | static bool | |
1954 | megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd, | |
1955 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, | |
1956 | struct megasas_cmd_fusion *cmd, int sge_count) | |
1957 | { | |
1958 | int sge_len, offset, num_prp_in_chain = 0; | |
1959 | struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl; | |
d1da522f AB |
1960 | u64 *ptr_sgl; |
1961 | dma_addr_t ptr_sgl_phys; | |
33203bc4 S |
1962 | u64 sge_addr; |
1963 | u32 page_mask, page_mask_result; | |
1964 | struct scatterlist *sg_scmd; | |
1965 | u32 first_prp_len; | |
1966 | bool build_prp = false; | |
1967 | int data_len = scsi_bufflen(scmd); | |
1968 | struct fusion_context *fusion; | |
1969 | u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, | |
1970 | MR_DEFAULT_NVME_PAGE_SIZE); | |
1971 | ||
1972 | fusion = instance->ctrl_context; | |
1973 | ||
1974 | build_prp = megasas_is_prp_possible(instance, scmd, sge_count); | |
1975 | ||
1976 | if (!build_prp) | |
1977 | return false; | |
1978 | ||
1979 | /* | |
1980 | * Nvme has a very convoluted prp format. One prp is required | |
1981 | * for each page or partial page. Driver need to split up OS sg_list | |
1982 | * entries if it is longer than one page or cross a page | |
1983 | * boundary. Driver also have to insert a PRP list pointer entry as | |
1984 | * the last entry in each physical page of the PRP list. | |
1985 | * | |
1986 | * NOTE: The first PRP "entry" is actually placed in the first | |
1987 | * SGL entry in the main message as IEEE 64 format. The 2nd | |
1988 | * entry in the main message is the chain element, and the rest | |
1989 | * of the PRP entries are built in the contiguous pcie buffer. | |
1990 | */ | |
1991 | page_mask = mr_nvme_pg_size - 1; | |
1992 | ptr_sgl = (u64 *)cmd->sg_frame; | |
d1da522f | 1993 | ptr_sgl_phys = cmd->sg_frame_phys_addr; |
33203bc4 S |
1994 | memset(ptr_sgl, 0, instance->max_chain_frame_sz); |
1995 | ||
1996 | /* Build chain frame element which holds all prps except first*/ | |
1997 | main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *) | |
1998 | ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64)); | |
1999 | ||
d1da522f | 2000 | main_chain_element->Address = cpu_to_le64(ptr_sgl_phys); |
33203bc4 S |
2001 | main_chain_element->NextChainOffset = 0; |
2002 | main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | | |
2003 | IEEE_SGE_FLAGS_SYSTEM_ADDR | | |
2004 | MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP; | |
2005 | ||
2006 | /* Build first prp, sge need not to be page aligned*/ | |
2007 | ptr_first_sgl = sgl_ptr; | |
2008 | sg_scmd = scsi_sglist(scmd); | |
2009 | sge_addr = sg_dma_address(sg_scmd); | |
2010 | sge_len = sg_dma_len(sg_scmd); | |
2011 | ||
2012 | offset = (u32)(sge_addr & page_mask); | |
2013 | first_prp_len = mr_nvme_pg_size - offset; | |
2014 | ||
2015 | ptr_first_sgl->Address = cpu_to_le64(sge_addr); | |
2016 | ptr_first_sgl->Length = cpu_to_le32(first_prp_len); | |
2017 | ||
2018 | data_len -= first_prp_len; | |
2019 | ||
2020 | if (sge_len > first_prp_len) { | |
2021 | sge_addr += first_prp_len; | |
2022 | sge_len -= first_prp_len; | |
2023 | } else if (sge_len == first_prp_len) { | |
2024 | sg_scmd = sg_next(sg_scmd); | |
2025 | sge_addr = sg_dma_address(sg_scmd); | |
2026 | sge_len = sg_dma_len(sg_scmd); | |
2027 | } | |
2028 | ||
2029 | for (;;) { | |
2030 | offset = (u32)(sge_addr & page_mask); | |
2031 | ||
2032 | /* Put PRP pointer due to page boundary*/ | |
2033 | page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask; | |
2034 | if (unlikely(!page_mask_result)) { | |
2035 | scmd_printk(KERN_NOTICE, | |
2036 | scmd, "page boundary ptr_sgl: 0x%p\n", | |
2037 | ptr_sgl); | |
d1da522f AB |
2038 | ptr_sgl_phys += 8; |
2039 | *ptr_sgl = cpu_to_le64(ptr_sgl_phys); | |
33203bc4 S |
2040 | ptr_sgl++; |
2041 | num_prp_in_chain++; | |
2042 | } | |
2043 | ||
2044 | *ptr_sgl = cpu_to_le64(sge_addr); | |
2045 | ptr_sgl++; | |
d1da522f | 2046 | ptr_sgl_phys += 8; |
33203bc4 S |
2047 | num_prp_in_chain++; |
2048 | ||
2049 | sge_addr += mr_nvme_pg_size; | |
2050 | sge_len -= mr_nvme_pg_size; | |
2051 | data_len -= mr_nvme_pg_size; | |
2052 | ||
2053 | if (data_len <= 0) | |
2054 | break; | |
2055 | ||
2056 | if (sge_len > 0) | |
2057 | continue; | |
2058 | ||
2059 | sg_scmd = sg_next(sg_scmd); | |
2060 | sge_addr = sg_dma_address(sg_scmd); | |
2061 | sge_len = sg_dma_len(sg_scmd); | |
2062 | } | |
2063 | ||
2064 | main_chain_element->Length = | |
2065 | cpu_to_le32(num_prp_in_chain * sizeof(u64)); | |
2066 | ||
2067 | atomic_inc(&instance->prp_sgl); | |
2068 | return build_prp; | |
2069 | } | |
2070 | ||
9c915a8c AR |
2071 | /** |
2072 | * megasas_make_sgl_fusion - Prepares 32-bit SGL | |
2073 | * @instance: Adapter soft state | |
2074 | * @scp: SCSI command from the mid-layer | |
2075 | * @sgl_ptr: SGL to be filled in | |
2076 | * @cmd: cmd we are working on | |
33203bc4 | 2077 | * @sge_count sge count |
9c915a8c | 2078 | * |
9c915a8c | 2079 | */ |
33203bc4 | 2080 | static void |
9c915a8c AR |
2081 | megasas_make_sgl_fusion(struct megasas_instance *instance, |
2082 | struct scsi_cmnd *scp, | |
2083 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, | |
33203bc4 | 2084 | struct megasas_cmd_fusion *cmd, int sge_count) |
9c915a8c | 2085 | { |
33203bc4 | 2086 | int i, sg_processed; |
9c915a8c AR |
2087 | struct scatterlist *os_sgl; |
2088 | struct fusion_context *fusion; | |
2089 | ||
2090 | fusion = instance->ctrl_context; | |
2091 | ||
c365178f | 2092 | if (instance->adapter_type >= INVADER_SERIES) { |
36807e67 AR |
2093 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr; |
2094 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; | |
2095 | sgl_ptr_end->Flags = 0; | |
2096 | } | |
9c915a8c | 2097 | |
9c915a8c | 2098 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
94cd65dd SS |
2099 | sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl)); |
2100 | sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl)); | |
9c915a8c | 2101 | sgl_ptr->Flags = 0; |
c365178f | 2102 | if (instance->adapter_type >= INVADER_SERIES) |
36807e67 AR |
2103 | if (i == sge_count - 1) |
2104 | sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; | |
9c915a8c | 2105 | sgl_ptr++; |
9c915a8c AR |
2106 | sg_processed = i + 1; |
2107 | ||
2108 | if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) && | |
2109 | (sge_count > fusion->max_sge_in_main_msg)) { | |
2110 | ||
2111 | struct MPI25_IEEE_SGE_CHAIN64 *sg_chain; | |
c365178f | 2112 | if (instance->adapter_type >= INVADER_SERIES) { |
94cd65dd SS |
2113 | if ((le16_to_cpu(cmd->io_request->IoFlags) & |
2114 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) != | |
2115 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) | |
36807e67 AR |
2116 | cmd->io_request->ChainOffset = |
2117 | fusion-> | |
2118 | chain_offset_io_request; | |
2119 | else | |
2120 | cmd->io_request->ChainOffset = 0; | |
2121 | } else | |
2122 | cmd->io_request->ChainOffset = | |
2123 | fusion->chain_offset_io_request; | |
2124 | ||
9c915a8c AR |
2125 | sg_chain = sgl_ptr; |
2126 | /* Prepare chain element */ | |
2127 | sg_chain->NextChainOffset = 0; | |
c365178f | 2128 | if (instance->adapter_type >= INVADER_SERIES) |
36807e67 AR |
2129 | sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; |
2130 | else | |
2131 | sg_chain->Flags = | |
2132 | (IEEE_SGE_FLAGS_CHAIN_ELEMENT | | |
2133 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); | |
94cd65dd SS |
2134 | sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed))); |
2135 | sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr); | |
9c915a8c AR |
2136 | |
2137 | sgl_ptr = | |
2138 | (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame; | |
bd5f9484 | 2139 | memset(sgl_ptr, 0, instance->max_chain_frame_sz); |
9c915a8c AR |
2140 | } |
2141 | } | |
33203bc4 S |
2142 | atomic_inc(&instance->ieee_sgl); |
2143 | } | |
2144 | ||
2145 | /** | |
2146 | * megasas_make_sgl - Build Scatter Gather List(SGLs) | |
2147 | * @scp: SCSI command pointer | |
2148 | * @instance: Soft instance of controller | |
2149 | * @cmd: Fusion command pointer | |
2150 | * | |
2151 | * This function will build sgls based on device type. | |
2152 | * For nvme drives, there is different way of building sgls in nvme native | |
2153 | * format- PRPs(Physical Region Page). | |
2154 | * | |
2155 | * Returns the number of sg lists actually used, zero if the sg lists | |
2156 | * is NULL, or -ENOMEM if the mapping failed | |
2157 | */ | |
2158 | static | |
2159 | int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp, | |
2160 | struct megasas_cmd_fusion *cmd) | |
2161 | { | |
2162 | int sge_count; | |
2163 | bool build_prp = false; | |
2164 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64; | |
2165 | ||
2166 | sge_count = scsi_dma_map(scp); | |
2167 | ||
2168 | if ((sge_count > instance->max_num_sge) || (sge_count <= 0)) | |
2169 | return sge_count; | |
2170 | ||
2171 | sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL; | |
2172 | if ((le16_to_cpu(cmd->io_request->IoFlags) & | |
2173 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) && | |
2174 | (cmd->pd_interface == NVME_PD)) | |
2175 | build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64, | |
2176 | cmd, sge_count); | |
2177 | ||
2178 | if (!build_prp) | |
2179 | megasas_make_sgl_fusion(instance, scp, sgl_chain64, | |
2180 | cmd, sge_count); | |
9c915a8c AR |
2181 | |
2182 | return sge_count; | |
2183 | } | |
2184 | ||
2185 | /** | |
2186 | * megasas_set_pd_lba - Sets PD LBA | |
2187 | * @cdb: CDB | |
2188 | * @cdb_len: cdb length | |
2189 | * @start_blk: Start block of IO | |
2190 | * | |
2191 | * Used to set the PD LBA in CDB for FP IOs | |
2192 | */ | |
2193 | void | |
2194 | megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, | |
2195 | struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp, | |
51087a86 | 2196 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag) |
9c915a8c AR |
2197 | { |
2198 | struct MR_LD_RAID *raid; | |
d2d0358b | 2199 | u16 ld; |
9c915a8c AR |
2200 | u64 start_blk = io_info->pdBlock; |
2201 | u8 *cdb = io_request->CDB.CDB32; | |
2202 | u32 num_blocks = io_info->numBlocks; | |
495c5609 | 2203 | u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0; |
9c915a8c AR |
2204 | |
2205 | /* Check if T10 PI (DIF) is enabled for this LD */ | |
2206 | ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr); | |
2207 | raid = MR_LdRaidGet(ld, local_map_ptr); | |
2208 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) { | |
2209 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); | |
2210 | cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD; | |
2211 | cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN; | |
2212 | ||
2213 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | |
2214 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32; | |
2215 | else | |
2216 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32; | |
2217 | cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL; | |
2218 | ||
2219 | /* LBA */ | |
2220 | cdb[12] = (u8)((start_blk >> 56) & 0xff); | |
2221 | cdb[13] = (u8)((start_blk >> 48) & 0xff); | |
2222 | cdb[14] = (u8)((start_blk >> 40) & 0xff); | |
2223 | cdb[15] = (u8)((start_blk >> 32) & 0xff); | |
2224 | cdb[16] = (u8)((start_blk >> 24) & 0xff); | |
2225 | cdb[17] = (u8)((start_blk >> 16) & 0xff); | |
2226 | cdb[18] = (u8)((start_blk >> 8) & 0xff); | |
2227 | cdb[19] = (u8)(start_blk & 0xff); | |
2228 | ||
2229 | /* Logical block reference tag */ | |
2230 | io_request->CDB.EEDP32.PrimaryReferenceTag = | |
2231 | cpu_to_be32(ref_tag); | |
6e755ddc | 2232 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff); |
94cd65dd | 2233 | io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */ |
9c915a8c AR |
2234 | |
2235 | /* Transfer length */ | |
2236 | cdb[28] = (u8)((num_blocks >> 24) & 0xff); | |
2237 | cdb[29] = (u8)((num_blocks >> 16) & 0xff); | |
2238 | cdb[30] = (u8)((num_blocks >> 8) & 0xff); | |
2239 | cdb[31] = (u8)(num_blocks & 0xff); | |
2240 | ||
2241 | /* set SCSI IO EEDPFlags */ | |
2242 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) { | |
94cd65dd | 2243 | io_request->EEDPFlags = cpu_to_le16( |
9c915a8c AR |
2244 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
2245 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
2246 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP | | |
2247 | MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG | | |
45d44603 | 2248 | MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE | |
94cd65dd | 2249 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD); |
9c915a8c | 2250 | } else { |
94cd65dd | 2251 | io_request->EEDPFlags = cpu_to_le16( |
9c915a8c | 2252 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
94cd65dd | 2253 | MPI2_SCSIIO_EEDPFLAGS_INSERT_OP); |
9c915a8c | 2254 | } |
94cd65dd SS |
2255 | io_request->Control |= cpu_to_le32((0x4 << 26)); |
2256 | io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size); | |
9c915a8c AR |
2257 | } else { |
2258 | /* Some drives don't support 16/12 byte CDB's, convert to 10 */ | |
2259 | if (((cdb_len == 12) || (cdb_len == 16)) && | |
2260 | (start_blk <= 0xffffffff)) { | |
2261 | if (cdb_len == 16) { | |
2262 | opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10; | |
2263 | flagvals = cdb[1]; | |
2264 | groupnum = cdb[14]; | |
2265 | control = cdb[15]; | |
2266 | } else { | |
2267 | opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10; | |
2268 | flagvals = cdb[1]; | |
2269 | groupnum = cdb[10]; | |
2270 | control = cdb[11]; | |
2271 | } | |
2272 | ||
2273 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); | |
2274 | ||
2275 | cdb[0] = opcode; | |
2276 | cdb[1] = flagvals; | |
2277 | cdb[6] = groupnum; | |
2278 | cdb[9] = control; | |
2279 | ||
2280 | /* Transfer length */ | |
2281 | cdb[8] = (u8)(num_blocks & 0xff); | |
2282 | cdb[7] = (u8)((num_blocks >> 8) & 0xff); | |
2283 | ||
94cd65dd | 2284 | io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */ |
9c915a8c | 2285 | cdb_len = 10; |
495c5609 AR |
2286 | } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) { |
2287 | /* Convert to 16 byte CDB for large LBA's */ | |
2288 | switch (cdb_len) { | |
2289 | case 6: | |
2290 | opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16; | |
2291 | control = cdb[5]; | |
2292 | break; | |
2293 | case 10: | |
2294 | opcode = | |
2295 | cdb[0] == READ_10 ? READ_16 : WRITE_16; | |
2296 | flagvals = cdb[1]; | |
2297 | groupnum = cdb[6]; | |
2298 | control = cdb[9]; | |
2299 | break; | |
2300 | case 12: | |
2301 | opcode = | |
2302 | cdb[0] == READ_12 ? READ_16 : WRITE_16; | |
2303 | flagvals = cdb[1]; | |
2304 | groupnum = cdb[10]; | |
2305 | control = cdb[11]; | |
2306 | break; | |
2307 | } | |
2308 | ||
2309 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); | |
2310 | ||
2311 | cdb[0] = opcode; | |
2312 | cdb[1] = flagvals; | |
2313 | cdb[14] = groupnum; | |
2314 | cdb[15] = control; | |
2315 | ||
2316 | /* Transfer length */ | |
2317 | cdb[13] = (u8)(num_blocks & 0xff); | |
2318 | cdb[12] = (u8)((num_blocks >> 8) & 0xff); | |
2319 | cdb[11] = (u8)((num_blocks >> 16) & 0xff); | |
2320 | cdb[10] = (u8)((num_blocks >> 24) & 0xff); | |
2321 | ||
94cd65dd | 2322 | io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */ |
495c5609 | 2323 | cdb_len = 16; |
9c915a8c AR |
2324 | } |
2325 | ||
2326 | /* Normal case, just load LBA here */ | |
2327 | switch (cdb_len) { | |
2328 | case 6: | |
2329 | { | |
2330 | u8 val = cdb[1] & 0xE0; | |
2331 | cdb[3] = (u8)(start_blk & 0xff); | |
2332 | cdb[2] = (u8)((start_blk >> 8) & 0xff); | |
2333 | cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f); | |
2334 | break; | |
2335 | } | |
2336 | case 10: | |
2337 | cdb[5] = (u8)(start_blk & 0xff); | |
2338 | cdb[4] = (u8)((start_blk >> 8) & 0xff); | |
2339 | cdb[3] = (u8)((start_blk >> 16) & 0xff); | |
2340 | cdb[2] = (u8)((start_blk >> 24) & 0xff); | |
2341 | break; | |
2342 | case 12: | |
2343 | cdb[5] = (u8)(start_blk & 0xff); | |
2344 | cdb[4] = (u8)((start_blk >> 8) & 0xff); | |
2345 | cdb[3] = (u8)((start_blk >> 16) & 0xff); | |
2346 | cdb[2] = (u8)((start_blk >> 24) & 0xff); | |
2347 | break; | |
2348 | case 16: | |
2349 | cdb[9] = (u8)(start_blk & 0xff); | |
2350 | cdb[8] = (u8)((start_blk >> 8) & 0xff); | |
2351 | cdb[7] = (u8)((start_blk >> 16) & 0xff); | |
2352 | cdb[6] = (u8)((start_blk >> 24) & 0xff); | |
2353 | cdb[5] = (u8)((start_blk >> 32) & 0xff); | |
2354 | cdb[4] = (u8)((start_blk >> 40) & 0xff); | |
2355 | cdb[3] = (u8)((start_blk >> 48) & 0xff); | |
2356 | cdb[2] = (u8)((start_blk >> 56) & 0xff); | |
2357 | break; | |
2358 | } | |
2359 | } | |
2360 | } | |
2361 | ||
fdd84e25 SC |
2362 | /** |
2363 | * megasas_stream_detect - stream detection on read and and write IOs | |
2364 | * @instance: Adapter soft state | |
2365 | * @cmd: Command to be prepared | |
2366 | * @io_info: IO Request info | |
2367 | * | |
2368 | */ | |
2369 | ||
2370 | /** stream detection on read and and write IOs */ | |
2371 | static void megasas_stream_detect(struct megasas_instance *instance, | |
41064f1b S |
2372 | struct megasas_cmd_fusion *cmd, |
2373 | struct IO_REQUEST_INFO *io_info) | |
fdd84e25 SC |
2374 | { |
2375 | struct fusion_context *fusion = instance->ctrl_context; | |
2376 | u32 device_id = io_info->ldTgtId; | |
2377 | struct LD_STREAM_DETECT *current_ld_sd | |
2378 | = fusion->stream_detect_by_ld[device_id]; | |
2379 | u32 *track_stream = ¤t_ld_sd->mru_bit_map, stream_num; | |
2380 | u32 shifted_values, unshifted_values; | |
2381 | u32 index_value_mask, shifted_values_mask; | |
2382 | int i; | |
2383 | bool is_read_ahead = false; | |
2384 | struct STREAM_DETECT *current_sd; | |
2385 | /* find possible stream */ | |
2386 | for (i = 0; i < MAX_STREAMS_TRACKED; ++i) { | |
41064f1b S |
2387 | stream_num = (*track_stream >> |
2388 | (i * BITS_PER_INDEX_STREAM)) & | |
fdd84e25 SC |
2389 | STREAM_MASK; |
2390 | current_sd = ¤t_ld_sd->stream_track[stream_num]; | |
41064f1b S |
2391 | /* if we found a stream, update the raid |
2392 | * context and also update the mruBitMap | |
2393 | */ | |
2394 | /* boundary condition */ | |
2395 | if ((current_sd->next_seq_lba) && | |
2396 | (io_info->ldStartBlock >= current_sd->next_seq_lba) && | |
2397 | (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) && | |
2398 | (current_sd->is_read == io_info->isRead)) { | |
2399 | ||
2400 | if ((io_info->ldStartBlock != current_sd->next_seq_lba) && | |
2401 | ((!io_info->isRead) || (!is_read_ahead))) | |
2402 | /* | |
2403 | * Once the API availible we need to change this. | |
2404 | * At this point we are not allowing any gap | |
2405 | */ | |
2406 | continue; | |
2407 | ||
2408 | SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35); | |
2409 | current_sd->next_seq_lba = | |
2410 | io_info->ldStartBlock + io_info->numBlocks; | |
fdd84e25 | 2411 | /* |
41064f1b | 2412 | * update the mruBitMap LRU |
fdd84e25 | 2413 | */ |
41064f1b S |
2414 | shifted_values_mask = |
2415 | (1 << i * BITS_PER_INDEX_STREAM) - 1; | |
2416 | shifted_values = ((*track_stream & shifted_values_mask) | |
2417 | << BITS_PER_INDEX_STREAM); | |
2418 | index_value_mask = | |
2419 | STREAM_MASK << i * BITS_PER_INDEX_STREAM; | |
2420 | unshifted_values = | |
2421 | *track_stream & ~(shifted_values_mask | | |
2422 | index_value_mask); | |
2423 | *track_stream = | |
2424 | unshifted_values | shifted_values | stream_num; | |
2425 | return; | |
fdd84e25 | 2426 | } |
fdd84e25 SC |
2427 | } |
2428 | /* | |
2429 | * if we did not find any stream, create a new one | |
2430 | * from the least recently used | |
2431 | */ | |
41064f1b S |
2432 | stream_num = (*track_stream >> |
2433 | ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) & | |
2434 | STREAM_MASK; | |
fdd84e25 SC |
2435 | current_sd = ¤t_ld_sd->stream_track[stream_num]; |
2436 | current_sd->is_read = io_info->isRead; | |
2437 | current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks; | |
41064f1b | 2438 | *track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num); |
fdd84e25 | 2439 | return; |
fdd84e25 SC |
2440 | } |
2441 | ||
f6c0d55c S |
2442 | /** |
2443 | * megasas_set_raidflag_cpu_affinity - This function sets the cpu | |
2444 | * affinity (cpu of the controller) and raid_flags in the raid context | |
2445 | * based on IO type. | |
2446 | * | |
2447 | * @praid_context: IO RAID context | |
2448 | * @raid: LD raid map | |
2449 | * @fp_possible: Is fast path possible? | |
2450 | * @is_read: Is read IO? | |
2451 | * | |
2452 | */ | |
2453 | static void | |
2454 | megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context, | |
2455 | struct MR_LD_RAID *raid, bool fp_possible, | |
a48ba0ec | 2456 | u8 is_read, u32 scsi_buff_len) |
f6c0d55c S |
2457 | { |
2458 | u8 cpu_sel = MR_RAID_CTX_CPUSEL_0; | |
2459 | struct RAID_CONTEXT_G35 *rctx_g35; | |
2460 | ||
2461 | rctx_g35 = &praid_context->raid_context_g35; | |
2462 | if (fp_possible) { | |
2463 | if (is_read) { | |
2464 | if ((raid->cpuAffinity.pdRead.cpu0) && | |
2465 | (raid->cpuAffinity.pdRead.cpu1)) | |
2466 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; | |
2467 | else if (raid->cpuAffinity.pdRead.cpu1) | |
2468 | cpu_sel = MR_RAID_CTX_CPUSEL_1; | |
2469 | } else { | |
2470 | if ((raid->cpuAffinity.pdWrite.cpu0) && | |
2471 | (raid->cpuAffinity.pdWrite.cpu1)) | |
2472 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; | |
2473 | else if (raid->cpuAffinity.pdWrite.cpu1) | |
2474 | cpu_sel = MR_RAID_CTX_CPUSEL_1; | |
2475 | /* Fast path cache by pass capable R0/R1 VD */ | |
2476 | if ((raid->level <= 1) && | |
2477 | (raid->capability.fp_cache_bypass_capable)) { | |
a174118b S |
2478 | rctx_g35->routing_flags |= |
2479 | (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT); | |
f6c0d55c S |
2480 | rctx_g35->raid_flags = |
2481 | (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS | |
2482 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT); | |
2483 | } | |
2484 | } | |
2485 | } else { | |
2486 | if (is_read) { | |
2487 | if ((raid->cpuAffinity.ldRead.cpu0) && | |
2488 | (raid->cpuAffinity.ldRead.cpu1)) | |
2489 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; | |
2490 | else if (raid->cpuAffinity.ldRead.cpu1) | |
2491 | cpu_sel = MR_RAID_CTX_CPUSEL_1; | |
2492 | } else { | |
2493 | if ((raid->cpuAffinity.ldWrite.cpu0) && | |
2494 | (raid->cpuAffinity.ldWrite.cpu1)) | |
2495 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; | |
2496 | else if (raid->cpuAffinity.ldWrite.cpu1) | |
2497 | cpu_sel = MR_RAID_CTX_CPUSEL_1; | |
2498 | ||
a174118b | 2499 | if (is_stream_detected(rctx_g35) && |
874d025d | 2500 | ((raid->level == 5) || (raid->level == 6)) && |
f6c0d55c S |
2501 | (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) && |
2502 | (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS)) | |
2503 | cpu_sel = MR_RAID_CTX_CPUSEL_0; | |
2504 | } | |
2505 | } | |
2506 | ||
a174118b S |
2507 | rctx_g35->routing_flags |= |
2508 | (cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT); | |
a48ba0ec S |
2509 | |
2510 | /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT | |
2511 | * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS. | |
2512 | * IO Subtype is not bitmap. | |
2513 | */ | |
2514 | if ((raid->level == 1) && (!is_read)) { | |
2515 | if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE) | |
2516 | praid_context->raid_context_g35.raid_flags = | |
2517 | (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT | |
2518 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT); | |
2519 | } | |
f6c0d55c S |
2520 | } |
2521 | ||
9c915a8c AR |
2522 | /** |
2523 | * megasas_build_ldio_fusion - Prepares IOs to devices | |
2524 | * @instance: Adapter soft state | |
2525 | * @scp: SCSI command | |
2526 | * @cmd: Command to be prepared | |
2527 | * | |
2528 | * Prepares the io_request and chain elements (sg_frame) for IO | |
2529 | * The IO can be for PD (Fast Path) or LD | |
2530 | */ | |
2531 | void | |
2532 | megasas_build_ldio_fusion(struct megasas_instance *instance, | |
2533 | struct scsi_cmnd *scp, | |
2534 | struct megasas_cmd_fusion *cmd) | |
2535 | { | |
f6c0d55c S |
2536 | bool fp_possible; |
2537 | u16 ld; | |
2538 | u32 start_lba_lo, start_lba_hi, device_id, datalength = 0; | |
2539 | u32 scsi_buff_len; | |
9c915a8c AR |
2540 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
2541 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; | |
2542 | struct IO_REQUEST_INFO io_info; | |
2543 | struct fusion_context *fusion; | |
51087a86 | 2544 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
21c9e160 | 2545 | u8 *raidLUN; |
fdd84e25 | 2546 | unsigned long spinlock_flags; |
d889344e | 2547 | union RAID_CONTEXT_UNION *praid_context; |
f6c0d55c S |
2548 | struct MR_LD_RAID *raid = NULL; |
2549 | struct MR_PRIV_DEVICE *mrdev_priv; | |
9c915a8c | 2550 | |
4a5c814d | 2551 | device_id = MEGASAS_DEV_INDEX(scp); |
9c915a8c AR |
2552 | |
2553 | fusion = instance->ctrl_context; | |
2554 | ||
2555 | io_request = cmd->io_request; | |
d889344e | 2556 | io_request->RaidContext.raid_context.virtual_disk_tgt_id = |
fdd84e25 SC |
2557 | cpu_to_le16(device_id); |
2558 | io_request->RaidContext.raid_context.status = 0; | |
d889344e | 2559 | io_request->RaidContext.raid_context.ex_status = 0; |
9c915a8c AR |
2560 | |
2561 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; | |
2562 | ||
2563 | start_lba_lo = 0; | |
2564 | start_lba_hi = 0; | |
f6c0d55c | 2565 | fp_possible = false; |
9c915a8c AR |
2566 | |
2567 | /* | |
2568 | * 6-byte READ(0x08) or WRITE(0x0A) cdb | |
2569 | */ | |
2570 | if (scp->cmd_len == 6) { | |
f9eff815 | 2571 | datalength = (u32) scp->cmnd[4]; |
9c915a8c AR |
2572 | start_lba_lo = ((u32) scp->cmnd[1] << 16) | |
2573 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; | |
2574 | ||
2575 | start_lba_lo &= 0x1FFFFF; | |
2576 | } | |
2577 | ||
2578 | /* | |
2579 | * 10-byte READ(0x28) or WRITE(0x2A) cdb | |
2580 | */ | |
2581 | else if (scp->cmd_len == 10) { | |
f9eff815 | 2582 | datalength = (u32) scp->cmnd[8] | |
9c915a8c AR |
2583 | ((u32) scp->cmnd[7] << 8); |
2584 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | | |
2585 | ((u32) scp->cmnd[3] << 16) | | |
2586 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
2587 | } | |
2588 | ||
2589 | /* | |
2590 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb | |
2591 | */ | |
2592 | else if (scp->cmd_len == 12) { | |
f9eff815 | 2593 | datalength = ((u32) scp->cmnd[6] << 24) | |
9c915a8c AR |
2594 | ((u32) scp->cmnd[7] << 16) | |
2595 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | |
2596 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | | |
2597 | ((u32) scp->cmnd[3] << 16) | | |
2598 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
2599 | } | |
2600 | ||
2601 | /* | |
2602 | * 16-byte READ(0x88) or WRITE(0x8A) cdb | |
2603 | */ | |
2604 | else if (scp->cmd_len == 16) { | |
f9eff815 | 2605 | datalength = ((u32) scp->cmnd[10] << 24) | |
9c915a8c AR |
2606 | ((u32) scp->cmnd[11] << 16) | |
2607 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; | |
2608 | start_lba_lo = ((u32) scp->cmnd[6] << 24) | | |
2609 | ((u32) scp->cmnd[7] << 16) | | |
2610 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | |
2611 | ||
2612 | start_lba_hi = ((u32) scp->cmnd[2] << 24) | | |
2613 | ((u32) scp->cmnd[3] << 16) | | |
2614 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
2615 | } | |
2616 | ||
2617 | memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); | |
2618 | io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo; | |
f9eff815 | 2619 | io_info.numBlocks = datalength; |
9c915a8c | 2620 | io_info.ldTgtId = device_id; |
8bf7c65d | 2621 | io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
f6c0d55c S |
2622 | scsi_buff_len = scsi_bufflen(scp); |
2623 | io_request->DataLength = cpu_to_le32(scsi_buff_len); | |
9c915a8c AR |
2624 | |
2625 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | |
2626 | io_info.isRead = 1; | |
2627 | ||
51087a86 | 2628 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
d889344e | 2629 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
9c915a8c | 2630 | |
d2d0358b S |
2631 | if (ld < instance->fw_supported_vd_count) |
2632 | raid = MR_LdRaidGet(ld, local_map_ptr); | |
2633 | ||
2634 | if (!raid || (!fusion->fast_path_io)) { | |
d889344e | 2635 | io_request->RaidContext.raid_context.reg_lock_flags = 0; |
f6c0d55c | 2636 | fp_possible = false; |
9c915a8c | 2637 | } else { |
36807e67 | 2638 | if (MR_BuildRaidContext(instance, &io_info, |
fdd84e25 | 2639 | &io_request->RaidContext.raid_context, |
21c9e160 | 2640 | local_map_ptr, &raidLUN)) |
f6c0d55c | 2641 | fp_possible = (io_info.fpOkForIo > 0) ? true : false; |
9c915a8c AR |
2642 | } |
2643 | ||
99fe57b3 ML |
2644 | cmd->request_desc->SCSIIO.MSIxIndex = |
2645 | instance->reply_map[raw_smp_processor_id()]; | |
c8e858fe | 2646 | |
f6c0d55c S |
2647 | praid_context = &io_request->RaidContext; |
2648 | ||
f369a315 | 2649 | if (instance->adapter_type == VENTURA_SERIES) { |
fdd84e25 SC |
2650 | spin_lock_irqsave(&instance->stream_lock, spinlock_flags); |
2651 | megasas_stream_detect(instance, cmd, &io_info); | |
2652 | spin_unlock_irqrestore(&instance->stream_lock, spinlock_flags); | |
2653 | /* In ventura if stream detected for a read and it is read ahead | |
2654 | * capable make this IO as LDIO | |
2655 | */ | |
a174118b | 2656 | if (is_stream_detected(&io_request->RaidContext.raid_context_g35) && |
f6c0d55c | 2657 | io_info.isRead && io_info.ra_capable) |
fdd84e25 | 2658 | fp_possible = false; |
fdd84e25 | 2659 | |
a48ba0ec S |
2660 | /* FP for Optimal raid level 1. |
2661 | * All large RAID-1 writes (> 32 KiB, both WT and WB modes) | |
2662 | * are built by the driver as LD I/Os. | |
2663 | * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os | |
2664 | * (there is never a reason to process these as buffered writes) | |
2665 | * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os | |
2666 | * with the SLD bit asserted. | |
2667 | */ | |
8bf7c65d | 2668 | if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) { |
f6c0d55c S |
2669 | mrdev_priv = scp->device->hostdata; |
2670 | ||
2671 | if (atomic_inc_return(&instance->fw_outstanding) > | |
2672 | (instance->host->can_queue)) { | |
2673 | fp_possible = false; | |
2674 | atomic_dec(&instance->fw_outstanding); | |
a48ba0ec | 2675 | } else if ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) || |
49524b3c | 2676 | (atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint) > 0)) { |
a48ba0ec S |
2677 | fp_possible = false; |
2678 | atomic_dec(&instance->fw_outstanding); | |
2679 | if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE) | |
2680 | atomic_set(&mrdev_priv->r1_ldio_hint, | |
2681 | instance->r1_ldio_hint_default); | |
f6c0d55c S |
2682 | } |
2683 | } | |
2684 | ||
2685 | /* If raid is NULL, set CPU affinity to default CPU0 */ | |
2686 | if (raid) | |
2687 | megasas_set_raidflag_cpu_affinity(praid_context, | |
a48ba0ec S |
2688 | raid, fp_possible, io_info.isRead, |
2689 | scsi_buff_len); | |
f6c0d55c | 2690 | else |
a174118b S |
2691 | praid_context->raid_context_g35.routing_flags |= |
2692 | (MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT); | |
f6c0d55c | 2693 | } |
d889344e | 2694 | |
9c915a8c AR |
2695 | if (fp_possible) { |
2696 | megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp, | |
2697 | local_map_ptr, start_lba_lo); | |
9c915a8c AR |
2698 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
2699 | cmd->request_desc->SCSIIO.RequestFlags = | |
2c048351 | 2700 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO |
9c915a8c | 2701 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
c365178f | 2702 | if (instance->adapter_type == INVADER_SERIES) { |
d889344e | 2703 | if (io_request->RaidContext.raid_context.reg_lock_flags == |
36807e67 AR |
2704 | REGION_TYPE_UNUSED) |
2705 | cmd->request_desc->SCSIIO.RequestFlags = | |
2706 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << | |
2707 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
d889344e | 2708 | io_request->RaidContext.raid_context.type |
fdd84e25 SC |
2709 | = MPI2_TYPE_CUDA; |
2710 | io_request->RaidContext.raid_context.nseg = 0x1; | |
94cd65dd | 2711 | io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
d889344e | 2712 | io_request->RaidContext.raid_context.reg_lock_flags |= |
36807e67 AR |
2713 | (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | |
2714 | MR_RL_FLAGS_SEQ_NUM_ENABLE); | |
f369a315 | 2715 | } else if (instance->adapter_type == VENTURA_SERIES) { |
a174118b S |
2716 | io_request->RaidContext.raid_context_g35.nseg_type |= |
2717 | (1 << RAID_CONTEXT_NSEG_SHIFT); | |
2718 | io_request->RaidContext.raid_context_g35.nseg_type |= | |
2719 | (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT); | |
2720 | io_request->RaidContext.raid_context_g35.routing_flags |= | |
2721 | (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT); | |
d889344e | 2722 | io_request->IoFlags |= |
a174118b | 2723 | cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
36807e67 | 2724 | } |
5fc499b6 S |
2725 | if (fusion->load_balance_info && |
2726 | (fusion->load_balance_info[device_id].loadBalanceFlag) && | |
2727 | (io_info.isRead)) { | |
9c915a8c | 2728 | io_info.devHandle = |
d2552ebe | 2729 | get_updated_dev_handle(instance, |
9c915a8c | 2730 | &fusion->load_balance_info[device_id], |
33203bc4 | 2731 | &io_info, local_map_ptr); |
9c915a8c | 2732 | scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG; |
d2552ebe | 2733 | cmd->pd_r1_lb = io_info.pd_after_lb; |
f369a315 | 2734 | if (instance->adapter_type == VENTURA_SERIES) |
d889344e SC |
2735 | io_request->RaidContext.raid_context_g35.span_arm |
2736 | = io_info.span_arm; | |
2737 | else | |
2738 | io_request->RaidContext.raid_context.span_arm | |
2739 | = io_info.span_arm; | |
2740 | ||
9c915a8c AR |
2741 | } else |
2742 | scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; | |
5765c5b8 | 2743 | |
f369a315 | 2744 | if (instance->adapter_type == VENTURA_SERIES) |
69c337c0 | 2745 | cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle; |
8bf7c65d S |
2746 | else |
2747 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; | |
69c337c0 | 2748 | |
5765c5b8 | 2749 | if ((raidLUN[0] == 1) && |
75b96061 | 2750 | (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) { |
5765c5b8 SS |
2751 | instance->dev_handle = !(instance->dev_handle); |
2752 | io_info.devHandle = | |
2753 | local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle]; | |
2754 | } | |
2755 | ||
9c915a8c AR |
2756 | cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; |
2757 | io_request->DevHandle = io_info.devHandle; | |
33203bc4 | 2758 | cmd->pd_interface = io_info.pd_interface; |
21c9e160 AR |
2759 | /* populate the LUN field */ |
2760 | memcpy(io_request->LUN, raidLUN, 8); | |
9c915a8c | 2761 | } else { |
d889344e | 2762 | io_request->RaidContext.raid_context.timeout_value = |
94cd65dd | 2763 | cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec); |
9c915a8c AR |
2764 | cmd->request_desc->SCSIIO.RequestFlags = |
2765 | (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO | |
2766 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
c365178f | 2767 | if (instance->adapter_type == INVADER_SERIES) { |
8f05024c | 2768 | if (io_info.do_fp_rlbypass || |
d889344e | 2769 | (io_request->RaidContext.raid_context.reg_lock_flags |
fdd84e25 | 2770 | == REGION_TYPE_UNUSED)) |
36807e67 AR |
2771 | cmd->request_desc->SCSIIO.RequestFlags = |
2772 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << | |
2773 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
d889344e | 2774 | io_request->RaidContext.raid_context.type |
fdd84e25 | 2775 | = MPI2_TYPE_CUDA; |
d889344e | 2776 | io_request->RaidContext.raid_context.reg_lock_flags |= |
36807e67 AR |
2777 | (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | |
2778 | MR_RL_FLAGS_SEQ_NUM_ENABLE); | |
fdd84e25 | 2779 | io_request->RaidContext.raid_context.nseg = 0x1; |
f369a315 | 2780 | } else if (instance->adapter_type == VENTURA_SERIES) { |
a174118b S |
2781 | io_request->RaidContext.raid_context_g35.routing_flags |= |
2782 | (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT); | |
2783 | io_request->RaidContext.raid_context_g35.nseg_type |= | |
2784 | (1 << RAID_CONTEXT_NSEG_SHIFT); | |
2785 | io_request->RaidContext.raid_context_g35.nseg_type |= | |
2786 | (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT); | |
36807e67 AR |
2787 | } |
2788 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; | |
94cd65dd | 2789 | io_request->DevHandle = cpu_to_le16(device_id); |
d889344e | 2790 | |
9c915a8c AR |
2791 | } /* Not FP */ |
2792 | } | |
2793 | ||
2794 | /** | |
4a5c814d | 2795 | * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk |
9c915a8c AR |
2796 | * @instance: Adapter soft state |
2797 | * @scp: SCSI command | |
2798 | * @cmd: Command to be prepared | |
2799 | * | |
4a5c814d | 2800 | * Prepares the io_request frame for non-rw io cmds for vd. |
9c915a8c | 2801 | */ |
4a5c814d SS |
2802 | static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, |
2803 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd) | |
9c915a8c AR |
2804 | { |
2805 | u32 device_id; | |
2806 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; | |
25fb13dd | 2807 | u16 ld; |
51087a86 | 2808 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
9c915a8c | 2809 | struct fusion_context *fusion = instance->ctrl_context; |
21c9e160 | 2810 | u8 span, physArm; |
9ab9ed38 | 2811 | __le16 devHandle; |
d2d0358b | 2812 | u32 arRef, pd; |
21c9e160 AR |
2813 | struct MR_LD_RAID *raid; |
2814 | struct RAID_CONTEXT *pRAID_Context; | |
4a5c814d | 2815 | u8 fp_possible = 1; |
9c915a8c AR |
2816 | |
2817 | io_request = cmd->io_request; | |
4a5c814d | 2818 | device_id = MEGASAS_DEV_INDEX(scmd); |
51087a86 | 2819 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
94cd65dd | 2820 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
4a5c814d | 2821 | /* get RAID_Context pointer */ |
fdd84e25 | 2822 | pRAID_Context = &io_request->RaidContext.raid_context; |
4a5c814d | 2823 | /* Check with FW team */ |
d889344e SC |
2824 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
2825 | pRAID_Context->reg_lock_row_lba = 0; | |
2826 | pRAID_Context->reg_lock_length = 0; | |
21c9e160 | 2827 | |
4a5c814d SS |
2828 | if (fusion->fast_path_io && ( |
2829 | device_id < instance->fw_supported_vd_count)) { | |
ab2f0608 | 2830 | |
21c9e160 | 2831 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
b6b3ed87 | 2832 | if (ld >= instance->fw_supported_vd_count - 1) |
4a5c814d | 2833 | fp_possible = 0; |
d2d0358b S |
2834 | else { |
2835 | raid = MR_LdRaidGet(ld, local_map_ptr); | |
2836 | if (!(raid->capability.fpNonRWCapable)) | |
2837 | fp_possible = 0; | |
2838 | } | |
4a5c814d SS |
2839 | } else |
2840 | fp_possible = 0; | |
21c9e160 | 2841 | |
4a5c814d SS |
2842 | if (!fp_possible) { |
2843 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; | |
2844 | io_request->DevHandle = cpu_to_le16(device_id); | |
2845 | io_request->LUN[1] = scmd->device->lun; | |
d889344e | 2846 | pRAID_Context->timeout_value = |
4a5c814d SS |
2847 | cpu_to_le16 (scmd->request->timeout / HZ); |
2848 | cmd->request_desc->SCSIIO.RequestFlags = | |
2849 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << | |
2850 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
2851 | } else { | |
21c9e160 AR |
2852 | |
2853 | /* set RAID context values */ | |
d889344e | 2854 | pRAID_Context->config_seq_num = raid->seqNum; |
f369a315 | 2855 | if (instance->adapter_type != VENTURA_SERIES) |
d889344e SC |
2856 | pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ; |
2857 | pRAID_Context->timeout_value = | |
2858 | cpu_to_le16(raid->fpIoTimeoutForLd); | |
21c9e160 AR |
2859 | |
2860 | /* get the DevHandle for the PD (since this is | |
2861 | fpNonRWCapable, this is a single disk RAID0) */ | |
2862 | span = physArm = 0; | |
2863 | arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr); | |
2864 | pd = MR_ArPdGet(arRef, physArm, local_map_ptr); | |
2865 | devHandle = MR_PdDevHandleGet(pd, local_map_ptr); | |
2866 | ||
2867 | /* build request descriptor */ | |
2868 | cmd->request_desc->SCSIIO.RequestFlags = | |
2c048351 | 2869 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO << |
4a5c814d | 2870 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
21c9e160 AR |
2871 | cmd->request_desc->SCSIIO.DevHandle = devHandle; |
2872 | ||
2873 | /* populate the LUN field */ | |
2874 | memcpy(io_request->LUN, raid->LUN, 8); | |
2875 | ||
2876 | /* build the raidScsiIO structure */ | |
2877 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
2878 | io_request->DevHandle = devHandle; | |
4a5c814d SS |
2879 | } |
2880 | } | |
21c9e160 | 2881 | |
4a5c814d SS |
2882 | /** |
2883 | * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd | |
2884 | * @instance: Adapter soft state | |
2885 | * @scp: SCSI command | |
2886 | * @cmd: Command to be prepared | |
2887 | * @fp_possible: parameter to detect fast path or firmware path io. | |
2888 | * | |
2889 | * Prepares the io_request frame for rw/non-rw io cmds for syspds | |
2890 | */ | |
2891 | static void | |
2892 | megasas_build_syspd_fusion(struct megasas_instance *instance, | |
1d6dbd17 S |
2893 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd, |
2894 | bool fp_possible) | |
4a5c814d SS |
2895 | { |
2896 | u32 device_id; | |
2897 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; | |
2898 | u16 pd_index = 0; | |
2899 | u16 os_timeout_value; | |
2900 | u16 timeout_limit; | |
2901 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; | |
2902 | struct RAID_CONTEXT *pRAID_Context; | |
3761cb4c | 2903 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
33203bc4 | 2904 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
4a5c814d | 2905 | struct fusion_context *fusion = instance->ctrl_context; |
3761cb4c | 2906 | pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1]; |
4a5c814d SS |
2907 | |
2908 | device_id = MEGASAS_DEV_INDEX(scmd); | |
2909 | pd_index = MEGASAS_PD_INDEX(scmd); | |
2910 | os_timeout_value = scmd->request->timeout / HZ; | |
33203bc4 S |
2911 | mr_device_priv_data = scmd->device->hostdata; |
2912 | cmd->pd_interface = mr_device_priv_data->interface_type; | |
21c9e160 | 2913 | |
4a5c814d SS |
2914 | io_request = cmd->io_request; |
2915 | /* get RAID_Context pointer */ | |
fdd84e25 | 2916 | pRAID_Context = &io_request->RaidContext.raid_context; |
d889344e SC |
2917 | pRAID_Context->reg_lock_flags = 0; |
2918 | pRAID_Context->reg_lock_row_lba = 0; | |
2919 | pRAID_Context->reg_lock_length = 0; | |
4a5c814d SS |
2920 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
2921 | io_request->LUN[1] = scmd->device->lun; | |
d889344e | 2922 | pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD |
4a5c814d SS |
2923 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT; |
2924 | ||
3761cb4c | 2925 | /* If FW supports PD sequence number */ |
2926 | if (instance->use_seqnum_jbod_fp && | |
2927 | instance->pd_list[pd_index].driveType == TYPE_DISK) { | |
2928 | /* TgtId must be incremented by 255 as jbod seq number is index | |
2929 | * below raid map | |
2930 | */ | |
ede7c3ce SC |
2931 | /* More than 256 PD/JBOD support for Ventura */ |
2932 | if (instance->support_morethan256jbod) | |
2933 | pRAID_Context->virtual_disk_tgt_id = | |
2934 | pd_sync->seq[pd_index].pd_target_id; | |
2935 | else | |
a174118b S |
2936 | pRAID_Context->virtual_disk_tgt_id = |
2937 | cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1)); | |
d889344e | 2938 | pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum; |
3761cb4c | 2939 | io_request->DevHandle = pd_sync->seq[pd_index].devHandle; |
f369a315 | 2940 | if (instance->adapter_type == VENTURA_SERIES) { |
a174118b S |
2941 | io_request->RaidContext.raid_context_g35.routing_flags |= |
2942 | (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT); | |
2943 | io_request->RaidContext.raid_context_g35.nseg_type |= | |
2944 | (1 << RAID_CONTEXT_NSEG_SHIFT); | |
2945 | io_request->RaidContext.raid_context_g35.nseg_type |= | |
2946 | (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT); | |
2947 | } else { | |
2948 | pRAID_Context->type = MPI2_TYPE_CUDA; | |
2949 | pRAID_Context->nseg = 0x1; | |
2950 | pRAID_Context->reg_lock_flags |= | |
2951 | (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA); | |
2952 | } | |
3761cb4c | 2953 | } else if (fusion->fast_path_io) { |
d889344e SC |
2954 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
2955 | pRAID_Context->config_seq_num = 0; | |
3761cb4c | 2956 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
2957 | io_request->DevHandle = | |
2958 | local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; | |
2959 | } else { | |
2960 | /* Want to send all IO via FW path */ | |
d889344e SC |
2961 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
2962 | pRAID_Context->config_seq_num = 0; | |
9fb74c4e | 2963 | io_request->DevHandle = cpu_to_le16(0xFFFF); |
3761cb4c | 2964 | } |
4a5c814d SS |
2965 | |
2966 | cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; | |
4a5c814d | 2967 | |
99fe57b3 ML |
2968 | cmd->request_desc->SCSIIO.MSIxIndex = |
2969 | instance->reply_map[raw_smp_processor_id()]; | |
4a5c814d SS |
2970 | |
2971 | if (!fp_possible) { | |
2972 | /* system pd firmware path */ | |
9c915a8c | 2973 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
9c915a8c AR |
2974 | cmd->request_desc->SCSIIO.RequestFlags = |
2975 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << | |
4a5c814d | 2976 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
d889344e SC |
2977 | pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value); |
2978 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); | |
4a5c814d | 2979 | } else { |
30086fb1 S |
2980 | if (os_timeout_value) |
2981 | os_timeout_value++; | |
2982 | ||
4a5c814d SS |
2983 | /* system pd Fast Path */ |
2984 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4a5c814d SS |
2985 | timeout_limit = (scmd->device->type == TYPE_DISK) ? |
2986 | 255 : 0xFFFF; | |
d889344e | 2987 | pRAID_Context->timeout_value = |
4a5c814d SS |
2988 | cpu_to_le16((os_timeout_value > timeout_limit) ? |
2989 | timeout_limit : os_timeout_value); | |
c365178f | 2990 | if (instance->adapter_type >= INVADER_SERIES) |
4a5c814d SS |
2991 | io_request->IoFlags |= |
2992 | cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); | |
d5573584 | 2993 | |
4a5c814d | 2994 | cmd->request_desc->SCSIIO.RequestFlags = |
2c048351 | 2995 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO << |
4a5c814d | 2996 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
9c915a8c | 2997 | } |
9c915a8c AR |
2998 | } |
2999 | ||
3000 | /** | |
3001 | * megasas_build_io_fusion - Prepares IOs to devices | |
3002 | * @instance: Adapter soft state | |
3003 | * @scp: SCSI command | |
3004 | * @cmd: Command to be prepared | |
3005 | * | |
3006 | * Invokes helper functions to prepare request frames | |
3007 | * and sets flags appropriate for IO/Non-IO cmd | |
3008 | */ | |
3009 | int | |
3010 | megasas_build_io_fusion(struct megasas_instance *instance, | |
3011 | struct scsi_cmnd *scp, | |
3012 | struct megasas_cmd_fusion *cmd) | |
3013 | { | |
33203bc4 | 3014 | int sge_count; |
4a5c814d | 3015 | u8 cmd_type; |
9c915a8c | 3016 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request; |
1d6dbd17 S |
3017 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
3018 | mr_device_priv_data = scp->device->hostdata; | |
9c915a8c | 3019 | |
9c915a8c | 3020 | /* Zero out some fields so they don't get reused */ |
9cb78c16 | 3021 | memset(io_request->LUN, 0x0, 8); |
9c915a8c AR |
3022 | io_request->CDB.EEDP32.PrimaryReferenceTag = 0; |
3023 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0; | |
3024 | io_request->EEDPFlags = 0; | |
3025 | io_request->Control = 0; | |
3026 | io_request->EEDPBlockSize = 0; | |
36807e67 | 3027 | io_request->ChainOffset = 0; |
d889344e SC |
3028 | io_request->RaidContext.raid_context.raid_flags = 0; |
3029 | io_request->RaidContext.raid_context.type = 0; | |
fdd84e25 | 3030 | io_request->RaidContext.raid_context.nseg = 0; |
9c915a8c AR |
3031 | |
3032 | memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len); | |
3033 | /* | |
3034 | * Just the CDB length,rest of the Flags are zero | |
3035 | * This will be modified for FP in build_ldio_fusion | |
3036 | */ | |
94cd65dd | 3037 | io_request->IoFlags = cpu_to_le16(scp->cmd_len); |
9c915a8c | 3038 | |
4a5c814d SS |
3039 | switch (cmd_type = megasas_cmd_type(scp)) { |
3040 | case READ_WRITE_LDIO: | |
9c915a8c | 3041 | megasas_build_ldio_fusion(instance, scp, cmd); |
4a5c814d SS |
3042 | break; |
3043 | case NON_READ_WRITE_LDIO: | |
3044 | megasas_build_ld_nonrw_fusion(instance, scp, cmd); | |
3045 | break; | |
3046 | case READ_WRITE_SYSPDIO: | |
1d6dbd17 S |
3047 | megasas_build_syspd_fusion(instance, scp, cmd, true); |
3048 | break; | |
4a5c814d | 3049 | case NON_READ_WRITE_SYSPDIO: |
1d6dbd17 S |
3050 | if (instance->secure_jbod_support || |
3051 | mr_device_priv_data->is_tm_capable) | |
3052 | megasas_build_syspd_fusion(instance, scp, cmd, false); | |
4a5c814d | 3053 | else |
1d6dbd17 | 3054 | megasas_build_syspd_fusion(instance, scp, cmd, true); |
4a5c814d SS |
3055 | break; |
3056 | default: | |
3057 | break; | |
3058 | } | |
9c915a8c AR |
3059 | |
3060 | /* | |
3061 | * Construct SGL | |
3062 | */ | |
3063 | ||
33203bc4 | 3064 | sge_count = megasas_make_sgl(instance, scp, cmd); |
9c915a8c | 3065 | |
33203bc4 S |
3066 | if (sge_count > instance->max_num_sge || (sge_count < 0)) { |
3067 | dev_err(&instance->pdev->dev, | |
3068 | "%s %d sge_count (%d) is out of range. Range is: 0-%d\n", | |
3069 | __func__, __LINE__, sge_count, instance->max_num_sge); | |
9c915a8c AR |
3070 | return 1; |
3071 | } | |
3072 | ||
f369a315 | 3073 | if (instance->adapter_type == VENTURA_SERIES) { |
a174118b S |
3074 | set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count); |
3075 | cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags); | |
3076 | cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type); | |
3077 | } else { | |
d889344e SC |
3078 | /* numSGE store lower 8 bit of sge_count. |
3079 | * numSGEExt store higher 8 bit of sge_count | |
3080 | */ | |
3081 | io_request->RaidContext.raid_context.num_sge = sge_count; | |
3082 | io_request->RaidContext.raid_context.num_sge_ext = | |
3083 | (u8)(sge_count >> 8); | |
3084 | } | |
9c915a8c | 3085 | |
94cd65dd | 3086 | io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING); |
9c915a8c AR |
3087 | |
3088 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) | |
94cd65dd | 3089 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE); |
9c915a8c | 3090 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
94cd65dd | 3091 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ); |
9c915a8c AR |
3092 | |
3093 | io_request->SGLOffset0 = | |
3094 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4; | |
3095 | ||
107a60dd S |
3096 | io_request->SenseBufferLowAddress = |
3097 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); | |
9c915a8c AR |
3098 | io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
3099 | ||
3100 | cmd->scmd = scp; | |
3101 | scp->SCp.ptr = (char *)cmd; | |
3102 | ||
3103 | return 0; | |
3104 | } | |
3105 | ||
52205ac8 | 3106 | static union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
9c915a8c AR |
3107 | megasas_get_request_descriptor(struct megasas_instance *instance, u16 index) |
3108 | { | |
3109 | u8 *p; | |
3110 | struct fusion_context *fusion; | |
3111 | ||
9c915a8c | 3112 | fusion = instance->ctrl_context; |
69c337c0 SC |
3113 | p = fusion->req_frames_desc + |
3114 | sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index; | |
9c915a8c AR |
3115 | |
3116 | return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p; | |
3117 | } | |
3118 | ||
69c337c0 SC |
3119 | |
3120 | /* megasas_prepate_secondRaid1_IO | |
3121 | * It prepares the raid 1 second IO | |
3122 | */ | |
3123 | void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance, | |
3124 | struct megasas_cmd_fusion *cmd, | |
3125 | struct megasas_cmd_fusion *r1_cmd) | |
3126 | { | |
3127 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL; | |
3128 | struct fusion_context *fusion; | |
69c337c0 SC |
3129 | fusion = instance->ctrl_context; |
3130 | req_desc = cmd->request_desc; | |
8bf7c65d S |
3131 | /* copy the io request frame as well as 8 SGEs data for r1 command*/ |
3132 | memcpy(r1_cmd->io_request, cmd->io_request, | |
3133 | (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST))); | |
3134 | memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL, | |
3135 | (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION))); | |
3136 | /*sense buffer is different for r1 command*/ | |
3137 | r1_cmd->io_request->SenseBufferLowAddress = | |
107a60dd | 3138 | cpu_to_le32(lower_32_bits(r1_cmd->sense_phys_addr)); |
8bf7c65d S |
3139 | r1_cmd->scmd = cmd->scmd; |
3140 | req_desc2 = megasas_get_request_descriptor(instance, | |
3141 | (r1_cmd->index - 1)); | |
3142 | req_desc2->Words = 0; | |
3143 | r1_cmd->request_desc = req_desc2; | |
3144 | req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index); | |
3145 | req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags; | |
3146 | r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle; | |
3147 | r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle; | |
3148 | r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle; | |
3149 | cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid = | |
3150 | cpu_to_le16(r1_cmd->index); | |
3151 | r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid = | |
3152 | cpu_to_le16(cmd->index); | |
3153 | /*MSIxIndex of both commands request descriptors should be same*/ | |
3154 | r1_cmd->request_desc->SCSIIO.MSIxIndex = | |
3155 | cmd->request_desc->SCSIIO.MSIxIndex; | |
3156 | /*span arm is different for r1 cmd*/ | |
3157 | r1_cmd->io_request->RaidContext.raid_context_g35.span_arm = | |
69c337c0 | 3158 | cmd->io_request->RaidContext.raid_context_g35.span_arm + 1; |
69c337c0 SC |
3159 | } |
3160 | ||
9c915a8c AR |
3161 | /** |
3162 | * megasas_build_and_issue_cmd_fusion -Main routine for building and | |
3163 | * issuing non IOCTL cmd | |
3164 | * @instance: Adapter soft state | |
3165 | * @scmd: pointer to scsi cmd from OS | |
3166 | */ | |
3167 | static u32 | |
3168 | megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, | |
3169 | struct scsi_cmnd *scmd) | |
3170 | { | |
69c337c0 | 3171 | struct megasas_cmd_fusion *cmd, *r1_cmd = NULL; |
9c915a8c AR |
3172 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
3173 | u32 index; | |
3174 | struct fusion_context *fusion; | |
3175 | ||
3176 | fusion = instance->ctrl_context; | |
3177 | ||
308ec459 SS |
3178 | if ((megasas_cmd_type(scmd) == READ_WRITE_LDIO) && |
3179 | instance->ldio_threshold && | |
3180 | (atomic_inc_return(&instance->ldio_outstanding) > | |
3181 | instance->ldio_threshold)) { | |
3182 | atomic_dec(&instance->ldio_outstanding); | |
3183 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
3184 | } | |
3185 | ||
69c337c0 SC |
3186 | if (atomic_inc_return(&instance->fw_outstanding) > |
3187 | instance->host->can_queue) { | |
69c337c0 SC |
3188 | atomic_dec(&instance->fw_outstanding); |
3189 | return SCSI_MLQUEUE_HOST_BUSY; | |
3190 | } | |
3191 | ||
4026e9aa | 3192 | cmd = megasas_get_cmd_fusion(instance, scmd->request->tag); |
9c915a8c | 3193 | |
69c337c0 SC |
3194 | if (!cmd) { |
3195 | atomic_dec(&instance->fw_outstanding); | |
3196 | return SCSI_MLQUEUE_HOST_BUSY; | |
3197 | } | |
3198 | ||
9c915a8c AR |
3199 | index = cmd->index; |
3200 | ||
3201 | req_desc = megasas_get_request_descriptor(instance, index-1); | |
9c915a8c AR |
3202 | |
3203 | req_desc->Words = 0; | |
3204 | cmd->request_desc = req_desc; | |
9c915a8c AR |
3205 | |
3206 | if (megasas_build_io_fusion(instance, scmd, cmd)) { | |
3207 | megasas_return_cmd_fusion(instance, cmd); | |
1be18254 | 3208 | dev_err(&instance->pdev->dev, "Error building command\n"); |
9c915a8c | 3209 | cmd->request_desc = NULL; |
69c337c0 | 3210 | atomic_dec(&instance->fw_outstanding); |
f9a9dee6 | 3211 | return SCSI_MLQUEUE_HOST_BUSY; |
9c915a8c AR |
3212 | } |
3213 | ||
3214 | req_desc = cmd->request_desc; | |
94cd65dd | 3215 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
9c915a8c AR |
3216 | |
3217 | if (cmd->io_request->ChainOffset != 0 && | |
3218 | cmd->io_request->ChainOffset != 0xF) | |
1be18254 | 3219 | dev_err(&instance->pdev->dev, "The chain offset value is not " |
9c915a8c | 3220 | "correct : %x\n", cmd->io_request->ChainOffset); |
69c337c0 SC |
3221 | /* |
3222 | * if it is raid 1/10 fp write capable. | |
3223 | * try to get second command from pool and construct it. | |
3224 | * From FW, it has confirmed that lba values of two PDs | |
3225 | * corresponds to single R1/10 LD are always same | |
3226 | * | |
3227 | */ | |
3228 | /* driver side count always should be less than max_fw_cmds | |
3229 | * to get new command | |
3230 | */ | |
8bf7c65d | 3231 | if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) { |
69c337c0 SC |
3232 | r1_cmd = megasas_get_cmd_fusion(instance, |
3233 | (scmd->request->tag + instance->max_fw_cmds)); | |
3234 | megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd); | |
3235 | } | |
3236 | ||
18bbcabd | 3237 | |
9c915a8c AR |
3238 | /* |
3239 | * Issue the command to the FW | |
3240 | */ | |
9c915a8c | 3241 | |
45b8a35e | 3242 | megasas_fire_cmd_fusion(instance, req_desc); |
9c915a8c | 3243 | |
18bbcabd | 3244 | if (r1_cmd) |
45b8a35e | 3245 | megasas_fire_cmd_fusion(instance, r1_cmd->request_desc); |
18bbcabd | 3246 | |
69c337c0 | 3247 | |
9c915a8c AR |
3248 | return 0; |
3249 | } | |
3250 | ||
8bf7c65d S |
3251 | /** |
3252 | * megasas_complete_r1_command - | |
3253 | * completes R1 FP write commands which has valid peer smid | |
3254 | * @instance: Adapter soft state | |
3255 | * @cmd_fusion: MPT command frame | |
3256 | * | |
3257 | */ | |
3258 | static inline void | |
3259 | megasas_complete_r1_command(struct megasas_instance *instance, | |
3260 | struct megasas_cmd_fusion *cmd) | |
3261 | { | |
3262 | u8 *sense, status, ex_status; | |
3263 | u32 data_length; | |
3264 | u16 peer_smid; | |
3265 | struct fusion_context *fusion; | |
3266 | struct megasas_cmd_fusion *r1_cmd = NULL; | |
3267 | struct scsi_cmnd *scmd_local = NULL; | |
3268 | struct RAID_CONTEXT_G35 *rctx_g35; | |
3269 | ||
3270 | rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35; | |
3271 | fusion = instance->ctrl_context; | |
3272 | peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid); | |
3273 | ||
3274 | r1_cmd = fusion->cmd_list[peer_smid - 1]; | |
3275 | scmd_local = cmd->scmd; | |
3276 | status = rctx_g35->status; | |
3277 | ex_status = rctx_g35->ex_status; | |
3278 | data_length = cmd->io_request->DataLength; | |
3279 | sense = cmd->sense; | |
3280 | ||
3281 | cmd->cmd_completed = true; | |
3282 | ||
3283 | /* Check if peer command is completed or not*/ | |
3284 | if (r1_cmd->cmd_completed) { | |
3285 | rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35; | |
3286 | if (rctx_g35->status != MFI_STAT_OK) { | |
3287 | status = rctx_g35->status; | |
3288 | ex_status = rctx_g35->ex_status; | |
3289 | data_length = r1_cmd->io_request->DataLength; | |
3290 | sense = r1_cmd->sense; | |
3291 | } | |
3292 | ||
3293 | megasas_return_cmd_fusion(instance, r1_cmd); | |
3294 | map_cmd_status(fusion, scmd_local, status, ex_status, | |
3295 | le32_to_cpu(data_length), sense); | |
3296 | if (instance->ldio_threshold && | |
3297 | megasas_cmd_type(scmd_local) == READ_WRITE_LDIO) | |
3298 | atomic_dec(&instance->ldio_outstanding); | |
3299 | scmd_local->SCp.ptr = NULL; | |
3300 | megasas_return_cmd_fusion(instance, cmd); | |
3301 | scsi_dma_unmap(scmd_local); | |
3302 | scmd_local->scsi_done(scmd_local); | |
3303 | } | |
3304 | } | |
3305 | ||
9c915a8c AR |
3306 | /** |
3307 | * complete_cmd_fusion - Completes command | |
3308 | * @instance: Adapter soft state | |
3309 | * Completes all commands that is in reply descriptor queue | |
3310 | */ | |
3311 | int | |
c8e858fe | 3312 | complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) |
9c915a8c AR |
3313 | { |
3314 | union MPI2_REPLY_DESCRIPTORS_UNION *desc; | |
3315 | struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc; | |
3316 | struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req; | |
3317 | struct fusion_context *fusion; | |
3318 | struct megasas_cmd *cmd_mfi; | |
8bf7c65d | 3319 | struct megasas_cmd_fusion *cmd_fusion; |
9c915a8c | 3320 | u16 smid, num_completed; |
8bf7c65d S |
3321 | u8 reply_descript_type, *sense, status, extStatus; |
3322 | u32 device_id, data_length; | |
9c915a8c AR |
3323 | union desc_value d_val; |
3324 | struct LD_LOAD_BALANCE_INFO *lbinfo; | |
db4fc864 | 3325 | int threshold_reply_count = 0; |
4026e9aa | 3326 | struct scsi_cmnd *scmd_local = NULL; |
18365b13 SS |
3327 | struct MR_TASK_MANAGE_REQUEST *mr_tm_req; |
3328 | struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_tm_req; | |
9c915a8c AR |
3329 | |
3330 | fusion = instance->ctrl_context; | |
3331 | ||
8a01a41d | 3332 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
9c915a8c AR |
3333 | return IRQ_HANDLED; |
3334 | ||
179ac142 SS |
3335 | desc = fusion->reply_frames_desc[MSIxIndex] + |
3336 | fusion->last_reply_idx[MSIxIndex]; | |
9c915a8c AR |
3337 | |
3338 | reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; | |
3339 | ||
3340 | d_val.word = desc->Words; | |
3341 | ||
3342 | reply_descript_type = reply_desc->ReplyFlags & | |
3343 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; | |
3344 | ||
3345 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) | |
3346 | return IRQ_NONE; | |
3347 | ||
9c915a8c AR |
3348 | num_completed = 0; |
3349 | ||
c6f5bf81 CH |
3350 | while (d_val.u.low != cpu_to_le32(UINT_MAX) && |
3351 | d_val.u.high != cpu_to_le32(UINT_MAX)) { | |
69c337c0 | 3352 | |
94cd65dd | 3353 | smid = le16_to_cpu(reply_desc->SMID); |
9c915a8c | 3354 | cmd_fusion = fusion->cmd_list[smid - 1]; |
8bf7c65d S |
3355 | scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *) |
3356 | cmd_fusion->io_request; | |
9c915a8c | 3357 | |
4026e9aa | 3358 | scmd_local = cmd_fusion->scmd; |
fdd84e25 | 3359 | status = scsi_io_req->RaidContext.raid_context.status; |
d889344e | 3360 | extStatus = scsi_io_req->RaidContext.raid_context.ex_status; |
69c337c0 SC |
3361 | sense = cmd_fusion->sense; |
3362 | data_length = scsi_io_req->DataLength; | |
9c915a8c AR |
3363 | |
3364 | switch (scsi_io_req->Function) { | |
18365b13 SS |
3365 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
3366 | mr_tm_req = (struct MR_TASK_MANAGE_REQUEST *) | |
3367 | cmd_fusion->io_request; | |
3368 | mpi_tm_req = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) | |
3369 | &mr_tm_req->TmRequest; | |
3370 | dev_dbg(&instance->pdev->dev, "TM completion:" | |
3371 | "type: 0x%x TaskMID: 0x%x\n", | |
3372 | mpi_tm_req->TaskType, mpi_tm_req->TaskMID); | |
3373 | complete(&cmd_fusion->done); | |
3374 | break; | |
9c915a8c AR |
3375 | case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/ |
3376 | /* Update load balancing info */ | |
8bf7c65d S |
3377 | if (fusion->load_balance_info && |
3378 | (cmd_fusion->scmd->SCp.Status & | |
3379 | MEGASAS_LOAD_BALANCE_FLAG)) { | |
3380 | device_id = MEGASAS_DEV_INDEX(scmd_local); | |
3381 | lbinfo = &fusion->load_balance_info[device_id]; | |
d2552ebe | 3382 | atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]); |
8bf7c65d | 3383 | cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; |
9c915a8c | 3384 | } |
8bf7c65d | 3385 | //Fall thru and complete IO |
9c915a8c | 3386 | case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */ |
8bf7c65d S |
3387 | atomic_dec(&instance->fw_outstanding); |
3388 | if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) { | |
69c337c0 | 3389 | map_cmd_status(fusion, scmd_local, status, |
8bf7c65d S |
3390 | extStatus, le32_to_cpu(data_length), |
3391 | sense); | |
3392 | if (instance->ldio_threshold && | |
3393 | (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)) | |
b71b49c2 | 3394 | atomic_dec(&instance->ldio_outstanding); |
8bf7c65d | 3395 | scmd_local->SCp.ptr = NULL; |
69c337c0 SC |
3396 | megasas_return_cmd_fusion(instance, cmd_fusion); |
3397 | scsi_dma_unmap(scmd_local); | |
3398 | scmd_local->scsi_done(scmd_local); | |
8bf7c65d S |
3399 | } else /* Optimal VD - R1 FP command completion. */ |
3400 | megasas_complete_r1_command(instance, cmd_fusion); | |
9c915a8c AR |
3401 | break; |
3402 | case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */ | |
3403 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; | |
4026e9aa SS |
3404 | /* Poll mode. Dummy free. |
3405 | * In case of Interrupt mode, caller has reverse check. | |
3406 | */ | |
3407 | if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) { | |
3408 | cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE; | |
3409 | megasas_return_cmd(instance, cmd_mfi); | |
3410 | } else | |
3411 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); | |
9c915a8c AR |
3412 | break; |
3413 | } | |
3414 | ||
c8e858fe AR |
3415 | fusion->last_reply_idx[MSIxIndex]++; |
3416 | if (fusion->last_reply_idx[MSIxIndex] >= | |
3417 | fusion->reply_q_depth) | |
3418 | fusion->last_reply_idx[MSIxIndex] = 0; | |
9c915a8c | 3419 | |
c6f5bf81 | 3420 | desc->Words = cpu_to_le64(ULLONG_MAX); |
9c915a8c | 3421 | num_completed++; |
db4fc864 | 3422 | threshold_reply_count++; |
9c915a8c AR |
3423 | |
3424 | /* Get the next reply descriptor */ | |
c8e858fe | 3425 | if (!fusion->last_reply_idx[MSIxIndex]) |
179ac142 | 3426 | desc = fusion->reply_frames_desc[MSIxIndex]; |
9c915a8c AR |
3427 | else |
3428 | desc++; | |
3429 | ||
3430 | reply_desc = | |
3431 | (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; | |
3432 | ||
3433 | d_val.word = desc->Words; | |
3434 | ||
3435 | reply_descript_type = reply_desc->ReplyFlags & | |
3436 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; | |
3437 | ||
3438 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) | |
3439 | break; | |
db4fc864 SS |
3440 | /* |
3441 | * Write to reply post host index register after completing threshold | |
3442 | * number of reply counts and still there are more replies in reply queue | |
3443 | * pending to be completed | |
3444 | */ | |
3445 | if (threshold_reply_count >= THRESHOLD_REPLY_COUNT) { | |
2493c67e | 3446 | if (instance->msix_combined) |
db4fc864 SS |
3447 | writel(((MSIxIndex & 0x7) << 24) | |
3448 | fusion->last_reply_idx[MSIxIndex], | |
3449 | instance->reply_post_host_index_addr[MSIxIndex/8]); | |
3450 | else | |
3451 | writel((MSIxIndex << 24) | | |
3452 | fusion->last_reply_idx[MSIxIndex], | |
3453 | instance->reply_post_host_index_addr[0]); | |
3454 | threshold_reply_count = 0; | |
3455 | } | |
9c915a8c AR |
3456 | } |
3457 | ||
3458 | if (!num_completed) | |
3459 | return IRQ_NONE; | |
3460 | ||
3461 | wmb(); | |
2493c67e | 3462 | if (instance->msix_combined) |
d46a3ad6 SS |
3463 | writel(((MSIxIndex & 0x7) << 24) | |
3464 | fusion->last_reply_idx[MSIxIndex], | |
3465 | instance->reply_post_host_index_addr[MSIxIndex/8]); | |
3466 | else | |
3467 | writel((MSIxIndex << 24) | | |
3468 | fusion->last_reply_idx[MSIxIndex], | |
3469 | instance->reply_post_host_index_addr[0]); | |
53ef2bbd | 3470 | megasas_check_and_restore_queue_depth(instance); |
9c915a8c AR |
3471 | return IRQ_HANDLED; |
3472 | } | |
3473 | ||
29206da1 S |
3474 | /** |
3475 | * megasas_sync_irqs - Synchronizes all IRQs owned by adapter | |
3476 | * @instance: Adapter soft state | |
3477 | */ | |
3478 | void megasas_sync_irqs(unsigned long instance_addr) | |
3479 | { | |
3480 | u32 count, i; | |
3481 | struct megasas_instance *instance = | |
3482 | (struct megasas_instance *)instance_addr; | |
3483 | ||
3484 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; | |
3485 | ||
3486 | for (i = 0; i < count; i++) | |
3487 | synchronize_irq(pci_irq_vector(instance->pdev, i)); | |
3488 | } | |
3489 | ||
9c915a8c AR |
3490 | /** |
3491 | * megasas_complete_cmd_dpc_fusion - Completes command | |
3492 | * @instance: Adapter soft state | |
3493 | * | |
3494 | * Tasklet to complete cmds | |
3495 | */ | |
3496 | void | |
3497 | megasas_complete_cmd_dpc_fusion(unsigned long instance_addr) | |
3498 | { | |
3499 | struct megasas_instance *instance = | |
3500 | (struct megasas_instance *)instance_addr; | |
3501 | unsigned long flags; | |
c8e858fe AR |
3502 | u32 count, MSIxIndex; |
3503 | ||
3504 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; | |
9c915a8c AR |
3505 | |
3506 | /* If we have already declared adapter dead, donot complete cmds */ | |
3507 | spin_lock_irqsave(&instance->hba_lock, flags); | |
8a01a41d | 3508 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
9c915a8c AR |
3509 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
3510 | return; | |
3511 | } | |
3512 | spin_unlock_irqrestore(&instance->hba_lock, flags); | |
3513 | ||
c8e858fe AR |
3514 | for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++) |
3515 | complete_cmd_fusion(instance, MSIxIndex); | |
9c915a8c AR |
3516 | } |
3517 | ||
3518 | /** | |
3519 | * megasas_isr_fusion - isr entry point | |
3520 | */ | |
3521 | irqreturn_t megasas_isr_fusion(int irq, void *devp) | |
3522 | { | |
c8e858fe AR |
3523 | struct megasas_irq_context *irq_context = devp; |
3524 | struct megasas_instance *instance = irq_context->instance; | |
fc62b3fc | 3525 | u32 mfiStatus, fw_state, dma_state; |
9c915a8c | 3526 | |
d46a3ad6 SS |
3527 | if (instance->mask_interrupts) |
3528 | return IRQ_NONE; | |
3529 | ||
c8e858fe | 3530 | if (!instance->msix_vectors) { |
9c915a8c AR |
3531 | mfiStatus = instance->instancet->clear_intr(instance->reg_set); |
3532 | if (!mfiStatus) | |
3533 | return IRQ_NONE; | |
3534 | } | |
3535 | ||
3536 | /* If we are resetting, bail */ | |
6497b247 AR |
3537 | if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) { |
3538 | instance->instancet->clear_intr(instance->reg_set); | |
9c915a8c | 3539 | return IRQ_HANDLED; |
6497b247 | 3540 | } |
9c915a8c | 3541 | |
c8e858fe | 3542 | if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) { |
6497b247 | 3543 | instance->instancet->clear_intr(instance->reg_set); |
9c915a8c AR |
3544 | /* If we didn't complete any commands, check for FW fault */ |
3545 | fw_state = instance->instancet->read_fw_status_reg( | |
3546 | instance->reg_set) & MFI_STATE_MASK; | |
fc62b3fc SS |
3547 | dma_state = instance->instancet->read_fw_status_reg |
3548 | (instance->reg_set) & MFI_STATE_DMADONE; | |
3549 | if (instance->crash_dump_drv_support && | |
3550 | instance->crash_dump_app_support) { | |
3551 | /* Start collecting crash, if DMA bit is done */ | |
3552 | if ((fw_state == MFI_STATE_FAULT) && dma_state) | |
3553 | schedule_work(&instance->crash_init); | |
a1dfd62c KD |
3554 | else if (fw_state == MFI_STATE_FAULT) { |
3555 | if (instance->unload == 0) | |
3556 | schedule_work(&instance->work_init); | |
3557 | } | |
fc62b3fc | 3558 | } else if (fw_state == MFI_STATE_FAULT) { |
1be18254 | 3559 | dev_warn(&instance->pdev->dev, "Iop2SysDoorbellInt" |
229fe47c | 3560 | "for scsi%d\n", instance->host->host_no); |
a1dfd62c KD |
3561 | if (instance->unload == 0) |
3562 | schedule_work(&instance->work_init); | |
229fe47c | 3563 | } |
9c915a8c AR |
3564 | } |
3565 | ||
3566 | return IRQ_HANDLED; | |
3567 | } | |
3568 | ||
3569 | /** | |
3570 | * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru | |
3571 | * @instance: Adapter soft state | |
3572 | * mfi_cmd: megasas_cmd pointer | |
3573 | * | |
3574 | */ | |
7a7ae4f1 | 3575 | void |
9c915a8c AR |
3576 | build_mpt_mfi_pass_thru(struct megasas_instance *instance, |
3577 | struct megasas_cmd *mfi_cmd) | |
3578 | { | |
3579 | struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain; | |
3580 | struct MPI2_RAID_SCSI_IO_REQUEST *io_req; | |
3581 | struct megasas_cmd_fusion *cmd; | |
3582 | struct fusion_context *fusion; | |
3583 | struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr; | |
3584 | ||
4026e9aa SS |
3585 | fusion = instance->ctrl_context; |
3586 | ||
3587 | cmd = megasas_get_cmd_fusion(instance, | |
3588 | instance->max_scsi_cmds + mfi_cmd->index); | |
9c915a8c AR |
3589 | |
3590 | /* Save the smid. To be used for returning the cmd */ | |
3591 | mfi_cmd->context.smid = cmd->index; | |
90dc9d98 | 3592 | |
9c915a8c AR |
3593 | /* |
3594 | * For cmds where the flag is set, store the flag and check | |
3595 | * on completion. For cmds with this flag, don't call | |
3596 | * megasas_complete_cmd | |
3597 | */ | |
3598 | ||
6e755ddc | 3599 | if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)) |
4026e9aa | 3600 | mfi_cmd->flags |= DRV_DCMD_POLLED_MODE; |
9c915a8c | 3601 | |
9c915a8c | 3602 | io_req = cmd->io_request; |
36807e67 | 3603 | |
c365178f | 3604 | if (instance->adapter_type >= INVADER_SERIES) { |
36807e67 AR |
3605 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = |
3606 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL; | |
3607 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; | |
3608 | sgl_ptr_end->Flags = 0; | |
3609 | } | |
3610 | ||
9c915a8c AR |
3611 | mpi25_ieee_chain = |
3612 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain; | |
3613 | ||
3614 | io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST; | |
3615 | io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, | |
3616 | SGL) / 4; | |
3617 | io_req->ChainOffset = fusion->chain_offset_mfi_pthru; | |
3618 | ||
94cd65dd | 3619 | mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr); |
9c915a8c AR |
3620 | |
3621 | mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | | |
3622 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR; | |
3623 | ||
ed2983f4 | 3624 | mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size); |
9c915a8c AR |
3625 | } |
3626 | ||
3627 | /** | |
3628 | * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd | |
3629 | * @instance: Adapter soft state | |
3630 | * @cmd: mfi cmd to build | |
3631 | * | |
3632 | */ | |
3633 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * | |
3634 | build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) | |
3635 | { | |
52205ac8 | 3636 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL; |
9c915a8c AR |
3637 | u16 index; |
3638 | ||
7a7ae4f1 | 3639 | build_mpt_mfi_pass_thru(instance, cmd); |
9c915a8c AR |
3640 | index = cmd->context.smid; |
3641 | ||
3642 | req_desc = megasas_get_request_descriptor(instance, index - 1); | |
3643 | ||
9c915a8c AR |
3644 | req_desc->Words = 0; |
3645 | req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << | |
3646 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
3647 | ||
94cd65dd | 3648 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
9c915a8c AR |
3649 | |
3650 | return req_desc; | |
3651 | } | |
3652 | ||
3653 | /** | |
3654 | * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd | |
3655 | * @instance: Adapter soft state | |
3656 | * @cmd: mfi cmd pointer | |
3657 | * | |
3658 | */ | |
f4fc2093 | 3659 | void |
9c915a8c AR |
3660 | megasas_issue_dcmd_fusion(struct megasas_instance *instance, |
3661 | struct megasas_cmd *cmd) | |
3662 | { | |
3663 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; | |
9c915a8c AR |
3664 | |
3665 | req_desc = build_mpt_cmd(instance, cmd); | |
6d40afbc | 3666 | |
45b8a35e | 3667 | megasas_fire_cmd_fusion(instance, req_desc); |
f4fc2093 | 3668 | return; |
9c915a8c AR |
3669 | } |
3670 | ||
3671 | /** | |
3672 | * megasas_release_fusion - Reverses the FW initialization | |
4b63b286 | 3673 | * @instance: Adapter soft state |
9c915a8c AR |
3674 | */ |
3675 | void | |
3676 | megasas_release_fusion(struct megasas_instance *instance) | |
3677 | { | |
b9637d14 | 3678 | megasas_free_ioc_init_cmd(instance); |
9c915a8c AR |
3679 | megasas_free_cmds(instance); |
3680 | megasas_free_cmds_fusion(instance); | |
3681 | ||
3682 | iounmap(instance->reg_set); | |
3683 | ||
e7f85168 | 3684 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
9c915a8c AR |
3685 | } |
3686 | ||
3687 | /** | |
3688 | * megasas_read_fw_status_reg_fusion - returns the current FW status value | |
3689 | * @regs: MFI register set | |
3690 | */ | |
3691 | static u32 | |
3692 | megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs) | |
3693 | { | |
3694 | return readl(&(regs)->outbound_scratch_pad); | |
3695 | } | |
3696 | ||
fc62b3fc SS |
3697 | /** |
3698 | * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware | |
3699 | * @instance: Controller's soft instance | |
3700 | * return: Number of allocated host crash buffers | |
3701 | */ | |
3702 | static void | |
3703 | megasas_alloc_host_crash_buffer(struct megasas_instance *instance) | |
3704 | { | |
3705 | unsigned int i; | |
3706 | ||
fc62b3fc | 3707 | for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) { |
def3e8df | 3708 | instance->crash_buf[i] = vzalloc(CRASH_DMA_BUF_SIZE); |
fc62b3fc SS |
3709 | if (!instance->crash_buf[i]) { |
3710 | dev_info(&instance->pdev->dev, "Firmware crash dump " | |
3711 | "memory allocation failed at index %d\n", i); | |
3712 | break; | |
3713 | } | |
3714 | } | |
3715 | instance->drv_buf_alloc = i; | |
3716 | } | |
3717 | ||
3718 | /** | |
3719 | * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware | |
3720 | * @instance: Controller's soft instance | |
3721 | */ | |
3722 | void | |
3723 | megasas_free_host_crash_buffer(struct megasas_instance *instance) | |
3724 | { | |
def3e8df | 3725 | unsigned int i; |
fc62b3fc SS |
3726 | for (i = 0; i < instance->drv_buf_alloc; i++) { |
3727 | if (instance->crash_buf[i]) | |
def3e8df | 3728 | vfree(instance->crash_buf[i]); |
fc62b3fc SS |
3729 | } |
3730 | instance->drv_buf_index = 0; | |
3731 | instance->drv_buf_alloc = 0; | |
3732 | instance->fw_crash_state = UNAVAILABLE; | |
3733 | instance->fw_crash_buffer_size = 0; | |
3734 | } | |
3735 | ||
9c915a8c AR |
3736 | /** |
3737 | * megasas_adp_reset_fusion - For controller reset | |
3738 | * @regs: MFI register set | |
3739 | */ | |
3740 | static int | |
3741 | megasas_adp_reset_fusion(struct megasas_instance *instance, | |
3742 | struct megasas_register_set __iomem *regs) | |
3743 | { | |
79b82c2c | 3744 | u32 host_diag, abs_state, retry; |
3745 | ||
3746 | /* Now try to reset the chip */ | |
3747 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3748 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3749 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3750 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3751 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3752 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3753 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); | |
3754 | ||
3755 | /* Check that the diag write enable (DRWE) bit is on */ | |
3756 | host_diag = readl(&instance->reg_set->fusion_host_diag); | |
3757 | retry = 0; | |
3758 | while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) { | |
3759 | msleep(100); | |
3760 | host_diag = readl(&instance->reg_set->fusion_host_diag); | |
3761 | if (retry++ == 100) { | |
3762 | dev_warn(&instance->pdev->dev, | |
3763 | "Host diag unlock failed from %s %d\n", | |
3764 | __func__, __LINE__); | |
3765 | break; | |
3766 | } | |
3767 | } | |
3768 | if (!(host_diag & HOST_DIAG_WRITE_ENABLE)) | |
3769 | return -1; | |
3770 | ||
3771 | /* Send chip reset command */ | |
3772 | writel(host_diag | HOST_DIAG_RESET_ADAPTER, | |
3773 | &instance->reg_set->fusion_host_diag); | |
3774 | msleep(3000); | |
3775 | ||
3776 | /* Make sure reset adapter bit is cleared */ | |
3777 | host_diag = readl(&instance->reg_set->fusion_host_diag); | |
3778 | retry = 0; | |
3779 | while (host_diag & HOST_DIAG_RESET_ADAPTER) { | |
3780 | msleep(100); | |
3781 | host_diag = readl(&instance->reg_set->fusion_host_diag); | |
3782 | if (retry++ == 1000) { | |
3783 | dev_warn(&instance->pdev->dev, | |
3784 | "Diag reset adapter never cleared %s %d\n", | |
3785 | __func__, __LINE__); | |
3786 | break; | |
3787 | } | |
3788 | } | |
3789 | if (host_diag & HOST_DIAG_RESET_ADAPTER) | |
3790 | return -1; | |
3791 | ||
3792 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set) | |
3793 | & MFI_STATE_MASK; | |
3794 | retry = 0; | |
3795 | ||
3796 | while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) { | |
3797 | msleep(100); | |
3798 | abs_state = instance->instancet-> | |
3799 | read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; | |
3800 | } | |
3801 | if (abs_state <= MFI_STATE_FW_INIT) { | |
3802 | dev_warn(&instance->pdev->dev, | |
3803 | "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n", | |
3804 | abs_state, __func__, __LINE__); | |
3805 | return -1; | |
3806 | } | |
3807 | ||
9c915a8c AR |
3808 | return 0; |
3809 | } | |
3810 | ||
3811 | /** | |
3812 | * megasas_check_reset_fusion - For controller reset check | |
3813 | * @regs: MFI register set | |
3814 | */ | |
3815 | static int | |
3816 | megasas_check_reset_fusion(struct megasas_instance *instance, | |
3817 | struct megasas_register_set __iomem *regs) | |
3818 | { | |
3819 | return 0; | |
3820 | } | |
3821 | ||
3822 | /* This function waits for outstanding commands on fusion to complete */ | |
229fe47c | 3823 | int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, |
6d40afbc | 3824 | int reason, int *convert) |
9c915a8c | 3825 | { |
229fe47c | 3826 | int i, outstanding, retval = 0, hb_seconds_missed = 0; |
c007b8b2 | 3827 | u32 fw_state; |
9c915a8c | 3828 | |
c007b8b2 | 3829 | for (i = 0; i < resetwaittime; i++) { |
9c915a8c AR |
3830 | /* Check if firmware is in fault state */ |
3831 | fw_state = instance->instancet->read_fw_status_reg( | |
3832 | instance->reg_set) & MFI_STATE_MASK; | |
3833 | if (fw_state == MFI_STATE_FAULT) { | |
1be18254 | 3834 | dev_warn(&instance->pdev->dev, "Found FW in FAULT state," |
229fe47c AR |
3835 | " will reset adapter scsi%d.\n", |
3836 | instance->host->host_no); | |
64d0b8e4 | 3837 | megasas_complete_cmd_dpc_fusion((unsigned long)instance); |
def0eab3 S |
3838 | if (instance->requestorId && reason) { |
3839 | dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT" | |
3840 | " state while polling during" | |
3841 | " I/O timeout handling for %d\n", | |
3842 | instance->host->host_no); | |
3843 | *convert = 1; | |
3844 | } | |
3845 | ||
229fe47c AR |
3846 | retval = 1; |
3847 | goto out; | |
3848 | } | |
6d40afbc SS |
3849 | |
3850 | if (reason == MFI_IO_TIMEOUT_OCR) { | |
3851 | dev_info(&instance->pdev->dev, | |
3852 | "MFI IO is timed out, initiating OCR\n"); | |
64d0b8e4 | 3853 | megasas_complete_cmd_dpc_fusion((unsigned long)instance); |
6d40afbc SS |
3854 | retval = 1; |
3855 | goto out; | |
3856 | } | |
3857 | ||
229fe47c | 3858 | /* If SR-IOV VF mode & heartbeat timeout, don't wait */ |
6d40afbc | 3859 | if (instance->requestorId && !reason) { |
9c915a8c AR |
3860 | retval = 1; |
3861 | goto out; | |
3862 | } | |
3863 | ||
229fe47c | 3864 | /* If SR-IOV VF mode & I/O timeout, check for HB timeout */ |
def0eab3 | 3865 | if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) { |
229fe47c AR |
3866 | if (instance->hb_host_mem->HB.fwCounter != |
3867 | instance->hb_host_mem->HB.driverCounter) { | |
3868 | instance->hb_host_mem->HB.driverCounter = | |
3869 | instance->hb_host_mem->HB.fwCounter; | |
3870 | hb_seconds_missed = 0; | |
3871 | } else { | |
3872 | hb_seconds_missed++; | |
3873 | if (hb_seconds_missed == | |
3874 | (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) { | |
1be18254 | 3875 | dev_warn(&instance->pdev->dev, "SR-IOV:" |
229fe47c AR |
3876 | " Heartbeat never completed " |
3877 | " while polling during I/O " | |
3878 | " timeout handling for " | |
3879 | "scsi%d.\n", | |
3880 | instance->host->host_no); | |
3881 | *convert = 1; | |
3882 | retval = 1; | |
3883 | goto out; | |
3884 | } | |
3885 | } | |
3886 | } | |
3887 | ||
14298cf3 | 3888 | megasas_complete_cmd_dpc_fusion((unsigned long)instance); |
9c915a8c AR |
3889 | outstanding = atomic_read(&instance->fw_outstanding); |
3890 | if (!outstanding) | |
3891 | goto out; | |
3892 | ||
3893 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { | |
1be18254 | 3894 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
229fe47c AR |
3895 | "commands to complete for scsi%d\n", i, |
3896 | outstanding, instance->host->host_no); | |
9c915a8c AR |
3897 | } |
3898 | msleep(1000); | |
3899 | } | |
3900 | ||
3901 | if (atomic_read(&instance->fw_outstanding)) { | |
1be18254 | 3902 | dev_err(&instance->pdev->dev, "pending commands remain after waiting, " |
229fe47c AR |
3903 | "will reset adapter scsi%d.\n", |
3904 | instance->host->host_no); | |
18e1c7f6 | 3905 | *convert = 1; |
9c915a8c AR |
3906 | retval = 1; |
3907 | } | |
3908 | out: | |
3909 | return retval; | |
3910 | } | |
3911 | ||
3912 | void megasas_reset_reply_desc(struct megasas_instance *instance) | |
3913 | { | |
179ac142 | 3914 | int i, j, count; |
9c915a8c AR |
3915 | struct fusion_context *fusion; |
3916 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; | |
3917 | ||
3918 | fusion = instance->ctrl_context; | |
c8e858fe | 3919 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
179ac142 | 3920 | for (i = 0 ; i < count ; i++) { |
c8e858fe | 3921 | fusion->last_reply_idx[i] = 0; |
179ac142 SS |
3922 | reply_desc = fusion->reply_frames_desc[i]; |
3923 | for (j = 0 ; j < fusion->reply_q_depth; j++, reply_desc++) | |
3924 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); | |
3925 | } | |
9c915a8c AR |
3926 | } |
3927 | ||
9b828182 SS |
3928 | /* |
3929 | * megasas_refire_mgmt_cmd : Re-fire management commands | |
3930 | * @instance: Controller's soft instance | |
3931 | */ | |
3932 | void megasas_refire_mgmt_cmd(struct megasas_instance *instance) | |
3933 | { | |
3934 | int j; | |
3935 | struct megasas_cmd_fusion *cmd_fusion; | |
3936 | struct fusion_context *fusion; | |
3937 | struct megasas_cmd *cmd_mfi; | |
3938 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; | |
3939 | u16 smid; | |
6d40afbc | 3940 | bool refire_cmd = 0; |
9b828182 SS |
3941 | |
3942 | fusion = instance->ctrl_context; | |
3943 | ||
3944 | /* Re-fire management commands. | |
3945 | * Do not traverse complet MPT frame pool. Start from max_scsi_cmds. | |
3946 | */ | |
3947 | for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) { | |
3948 | cmd_fusion = fusion->cmd_list[j]; | |
3949 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; | |
3950 | smid = le16_to_cpu(cmd_mfi->context.smid); | |
3951 | ||
3952 | if (!smid) | |
3953 | continue; | |
690e9c38 S |
3954 | |
3955 | /* Do not refire shutdown command */ | |
3956 | if (le32_to_cpu(cmd_mfi->frame->dcmd.opcode) == | |
3957 | MR_DCMD_CTRL_SHUTDOWN) { | |
3958 | cmd_mfi->frame->dcmd.cmd_status = MFI_STAT_OK; | |
3959 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); | |
3960 | continue; | |
3961 | } | |
3962 | ||
9b828182 SS |
3963 | req_desc = megasas_get_request_descriptor |
3964 | (instance, smid - 1); | |
6d40afbc | 3965 | refire_cmd = req_desc && ((cmd_mfi->frame->dcmd.opcode != |
3761cb4c | 3966 | cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO)) && |
3967 | (cmd_mfi->frame->dcmd.opcode != | |
6d40afbc SS |
3968 | cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO))) |
3969 | && !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE); | |
3970 | if (refire_cmd) | |
45b8a35e | 3971 | megasas_fire_cmd_fusion(instance, req_desc); |
01d7f03b | 3972 | else |
9b828182 SS |
3973 | megasas_return_cmd(instance, cmd_mfi); |
3974 | } | |
9c915a8c AR |
3975 | } |
3976 | ||
18365b13 SS |
3977 | /* |
3978 | * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device | |
3979 | * @instance: per adapter struct | |
3980 | * @channel: the channel assigned by the OS | |
3981 | * @id: the id assigned by the OS | |
3982 | * | |
3983 | * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED | |
3984 | */ | |
3985 | ||
3986 | static int megasas_track_scsiio(struct megasas_instance *instance, | |
3987 | int id, int channel) | |
3988 | { | |
3989 | int i, found = 0; | |
3990 | struct megasas_cmd_fusion *cmd_fusion; | |
3991 | struct fusion_context *fusion; | |
3992 | fusion = instance->ctrl_context; | |
3993 | ||
3994 | for (i = 0 ; i < instance->max_scsi_cmds; i++) { | |
3995 | cmd_fusion = fusion->cmd_list[i]; | |
3996 | if (cmd_fusion->scmd && | |
3997 | (cmd_fusion->scmd->device->id == id && | |
3998 | cmd_fusion->scmd->device->channel == channel)) { | |
3999 | dev_info(&instance->pdev->dev, | |
4000 | "SCSI commands pending to target" | |
4001 | "channel %d id %d \tSMID: 0x%x\n", | |
4002 | channel, id, cmd_fusion->index); | |
4003 | scsi_print_command(cmd_fusion->scmd); | |
4004 | found = 1; | |
4005 | break; | |
4006 | } | |
4007 | } | |
4008 | ||
4009 | return found ? FAILED : SUCCESS; | |
4010 | } | |
4011 | ||
4012 | /** | |
4013 | * megasas_tm_response_code - translation of device response code | |
4014 | * @ioc: per adapter object | |
4015 | * @mpi_reply: MPI reply returned by firmware | |
4016 | * | |
4017 | * Return nothing. | |
4018 | */ | |
4019 | static void | |
4020 | megasas_tm_response_code(struct megasas_instance *instance, | |
4021 | struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply) | |
4022 | { | |
4023 | char *desc; | |
4024 | ||
4025 | switch (mpi_reply->ResponseCode) { | |
4026 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
4027 | desc = "task management request completed"; | |
4028 | break; | |
4029 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
4030 | desc = "invalid frame"; | |
4031 | break; | |
4032 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
4033 | desc = "task management request not supported"; | |
4034 | break; | |
4035 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
4036 | desc = "task management request failed"; | |
4037 | break; | |
4038 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
4039 | desc = "task management request succeeded"; | |
4040 | break; | |
4041 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
4042 | desc = "invalid lun"; | |
4043 | break; | |
4044 | case 0xA: | |
4045 | desc = "overlapped tag attempted"; | |
4046 | break; | |
4047 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
4048 | desc = "task queued, however not sent to target"; | |
4049 | break; | |
4050 | default: | |
4051 | desc = "unknown"; | |
4052 | break; | |
4053 | } | |
4054 | dev_dbg(&instance->pdev->dev, "response_code(%01x): %s\n", | |
4055 | mpi_reply->ResponseCode, desc); | |
4056 | dev_dbg(&instance->pdev->dev, | |
4057 | "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo" | |
4058 | " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n", | |
4059 | mpi_reply->TerminationCount, mpi_reply->DevHandle, | |
4060 | mpi_reply->Function, mpi_reply->TaskType, | |
4061 | mpi_reply->IOCStatus, mpi_reply->IOCLogInfo); | |
4062 | } | |
4063 | ||
4064 | /** | |
4065 | * megasas_issue_tm - main routine for sending tm requests | |
4066 | * @instance: per adapter struct | |
4067 | * @device_handle: device handle | |
4068 | * @channel: the channel assigned by the OS | |
4069 | * @id: the id assigned by the OS | |
4070 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c) | |
4071 | * @smid_task: smid assigned to the task | |
4072 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF | |
4073 | * Context: user | |
4074 | * | |
4075 | * MegaRaid use MPT interface for Task Magement request. | |
4076 | * A generic API for sending task management requests to firmware. | |
4077 | * | |
4078 | * Return SUCCESS or FAILED. | |
4079 | */ | |
4080 | static int | |
4081 | megasas_issue_tm(struct megasas_instance *instance, u16 device_handle, | |
4082 | uint channel, uint id, u16 smid_task, u8 type) | |
4083 | { | |
4084 | struct MR_TASK_MANAGE_REQUEST *mr_request; | |
4085 | struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request; | |
4086 | unsigned long timeleft; | |
4087 | struct megasas_cmd_fusion *cmd_fusion; | |
4088 | struct megasas_cmd *cmd_mfi; | |
4089 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; | |
28661c88 | 4090 | struct fusion_context *fusion = NULL; |
18365b13 SS |
4091 | struct megasas_cmd_fusion *scsi_lookup; |
4092 | int rc; | |
4093 | struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply; | |
4094 | ||
4095 | fusion = instance->ctrl_context; | |
4096 | ||
4097 | cmd_mfi = megasas_get_cmd(instance); | |
4098 | ||
4099 | if (!cmd_mfi) { | |
4100 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", | |
4101 | __func__, __LINE__); | |
4102 | return -ENOMEM; | |
4103 | } | |
4104 | ||
4105 | cmd_fusion = megasas_get_cmd_fusion(instance, | |
4106 | instance->max_scsi_cmds + cmd_mfi->index); | |
4107 | ||
4108 | /* Save the smid. To be used for returning the cmd */ | |
4109 | cmd_mfi->context.smid = cmd_fusion->index; | |
4110 | ||
4111 | req_desc = megasas_get_request_descriptor(instance, | |
4112 | (cmd_fusion->index - 1)); | |
18365b13 SS |
4113 | |
4114 | cmd_fusion->request_desc = req_desc; | |
4115 | req_desc->Words = 0; | |
4116 | ||
18365b13 SS |
4117 | mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request; |
4118 | memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST)); | |
4119 | mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) &mr_request->TmRequest; | |
4120 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
4121 | mpi_request->DevHandle = cpu_to_le16(device_handle); | |
4122 | mpi_request->TaskType = type; | |
4123 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
4124 | mpi_request->LUN[1] = 0; | |
4125 | ||
4126 | ||
4127 | req_desc = cmd_fusion->request_desc; | |
4128 | req_desc->HighPriority.SMID = cpu_to_le16(cmd_fusion->index); | |
4129 | req_desc->HighPriority.RequestFlags = | |
4130 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << | |
4131 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); | |
4132 | req_desc->HighPriority.MSIxIndex = 0; | |
4133 | req_desc->HighPriority.LMID = 0; | |
4134 | req_desc->HighPriority.Reserved1 = 0; | |
4135 | ||
4136 | if (channel < MEGASAS_MAX_PD_CHANNELS) | |
4137 | mr_request->tmReqFlags.isTMForPD = 1; | |
4138 | else | |
4139 | mr_request->tmReqFlags.isTMForLD = 1; | |
4140 | ||
4141 | init_completion(&cmd_fusion->done); | |
45b8a35e | 4142 | megasas_fire_cmd_fusion(instance, req_desc); |
18365b13 SS |
4143 | |
4144 | timeleft = wait_for_completion_timeout(&cmd_fusion->done, 50 * HZ); | |
4145 | ||
4146 | if (!timeleft) { | |
4147 | dev_err(&instance->pdev->dev, | |
4148 | "task mgmt type 0x%x timed out\n", type); | |
4149 | cmd_mfi->flags |= DRV_DCMD_SKIP_REFIRE; | |
4150 | mutex_unlock(&instance->reset_mutex); | |
4151 | rc = megasas_reset_fusion(instance->host, MFI_IO_TIMEOUT_OCR); | |
4152 | mutex_lock(&instance->reset_mutex); | |
4153 | return rc; | |
4154 | } | |
4155 | ||
4156 | mpi_reply = (struct MPI2_SCSI_TASK_MANAGE_REPLY *) &mr_request->TMReply; | |
4157 | megasas_tm_response_code(instance, mpi_reply); | |
4158 | ||
4159 | megasas_return_cmd(instance, cmd_mfi); | |
4160 | rc = SUCCESS; | |
4161 | switch (type) { | |
4162 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
28661c88 S |
4163 | scsi_lookup = fusion->cmd_list[smid_task - 1]; |
4164 | ||
18365b13 SS |
4165 | if (scsi_lookup->scmd == NULL) |
4166 | break; | |
4167 | else { | |
4168 | instance->instancet->disable_intr(instance); | |
29206da1 | 4169 | megasas_sync_irqs((unsigned long)instance); |
18365b13 SS |
4170 | instance->instancet->enable_intr(instance); |
4171 | if (scsi_lookup->scmd == NULL) | |
4172 | break; | |
4173 | } | |
4174 | rc = FAILED; | |
4175 | break; | |
4176 | ||
4177 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
4178 | if ((channel == 0xFFFFFFFF) && (id == 0xFFFFFFFF)) | |
4179 | break; | |
4180 | instance->instancet->disable_intr(instance); | |
bdb5c55f | 4181 | megasas_sync_irqs((unsigned long)instance); |
18365b13 SS |
4182 | rc = megasas_track_scsiio(instance, id, channel); |
4183 | instance->instancet->enable_intr(instance); | |
4184 | ||
4185 | break; | |
4186 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
4187 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
4188 | break; | |
4189 | default: | |
4190 | rc = FAILED; | |
4191 | break; | |
4192 | } | |
4193 | ||
4194 | return rc; | |
4195 | ||
4196 | } | |
4197 | ||
4198 | /* | |
4199 | * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI | |
4200 | * @instance: per adapter struct | |
4201 | * | |
4202 | * Return Non Zero index, if SMID found in outstanding commands | |
4203 | */ | |
4204 | static u16 megasas_fusion_smid_lookup(struct scsi_cmnd *scmd) | |
4205 | { | |
4206 | int i, ret = 0; | |
4207 | struct megasas_instance *instance; | |
4208 | struct megasas_cmd_fusion *cmd_fusion; | |
4209 | struct fusion_context *fusion; | |
4210 | ||
4211 | instance = (struct megasas_instance *)scmd->device->host->hostdata; | |
4212 | ||
4213 | fusion = instance->ctrl_context; | |
4214 | ||
4215 | for (i = 0; i < instance->max_scsi_cmds; i++) { | |
4216 | cmd_fusion = fusion->cmd_list[i]; | |
4217 | if (cmd_fusion->scmd && (cmd_fusion->scmd == scmd)) { | |
4218 | scmd_printk(KERN_NOTICE, scmd, "Abort request is for" | |
4219 | " SMID: %d\n", cmd_fusion->index); | |
4220 | ret = cmd_fusion->index; | |
4221 | break; | |
4222 | } | |
4223 | } | |
4224 | ||
4225 | return ret; | |
4226 | } | |
4227 | ||
4228 | /* | |
4229 | * megasas_get_tm_devhandle - Get devhandle for TM request | |
4230 | * @sdev- OS provided scsi device | |
4231 | * | |
4232 | * Returns- devhandle/targetID of SCSI device | |
4233 | */ | |
4234 | static u16 megasas_get_tm_devhandle(struct scsi_device *sdev) | |
4235 | { | |
4236 | u16 pd_index = 0; | |
4237 | u32 device_id; | |
4238 | struct megasas_instance *instance; | |
4239 | struct fusion_context *fusion; | |
4240 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; | |
4241 | u16 devhandle = (u16)ULONG_MAX; | |
4242 | ||
4243 | instance = (struct megasas_instance *)sdev->host->hostdata; | |
4244 | fusion = instance->ctrl_context; | |
4245 | ||
3cabd162 | 4246 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
18365b13 | 4247 | if (instance->use_seqnum_jbod_fp) { |
3cabd162 S |
4248 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) |
4249 | + sdev->id; | |
4250 | pd_sync = (void *)fusion->pd_seq_sync | |
4251 | [(instance->pd_seq_map_id - 1) & 1]; | |
4252 | devhandle = pd_sync->seq[pd_index].devHandle; | |
18365b13 SS |
4253 | } else |
4254 | sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable" | |
4255 | " without JBOD MAP support from %s %d\n", __func__, __LINE__); | |
4256 | } else { | |
4257 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) | |
4258 | + sdev->id; | |
4259 | devhandle = device_id; | |
4260 | } | |
4261 | ||
4262 | return devhandle; | |
4263 | } | |
4264 | ||
4265 | /* | |
4266 | * megasas_task_abort_fusion : SCSI task abort function for fusion adapters | |
4267 | * @scmd : pointer to scsi command object | |
4268 | * | |
4269 | * Return SUCCESS, if command aborted else FAILED | |
4270 | */ | |
4271 | ||
4272 | int megasas_task_abort_fusion(struct scsi_cmnd *scmd) | |
4273 | { | |
4274 | struct megasas_instance *instance; | |
4275 | u16 smid, devhandle; | |
4276 | struct fusion_context *fusion; | |
4277 | int ret; | |
4278 | struct MR_PRIV_DEVICE *mr_device_priv_data; | |
4279 | mr_device_priv_data = scmd->device->hostdata; | |
4280 | ||
4281 | ||
4282 | instance = (struct megasas_instance *)scmd->device->host->hostdata; | |
4283 | fusion = instance->ctrl_context; | |
4284 | ||
def0eab3 S |
4285 | scmd_printk(KERN_INFO, scmd, "task abort called for scmd(%p)\n", scmd); |
4286 | scsi_print_command(scmd); | |
4287 | ||
8a01a41d | 4288 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
18365b13 SS |
4289 | dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL," |
4290 | "SCSI host:%d\n", instance->host->host_no); | |
4291 | ret = FAILED; | |
4292 | return ret; | |
4293 | } | |
4294 | ||
4295 | if (!mr_device_priv_data) { | |
4296 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " | |
4297 | "scmd(%p)\n", scmd); | |
4298 | scmd->result = DID_NO_CONNECT << 16; | |
4299 | ret = SUCCESS; | |
4300 | goto out; | |
4301 | } | |
4302 | ||
4303 | ||
4304 | if (!mr_device_priv_data->is_tm_capable) { | |
4305 | ret = FAILED; | |
4306 | goto out; | |
4307 | } | |
4308 | ||
4309 | mutex_lock(&instance->reset_mutex); | |
4310 | ||
4311 | smid = megasas_fusion_smid_lookup(scmd); | |
4312 | ||
4313 | if (!smid) { | |
4314 | ret = SUCCESS; | |
4315 | scmd_printk(KERN_NOTICE, scmd, "Command for which abort is" | |
4316 | " issued is not found in oustanding commands\n"); | |
4317 | mutex_unlock(&instance->reset_mutex); | |
4318 | goto out; | |
4319 | } | |
4320 | ||
4321 | devhandle = megasas_get_tm_devhandle(scmd->device); | |
4322 | ||
4323 | if (devhandle == (u16)ULONG_MAX) { | |
4324 | ret = SUCCESS; | |
4325 | sdev_printk(KERN_INFO, scmd->device, | |
4326 | "task abort issued for invalid devhandle\n"); | |
4327 | mutex_unlock(&instance->reset_mutex); | |
4328 | goto out; | |
4329 | } | |
4330 | sdev_printk(KERN_INFO, scmd->device, | |
4331 | "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n", | |
4332 | scmd, devhandle); | |
4333 | ||
4334 | mr_device_priv_data->tm_busy = 1; | |
4335 | ret = megasas_issue_tm(instance, devhandle, | |
4336 | scmd->device->channel, scmd->device->id, smid, | |
4337 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK); | |
4338 | mr_device_priv_data->tm_busy = 0; | |
4339 | ||
4340 | mutex_unlock(&instance->reset_mutex); | |
4341 | out: | |
4342 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
4343 | ((ret == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
4344 | ||
4345 | return ret; | |
4346 | } | |
4347 | ||
4348 | /* | |
4349 | * megasas_reset_target_fusion : target reset function for fusion adapters | |
4350 | * scmd: SCSI command pointer | |
4351 | * | |
4352 | * Returns SUCCESS if all commands associated with target aborted else FAILED | |
4353 | */ | |
4354 | ||
4355 | int megasas_reset_target_fusion(struct scsi_cmnd *scmd) | |
4356 | { | |
4357 | ||
4358 | struct megasas_instance *instance; | |
4359 | int ret = FAILED; | |
4360 | u16 devhandle; | |
4361 | struct fusion_context *fusion; | |
4362 | struct MR_PRIV_DEVICE *mr_device_priv_data; | |
4363 | mr_device_priv_data = scmd->device->hostdata; | |
4364 | ||
4365 | instance = (struct megasas_instance *)scmd->device->host->hostdata; | |
4366 | fusion = instance->ctrl_context; | |
4367 | ||
def0eab3 S |
4368 | sdev_printk(KERN_INFO, scmd->device, |
4369 | "target reset called for scmd(%p)\n", scmd); | |
4370 | ||
8a01a41d | 4371 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
18365b13 SS |
4372 | dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL," |
4373 | "SCSI host:%d\n", instance->host->host_no); | |
4374 | ret = FAILED; | |
4375 | return ret; | |
4376 | } | |
4377 | ||
4378 | if (!mr_device_priv_data) { | |
4379 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " | |
4380 | "scmd(%p)\n", scmd); | |
4381 | scmd->result = DID_NO_CONNECT << 16; | |
4382 | ret = SUCCESS; | |
4383 | goto out; | |
4384 | } | |
4385 | ||
4386 | ||
4387 | if (!mr_device_priv_data->is_tm_capable) { | |
4388 | ret = FAILED; | |
4389 | goto out; | |
4390 | } | |
4391 | ||
4392 | mutex_lock(&instance->reset_mutex); | |
4393 | devhandle = megasas_get_tm_devhandle(scmd->device); | |
4394 | ||
4395 | if (devhandle == (u16)ULONG_MAX) { | |
4396 | ret = SUCCESS; | |
4397 | sdev_printk(KERN_INFO, scmd->device, | |
4398 | "target reset issued for invalid devhandle\n"); | |
4399 | mutex_unlock(&instance->reset_mutex); | |
4400 | goto out; | |
4401 | } | |
4402 | ||
4403 | sdev_printk(KERN_INFO, scmd->device, | |
4404 | "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n", | |
4405 | scmd, devhandle); | |
4406 | mr_device_priv_data->tm_busy = 1; | |
4407 | ret = megasas_issue_tm(instance, devhandle, | |
4408 | scmd->device->channel, scmd->device->id, 0, | |
4409 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET); | |
4410 | mr_device_priv_data->tm_busy = 0; | |
4411 | mutex_unlock(&instance->reset_mutex); | |
4412 | out: | |
4413 | scmd_printk(KERN_NOTICE, scmd, "megasas: target reset %s!!\n", | |
4414 | (ret == SUCCESS) ? "SUCCESS" : "FAILED"); | |
4415 | ||
4416 | return ret; | |
4417 | } | |
4418 | ||
8f67c8c5 SS |
4419 | /*SRIOV get other instance in cluster if any*/ |
4420 | struct megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance) | |
4421 | { | |
4422 | int i; | |
4423 | ||
4424 | for (i = 0; i < MAX_MGMT_ADAPTERS; i++) { | |
4425 | if (megasas_mgmt_info.instance[i] && | |
4426 | (megasas_mgmt_info.instance[i] != instance) && | |
4427 | megasas_mgmt_info.instance[i]->requestorId && | |
4428 | megasas_mgmt_info.instance[i]->peerIsPresent && | |
4429 | (memcmp((megasas_mgmt_info.instance[i]->clusterId), | |
4430 | instance->clusterId, MEGASAS_CLUSTER_ID_SIZE) == 0)) | |
4431 | return megasas_mgmt_info.instance[i]; | |
4432 | } | |
4433 | return NULL; | |
4434 | } | |
4435 | ||
229fe47c AR |
4436 | /* Check for a second path that is currently UP */ |
4437 | int megasas_check_mpio_paths(struct megasas_instance *instance, | |
4438 | struct scsi_cmnd *scmd) | |
4439 | { | |
8f67c8c5 | 4440 | struct megasas_instance *peer_instance = NULL; |
f55cf47d | 4441 | int retval = (DID_REQUEUE << 16); |
8f67c8c5 SS |
4442 | |
4443 | if (instance->peerIsPresent) { | |
4444 | peer_instance = megasas_get_peer_instance(instance); | |
4445 | if ((peer_instance) && | |
4446 | (atomic_read(&peer_instance->adprecovery) == | |
4447 | MEGASAS_HBA_OPERATIONAL)) | |
4448 | retval = (DID_NO_CONNECT << 16); | |
229fe47c | 4449 | } |
229fe47c AR |
4450 | return retval; |
4451 | } | |
4452 | ||
9c915a8c | 4453 | /* Core fusion reset function */ |
18365b13 | 4454 | int megasas_reset_fusion(struct Scsi_Host *shost, int reason) |
9c915a8c | 4455 | { |
fdd84e25 | 4456 | int retval = SUCCESS, i, j, convert = 0; |
9c915a8c | 4457 | struct megasas_instance *instance; |
8bf7c65d | 4458 | struct megasas_cmd_fusion *cmd_fusion, *r1_cmd; |
9c915a8c | 4459 | struct fusion_context *fusion; |
79b82c2c | 4460 | u32 abs_state, status_reg, reset_adapter; |
fc62b3fc | 4461 | u32 io_timeout_in_crash_mode = 0; |
4026e9aa | 4462 | struct scsi_cmnd *scmd_local = NULL; |
18365b13 | 4463 | struct scsi_device *sdev; |
9c915a8c AR |
4464 | |
4465 | instance = (struct megasas_instance *)shost->hostdata; | |
4466 | fusion = instance->ctrl_context; | |
4467 | ||
229fe47c AR |
4468 | mutex_lock(&instance->reset_mutex); |
4469 | ||
8a01a41d | 4470 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
1be18254 | 4471 | dev_warn(&instance->pdev->dev, "Hardware critical error, " |
229fe47c AR |
4472 | "returning FAILED for scsi%d.\n", |
4473 | instance->host->host_no); | |
a2fbcbc3 | 4474 | mutex_unlock(&instance->reset_mutex); |
d4a759a9 | 4475 | return FAILED; |
9c915a8c | 4476 | } |
fc62b3fc SS |
4477 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); |
4478 | abs_state = status_reg & MFI_STATE_MASK; | |
4479 | ||
4480 | /* IO timeout detected, forcibly put FW in FAULT state */ | |
4481 | if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf && | |
18365b13 SS |
4482 | instance->crash_dump_app_support && reason) { |
4483 | dev_info(&instance->pdev->dev, "IO/DCMD timeout is detected, " | |
fc62b3fc | 4484 | "forcibly FAULT Firmware\n"); |
8a01a41d | 4485 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
fc62b3fc SS |
4486 | status_reg = readl(&instance->reg_set->doorbell); |
4487 | writel(status_reg | MFI_STATE_FORCE_OCR, | |
4488 | &instance->reg_set->doorbell); | |
4489 | readl(&instance->reg_set->doorbell); | |
4490 | mutex_unlock(&instance->reset_mutex); | |
4491 | do { | |
4492 | ssleep(3); | |
4493 | io_timeout_in_crash_mode++; | |
4494 | dev_dbg(&instance->pdev->dev, "waiting for [%d] " | |
4495 | "seconds for crash dump collection and OCR " | |
4496 | "to be done\n", (io_timeout_in_crash_mode * 3)); | |
8a01a41d | 4497 | } while ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
fc62b3fc SS |
4498 | (io_timeout_in_crash_mode < 80)); |
4499 | ||
8a01a41d | 4500 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
fc62b3fc SS |
4501 | dev_info(&instance->pdev->dev, "OCR done for IO " |
4502 | "timeout case\n"); | |
4503 | retval = SUCCESS; | |
4504 | } else { | |
4505 | dev_info(&instance->pdev->dev, "Controller is not " | |
4506 | "operational after 240 seconds wait for IO " | |
4507 | "timeout case in FW crash dump mode\n do " | |
4508 | "OCR/kill adapter\n"); | |
4509 | retval = megasas_reset_fusion(shost, 0); | |
4510 | } | |
4511 | return retval; | |
4512 | } | |
9c915a8c | 4513 | |
229fe47c AR |
4514 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
4515 | del_timer_sync(&instance->sriov_heartbeat_timer); | |
7e70e733 | 4516 | set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
129e6210 | 4517 | set_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags); |
8a01a41d | 4518 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING); |
d46a3ad6 | 4519 | instance->instancet->disable_intr(instance); |
29206da1 | 4520 | megasas_sync_irqs((unsigned long)instance); |
7e70e733 | 4521 | |
9c915a8c | 4522 | /* First try waiting for commands to complete */ |
18365b13 | 4523 | if (megasas_wait_for_outstanding_fusion(instance, reason, |
229fe47c | 4524 | &convert)) { |
8a01a41d | 4525 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
1be18254 | 4526 | dev_warn(&instance->pdev->dev, "resetting fusion " |
229fe47c AR |
4527 | "adapter scsi%d.\n", instance->host->host_no); |
4528 | if (convert) | |
18365b13 | 4529 | reason = 0; |
229fe47c | 4530 | |
def0eab3 S |
4531 | if (megasas_dbg_lvl & OCR_LOGS) |
4532 | dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n"); | |
4533 | ||
9c915a8c | 4534 | /* Now return commands back to the OS */ |
4026e9aa | 4535 | for (i = 0 ; i < instance->max_scsi_cmds; i++) { |
9c915a8c | 4536 | cmd_fusion = fusion->cmd_list[i]; |
69c337c0 | 4537 | /*check for extra commands issued by driver*/ |
f369a315 | 4538 | if (instance->adapter_type == VENTURA_SERIES) { |
8bf7c65d S |
4539 | r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds]; |
4540 | megasas_return_cmd_fusion(instance, r1_cmd); | |
69c337c0 | 4541 | } |
4026e9aa | 4542 | scmd_local = cmd_fusion->scmd; |
9c915a8c | 4543 | if (cmd_fusion->scmd) { |
def0eab3 S |
4544 | if (megasas_dbg_lvl & OCR_LOGS) { |
4545 | sdev_printk(KERN_INFO, | |
4546 | cmd_fusion->scmd->device, "SMID: 0x%x\n", | |
4547 | cmd_fusion->index); | |
4548 | scsi_print_command(cmd_fusion->scmd); | |
4549 | } | |
4550 | ||
4026e9aa | 4551 | scmd_local->result = |
229fe47c | 4552 | megasas_check_mpio_paths(instance, |
4026e9aa | 4553 | scmd_local); |
b71b49c2 SC |
4554 | if (instance->ldio_threshold && |
4555 | megasas_cmd_type(scmd_local) == READ_WRITE_LDIO) | |
308ec459 | 4556 | atomic_dec(&instance->ldio_outstanding); |
9c915a8c | 4557 | megasas_return_cmd_fusion(instance, cmd_fusion); |
4026e9aa SS |
4558 | scsi_dma_unmap(scmd_local); |
4559 | scmd_local->scsi_done(scmd_local); | |
9c915a8c AR |
4560 | } |
4561 | } | |
4562 | ||
69c337c0 SC |
4563 | atomic_set(&instance->fw_outstanding, 0); |
4564 | ||
7e70e733 AR |
4565 | status_reg = instance->instancet->read_fw_status_reg( |
4566 | instance->reg_set); | |
4567 | abs_state = status_reg & MFI_STATE_MASK; | |
4568 | reset_adapter = status_reg & MFI_RESET_ADAPTER; | |
4569 | if (instance->disableOnlineCtrlReset || | |
4570 | (abs_state == MFI_STATE_FAULT && !reset_adapter)) { | |
9c915a8c | 4571 | /* Reset not supported, kill adapter */ |
1be18254 | 4572 | dev_warn(&instance->pdev->dev, "Reset not supported" |
229fe47c AR |
4573 | ", killing adapter scsi%d.\n", |
4574 | instance->host->host_no); | |
9c915a8c | 4575 | megaraid_sas_kill_hba(instance); |
229fe47c | 4576 | instance->skip_heartbeat_timer_del = 1; |
9c915a8c AR |
4577 | retval = FAILED; |
4578 | goto out; | |
4579 | } | |
4580 | ||
229fe47c | 4581 | /* Let SR-IOV VF & PF sync up if there was a HB failure */ |
18365b13 | 4582 | if (instance->requestorId && !reason) { |
229fe47c | 4583 | msleep(MEGASAS_OCR_SETTLE_TIME_VF); |
3885c26b | 4584 | goto transition_to_ready; |
229fe47c AR |
4585 | } |
4586 | ||
9c915a8c AR |
4587 | /* Now try to reset the chip */ |
4588 | for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) { | |
9c915a8c | 4589 | |
79b82c2c | 4590 | if (instance->instancet->adp_reset |
4591 | (instance, instance->reg_set)) | |
9c915a8c | 4592 | continue; |
3885c26b | 4593 | transition_to_ready: |
9c915a8c | 4594 | /* Wait for FW to become ready */ |
058a8fac | 4595 | if (megasas_transition_to_ready(instance, 1)) { |
3885c26b SS |
4596 | dev_warn(&instance->pdev->dev, |
4597 | "Failed to transition controller to ready for " | |
4598 | "scsi%d.\n", instance->host->host_no); | |
4599 | if (instance->requestorId && !reason) | |
4600 | goto fail_kill_adapter; | |
4601 | else | |
4602 | continue; | |
9c915a8c | 4603 | } |
9c915a8c | 4604 | megasas_reset_reply_desc(instance); |
308ec459 SS |
4605 | megasas_fusion_update_can_queue(instance, OCR_CONTEXT); |
4606 | ||
9c915a8c | 4607 | if (megasas_ioc_init_fusion(instance)) { |
3885c26b SS |
4608 | if (instance->requestorId && !reason) |
4609 | goto fail_kill_adapter; | |
4610 | else | |
4611 | continue; | |
9c915a8c AR |
4612 | } |
4613 | ||
9b828182 | 4614 | megasas_refire_mgmt_cmd(instance); |
9c915a8c | 4615 | |
d009b576 SS |
4616 | if (megasas_get_ctrl_info(instance)) { |
4617 | dev_info(&instance->pdev->dev, | |
4618 | "Failed from %s %d\n", | |
4619 | __func__, __LINE__); | |
d009b576 SS |
4620 | megaraid_sas_kill_hba(instance); |
4621 | retval = FAILED; | |
a6821ca3 | 4622 | goto out; |
d009b576 | 4623 | } |
9c915a8c | 4624 | /* Reset load balance info */ |
5fc499b6 S |
4625 | if (fusion->load_balance_info) |
4626 | memset(fusion->load_balance_info, 0, | |
4627 | (sizeof(struct LD_LOAD_BALANCE_INFO) * | |
4628 | MAX_LOGICAL_DRIVES_EXT)); | |
9c915a8c AR |
4629 | |
4630 | if (!megasas_get_map_info(instance)) | |
4631 | megasas_sync_map_info(instance); | |
4632 | ||
3761cb4c | 4633 | megasas_setup_jbod_map(instance); |
4634 | ||
18365b13 | 4635 | shost_for_each_device(sdev, shost) |
15dd0381 | 4636 | megasas_set_dynamic_target_properties(sdev); |
18365b13 | 4637 | |
fdd84e25 | 4638 | /* reset stream detection array */ |
f369a315 | 4639 | if (instance->adapter_type == VENTURA_SERIES) { |
fdd84e25 SC |
4640 | for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) { |
4641 | memset(fusion->stream_detect_by_ld[j], | |
4642 | 0, sizeof(struct LD_STREAM_DETECT)); | |
4643 | fusion->stream_detect_by_ld[j]->mru_bit_map | |
4644 | = MR_STREAM_BITMAP; | |
4645 | } | |
4646 | } | |
4647 | ||
ac340c5f SS |
4648 | clear_bit(MEGASAS_FUSION_IN_RESET, |
4649 | &instance->reset_flags); | |
4650 | instance->instancet->enable_intr(instance); | |
8a01a41d | 4651 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
ac340c5f | 4652 | |
2d2c2331 S |
4653 | dev_info(&instance->pdev->dev, "Interrupts are enabled and" |
4654 | " controller is OPERATIONAL for scsi:%d\n", | |
4655 | instance->host->host_no); | |
4656 | ||
229fe47c AR |
4657 | /* Restart SR-IOV heartbeat */ |
4658 | if (instance->requestorId) { | |
4659 | if (!megasas_sriov_start_heartbeat(instance, 0)) | |
c251a7be | 4660 | megasas_start_timer(instance); |
229fe47c AR |
4661 | else |
4662 | instance->skip_heartbeat_timer_del = 1; | |
4663 | } | |
4664 | ||
ac340c5f SS |
4665 | if (instance->crash_dump_drv_support && |
4666 | instance->crash_dump_app_support) | |
4667 | megasas_set_crash_dump_params(instance, | |
4668 | MR_CRASH_BUF_TURN_ON); | |
4669 | else | |
4670 | megasas_set_crash_dump_params(instance, | |
4671 | MR_CRASH_BUF_TURN_OFF); | |
4672 | ||
9c915a8c | 4673 | retval = SUCCESS; |
2d2c2331 S |
4674 | |
4675 | /* Adapter reset completed successfully */ | |
4676 | dev_warn(&instance->pdev->dev, | |
4677 | "Reset successful for scsi%d.\n", | |
4678 | instance->host->host_no); | |
4679 | ||
9c915a8c AR |
4680 | goto out; |
4681 | } | |
3885c26b | 4682 | fail_kill_adapter: |
9c915a8c | 4683 | /* Reset failed, kill the adapter */ |
1be18254 | 4684 | dev_warn(&instance->pdev->dev, "Reset failed, killing " |
229fe47c | 4685 | "adapter scsi%d.\n", instance->host->host_no); |
9c915a8c | 4686 | megaraid_sas_kill_hba(instance); |
229fe47c | 4687 | instance->skip_heartbeat_timer_del = 1; |
9c915a8c AR |
4688 | retval = FAILED; |
4689 | } else { | |
229fe47c AR |
4690 | /* For VF: Restart HB timer if we didn't OCR */ |
4691 | if (instance->requestorId) { | |
c251a7be | 4692 | megasas_start_timer(instance); |
229fe47c | 4693 | } |
3f0e58bc | 4694 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
d46a3ad6 | 4695 | instance->instancet->enable_intr(instance); |
8a01a41d | 4696 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
9c915a8c AR |
4697 | } |
4698 | out: | |
129e6210 | 4699 | clear_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags); |
9c915a8c AR |
4700 | mutex_unlock(&instance->reset_mutex); |
4701 | return retval; | |
4702 | } | |
4703 | ||
fc62b3fc SS |
4704 | /* Fusion Crash dump collection work queue */ |
4705 | void megasas_fusion_crash_dump_wq(struct work_struct *work) | |
4706 | { | |
4707 | struct megasas_instance *instance = | |
4708 | container_of(work, struct megasas_instance, crash_init); | |
4709 | u32 status_reg; | |
4710 | u8 partial_copy = 0; | |
4711 | ||
4712 | ||
4713 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); | |
4714 | ||
4715 | /* | |
4716 | * Allocate host crash buffers to copy data from 1 MB DMA crash buffer | |
4717 | * to host crash buffers | |
4718 | */ | |
4719 | if (instance->drv_buf_index == 0) { | |
4720 | /* Buffer is already allocated for old Crash dump. | |
4721 | * Do OCR and do not wait for crash dump collection | |
4722 | */ | |
4723 | if (instance->drv_buf_alloc) { | |
4724 | dev_info(&instance->pdev->dev, "earlier crash dump is " | |
4725 | "not yet copied by application, ignoring this " | |
4726 | "crash dump and initiating OCR\n"); | |
4727 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; | |
4728 | writel(status_reg, | |
4729 | &instance->reg_set->outbound_scratch_pad); | |
4730 | readl(&instance->reg_set->outbound_scratch_pad); | |
4731 | return; | |
4732 | } | |
4733 | megasas_alloc_host_crash_buffer(instance); | |
4734 | dev_info(&instance->pdev->dev, "Number of host crash buffers " | |
4735 | "allocated: %d\n", instance->drv_buf_alloc); | |
4736 | } | |
4737 | ||
4738 | /* | |
4739 | * Driver has allocated max buffers, which can be allocated | |
4740 | * and FW has more crash dump data, then driver will | |
4741 | * ignore the data. | |
4742 | */ | |
4743 | if (instance->drv_buf_index >= (instance->drv_buf_alloc)) { | |
4744 | dev_info(&instance->pdev->dev, "Driver is done copying " | |
4745 | "the buffer: %d\n", instance->drv_buf_alloc); | |
4746 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; | |
4747 | partial_copy = 1; | |
4748 | } else { | |
4749 | memcpy(instance->crash_buf[instance->drv_buf_index], | |
4750 | instance->crash_dump_buf, CRASH_DMA_BUF_SIZE); | |
4751 | instance->drv_buf_index++; | |
4752 | status_reg &= ~MFI_STATE_DMADONE; | |
4753 | } | |
4754 | ||
4755 | if (status_reg & MFI_STATE_CRASH_DUMP_DONE) { | |
4756 | dev_info(&instance->pdev->dev, "Crash Dump is available,number " | |
4757 | "of copied buffers: %d\n", instance->drv_buf_index); | |
4758 | instance->fw_crash_buffer_size = instance->drv_buf_index; | |
4759 | instance->fw_crash_state = AVAILABLE; | |
4760 | instance->drv_buf_index = 0; | |
4761 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); | |
4762 | readl(&instance->reg_set->outbound_scratch_pad); | |
4763 | if (!partial_copy) | |
4764 | megasas_reset_fusion(instance->host, 0); | |
4765 | } else { | |
4766 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); | |
4767 | readl(&instance->reg_set->outbound_scratch_pad); | |
4768 | } | |
4769 | } | |
4770 | ||
4771 | ||
9c915a8c AR |
4772 | /* Fusion OCR work queue */ |
4773 | void megasas_fusion_ocr_wq(struct work_struct *work) | |
4774 | { | |
4775 | struct megasas_instance *instance = | |
4776 | container_of(work, struct megasas_instance, work_init); | |
4777 | ||
229fe47c | 4778 | megasas_reset_fusion(instance->host, 0); |
9c915a8c AR |
4779 | } |
4780 | ||
5fc499b6 S |
4781 | /* Allocate fusion context */ |
4782 | int | |
4783 | megasas_alloc_fusion_context(struct megasas_instance *instance) | |
4784 | { | |
4785 | struct fusion_context *fusion; | |
4786 | ||
2dd689c8 S |
4787 | instance->ctrl_context = kzalloc(sizeof(struct fusion_context), |
4788 | GFP_KERNEL); | |
5fc499b6 | 4789 | if (!instance->ctrl_context) { |
2dd689c8 S |
4790 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
4791 | __func__, __LINE__); | |
4792 | return -ENOMEM; | |
5fc499b6 S |
4793 | } |
4794 | ||
4795 | fusion = instance->ctrl_context; | |
4796 | ||
2dd689c8 S |
4797 | fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT * |
4798 | sizeof(LD_SPAN_INFO)); | |
4799 | fusion->log_to_span = | |
4800 | (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO, | |
4801 | fusion->log_to_span_pages); | |
4802 | if (!fusion->log_to_span) { | |
4803 | fusion->log_to_span = vzalloc(MAX_LOGICAL_DRIVES_EXT * | |
4804 | sizeof(LD_SPAN_INFO)); | |
4805 | if (!fusion->log_to_span) { | |
4806 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", | |
4807 | __func__, __LINE__); | |
4808 | return -ENOMEM; | |
4809 | } | |
4810 | } | |
4811 | ||
5fc499b6 S |
4812 | fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT * |
4813 | sizeof(struct LD_LOAD_BALANCE_INFO)); | |
4814 | fusion->load_balance_info = | |
4815 | (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, | |
4816 | fusion->load_balance_info_pages); | |
4817 | if (!fusion->load_balance_info) { | |
4818 | fusion->load_balance_info = vzalloc(MAX_LOGICAL_DRIVES_EXT * | |
4819 | sizeof(struct LD_LOAD_BALANCE_INFO)); | |
4820 | if (!fusion->load_balance_info) | |
4821 | dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, " | |
4822 | "continuing without Load Balance support\n"); | |
4823 | } | |
4824 | ||
4825 | return 0; | |
4826 | } | |
4827 | ||
4828 | void | |
4829 | megasas_free_fusion_context(struct megasas_instance *instance) | |
4830 | { | |
4831 | struct fusion_context *fusion = instance->ctrl_context; | |
4832 | ||
4833 | if (fusion) { | |
4834 | if (fusion->load_balance_info) { | |
4835 | if (is_vmalloc_addr(fusion->load_balance_info)) | |
4836 | vfree(fusion->load_balance_info); | |
4837 | else | |
4838 | free_pages((ulong)fusion->load_balance_info, | |
4839 | fusion->load_balance_info_pages); | |
4840 | } | |
4841 | ||
2dd689c8 S |
4842 | if (fusion->log_to_span) { |
4843 | if (is_vmalloc_addr(fusion->log_to_span)) | |
4844 | vfree(fusion->log_to_span); | |
4845 | else | |
4846 | free_pages((ulong)fusion->log_to_span, | |
4847 | fusion->log_to_span_pages); | |
4848 | } | |
4849 | ||
4850 | kfree(fusion); | |
5fc499b6 S |
4851 | } |
4852 | } | |
4853 | ||
9c915a8c | 4854 | struct megasas_instance_template megasas_instance_template_fusion = { |
9c915a8c AR |
4855 | .enable_intr = megasas_enable_intr_fusion, |
4856 | .disable_intr = megasas_disable_intr_fusion, | |
4857 | .clear_intr = megasas_clear_intr_fusion, | |
4858 | .read_fw_status_reg = megasas_read_fw_status_reg_fusion, | |
4859 | .adp_reset = megasas_adp_reset_fusion, | |
4860 | .check_reset = megasas_check_reset_fusion, | |
4861 | .service_isr = megasas_isr_fusion, | |
4862 | .tasklet = megasas_complete_cmd_dpc_fusion, | |
4863 | .init_adapter = megasas_init_adapter_fusion, | |
4864 | .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion, | |
4865 | .issue_dcmd = megasas_issue_dcmd_fusion, | |
4866 | }; |