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