Commit | Line | Data |
---|---|---|
c4a3e0a5 BS |
1 | /* |
2 | * | |
3 | * Linux MegaRAID driver for SAS based RAID controllers | |
4 | * | |
f28cd7cf | 5 | * Copyright (c) 2003-2005 LSI Corporation. |
c4a3e0a5 BS |
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 | |
10 | * 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * FILE : megaraid_sas.c | |
6610a6b3 | 13 | * Version : v00.00.04.01-rc1 |
c4a3e0a5 BS |
14 | * |
15 | * Authors: | |
cc5968c8 SP |
16 | * (email-id : megaraidlinux@lsi.com) |
17 | * Sreenivas Bagalkote | |
18 | * Sumant Patro | |
19 | * Bo Yang | |
c4a3e0a5 BS |
20 | * |
21 | * List of supported controllers | |
22 | * | |
23 | * OEM Product Name VID DID SSVID SSID | |
24 | * --- ------------ --- --- ---- ---- | |
25 | */ | |
26 | ||
27 | #include <linux/kernel.h> | |
28 | #include <linux/types.h> | |
29 | #include <linux/pci.h> | |
30 | #include <linux/list.h> | |
c4a3e0a5 BS |
31 | #include <linux/moduleparam.h> |
32 | #include <linux/module.h> | |
33 | #include <linux/spinlock.h> | |
34 | #include <linux/interrupt.h> | |
35 | #include <linux/delay.h> | |
f2b9857e | 36 | #include <linux/smp_lock.h> |
c4a3e0a5 BS |
37 | #include <linux/uio.h> |
38 | #include <asm/uaccess.h> | |
43399236 | 39 | #include <linux/fs.h> |
c4a3e0a5 | 40 | #include <linux/compat.h> |
cf62a0a5 | 41 | #include <linux/blkdev.h> |
0b950672 | 42 | #include <linux/mutex.h> |
c3518837 | 43 | #include <linux/poll.h> |
c4a3e0a5 BS |
44 | |
45 | #include <scsi/scsi.h> | |
46 | #include <scsi/scsi_cmnd.h> | |
47 | #include <scsi/scsi_device.h> | |
48 | #include <scsi/scsi_host.h> | |
49 | #include "megaraid_sas.h" | |
50 | ||
ad84db2e | 51 | /* |
52 | * poll_mode_io:1- schedule complete completion from q cmd | |
53 | */ | |
54 | static unsigned int poll_mode_io; | |
55 | module_param_named(poll_mode_io, poll_mode_io, int, 0); | |
56 | MODULE_PARM_DESC(poll_mode_io, | |
57 | "Complete cmds from IO path, (default=0)"); | |
58 | ||
c4a3e0a5 BS |
59 | MODULE_LICENSE("GPL"); |
60 | MODULE_VERSION(MEGASAS_VERSION); | |
3d6d174a | 61 | MODULE_AUTHOR("megaraidlinux@lsi.com"); |
f28cd7cf | 62 | MODULE_DESCRIPTION("LSI MegaRAID SAS Driver"); |
c4a3e0a5 BS |
63 | |
64 | /* | |
65 | * PCI ID table for all supported controllers | |
66 | */ | |
67 | static struct pci_device_id megasas_pci_table[] = { | |
68 | ||
f3d7271c HK |
69 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
70 | /* xscale IOP */ | |
71 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, | |
72 | /* ppc IOP */ | |
af7a5647 | 73 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
74 | /* ppc IOP */ | |
6610a6b3 YB |
75 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
76 | /* gen2*/ | |
77 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, | |
78 | /* gen2*/ | |
87911122 YB |
79 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
80 | /* skinny*/ | |
81 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, | |
82 | /* skinny*/ | |
f3d7271c HK |
83 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
84 | /* xscale IOP, vega */ | |
85 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, | |
86 | /* xscale IOP */ | |
87 | {} | |
c4a3e0a5 BS |
88 | }; |
89 | ||
90 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); | |
91 | ||
92 | static int megasas_mgmt_majorno; | |
93 | static struct megasas_mgmt_info megasas_mgmt_info; | |
94 | static struct fasync_struct *megasas_async_queue; | |
0b950672 | 95 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
c4a3e0a5 | 96 | |
c3518837 YB |
97 | static int megasas_poll_wait_aen; |
98 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); | |
72c4fd36 | 99 | static u32 support_poll_for_event; |
658dcedb SP |
100 | static u32 megasas_dbg_lvl; |
101 | ||
c3518837 YB |
102 | /* define lock for aen poll */ |
103 | spinlock_t poll_aen_lock; | |
104 | ||
7343eb65 | 105 | static void |
106 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, | |
107 | u8 alt_status); | |
108 | ||
c4a3e0a5 BS |
109 | /** |
110 | * megasas_get_cmd - Get a command from the free pool | |
111 | * @instance: Adapter soft state | |
112 | * | |
113 | * Returns a free command from the pool | |
114 | */ | |
858119e1 | 115 | static struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
c4a3e0a5 BS |
116 | *instance) |
117 | { | |
118 | unsigned long flags; | |
119 | struct megasas_cmd *cmd = NULL; | |
120 | ||
121 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); | |
122 | ||
123 | if (!list_empty(&instance->cmd_pool)) { | |
124 | cmd = list_entry((&instance->cmd_pool)->next, | |
125 | struct megasas_cmd, list); | |
126 | list_del_init(&cmd->list); | |
127 | } else { | |
128 | printk(KERN_ERR "megasas: Command pool empty!\n"); | |
129 | } | |
130 | ||
131 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); | |
132 | return cmd; | |
133 | } | |
134 | ||
135 | /** | |
136 | * megasas_return_cmd - Return a cmd to free command pool | |
137 | * @instance: Adapter soft state | |
138 | * @cmd: Command packet to be returned to free command pool | |
139 | */ | |
140 | static inline void | |
141 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) | |
142 | { | |
143 | unsigned long flags; | |
144 | ||
145 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); | |
146 | ||
147 | cmd->scmd = NULL; | |
148 | list_add_tail(&cmd->list, &instance->cmd_pool); | |
149 | ||
150 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); | |
151 | } | |
152 | ||
1341c939 SP |
153 | |
154 | /** | |
155 | * The following functions are defined for xscale | |
156 | * (deviceid : 1064R, PERC5) controllers | |
157 | */ | |
158 | ||
c4a3e0a5 | 159 | /** |
1341c939 | 160 | * megasas_enable_intr_xscale - Enables interrupts |
c4a3e0a5 BS |
161 | * @regs: MFI register set |
162 | */ | |
163 | static inline void | |
1341c939 | 164 | megasas_enable_intr_xscale(struct megasas_register_set __iomem * regs) |
c4a3e0a5 BS |
165 | { |
166 | writel(1, &(regs)->outbound_intr_mask); | |
167 | ||
168 | /* Dummy readl to force pci flush */ | |
169 | readl(®s->outbound_intr_mask); | |
170 | } | |
171 | ||
b274cab7 SP |
172 | /** |
173 | * megasas_disable_intr_xscale -Disables interrupt | |
174 | * @regs: MFI register set | |
175 | */ | |
176 | static inline void | |
177 | megasas_disable_intr_xscale(struct megasas_register_set __iomem * regs) | |
178 | { | |
179 | u32 mask = 0x1f; | |
180 | writel(mask, ®s->outbound_intr_mask); | |
181 | /* Dummy readl to force pci flush */ | |
182 | readl(®s->outbound_intr_mask); | |
183 | } | |
184 | ||
1341c939 SP |
185 | /** |
186 | * megasas_read_fw_status_reg_xscale - returns the current FW status value | |
187 | * @regs: MFI register set | |
188 | */ | |
189 | static u32 | |
190 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) | |
191 | { | |
192 | return readl(&(regs)->outbound_msg_0); | |
193 | } | |
194 | /** | |
195 | * megasas_clear_interrupt_xscale - Check & clear interrupt | |
196 | * @regs: MFI register set | |
197 | */ | |
198 | static int | |
199 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) | |
200 | { | |
201 | u32 status; | |
202 | /* | |
203 | * Check if it is our interrupt | |
204 | */ | |
205 | status = readl(®s->outbound_intr_status); | |
206 | ||
207 | if (!(status & MFI_OB_INTR_STATUS_MASK)) { | |
208 | return 1; | |
209 | } | |
210 | ||
211 | /* | |
212 | * Clear the interrupt by writing back the same value | |
213 | */ | |
214 | writel(status, ®s->outbound_intr_status); | |
215 | ||
06f579de YB |
216 | /* Dummy readl to force pci flush */ |
217 | readl(®s->outbound_intr_status); | |
218 | ||
1341c939 SP |
219 | return 0; |
220 | } | |
221 | ||
222 | /** | |
223 | * megasas_fire_cmd_xscale - Sends command to the FW | |
224 | * @frame_phys_addr : Physical address of cmd | |
225 | * @frame_count : Number of frames for the command | |
226 | * @regs : MFI register set | |
227 | */ | |
228 | static inline void | |
229 | megasas_fire_cmd_xscale(dma_addr_t frame_phys_addr,u32 frame_count, struct megasas_register_set __iomem *regs) | |
230 | { | |
231 | writel((frame_phys_addr >> 3)|(frame_count), | |
232 | &(regs)->inbound_queue_port); | |
233 | } | |
234 | ||
235 | static struct megasas_instance_template megasas_instance_template_xscale = { | |
236 | ||
237 | .fire_cmd = megasas_fire_cmd_xscale, | |
238 | .enable_intr = megasas_enable_intr_xscale, | |
b274cab7 | 239 | .disable_intr = megasas_disable_intr_xscale, |
1341c939 SP |
240 | .clear_intr = megasas_clear_intr_xscale, |
241 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, | |
242 | }; | |
243 | ||
244 | /** | |
245 | * This is the end of set of functions & definitions specific | |
246 | * to xscale (deviceid : 1064R, PERC5) controllers | |
247 | */ | |
248 | ||
f9876f0b SP |
249 | /** |
250 | * The following functions are defined for ppc (deviceid : 0x60) | |
251 | * controllers | |
252 | */ | |
253 | ||
254 | /** | |
255 | * megasas_enable_intr_ppc - Enables interrupts | |
256 | * @regs: MFI register set | |
257 | */ | |
258 | static inline void | |
259 | megasas_enable_intr_ppc(struct megasas_register_set __iomem * regs) | |
260 | { | |
261 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); | |
262 | ||
263 | writel(~0x80000004, &(regs)->outbound_intr_mask); | |
264 | ||
265 | /* Dummy readl to force pci flush */ | |
266 | readl(®s->outbound_intr_mask); | |
267 | } | |
268 | ||
b274cab7 SP |
269 | /** |
270 | * megasas_disable_intr_ppc - Disable interrupt | |
271 | * @regs: MFI register set | |
272 | */ | |
273 | static inline void | |
274 | megasas_disable_intr_ppc(struct megasas_register_set __iomem * regs) | |
275 | { | |
276 | u32 mask = 0xFFFFFFFF; | |
277 | writel(mask, ®s->outbound_intr_mask); | |
278 | /* Dummy readl to force pci flush */ | |
279 | readl(®s->outbound_intr_mask); | |
280 | } | |
281 | ||
f9876f0b SP |
282 | /** |
283 | * megasas_read_fw_status_reg_ppc - returns the current FW status value | |
284 | * @regs: MFI register set | |
285 | */ | |
286 | static u32 | |
287 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) | |
288 | { | |
289 | return readl(&(regs)->outbound_scratch_pad); | |
290 | } | |
291 | ||
292 | /** | |
293 | * megasas_clear_interrupt_ppc - Check & clear interrupt | |
294 | * @regs: MFI register set | |
295 | */ | |
296 | static int | |
297 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) | |
298 | { | |
299 | u32 status; | |
300 | /* | |
301 | * Check if it is our interrupt | |
302 | */ | |
303 | status = readl(®s->outbound_intr_status); | |
304 | ||
305 | if (!(status & MFI_REPLY_1078_MESSAGE_INTERRUPT)) { | |
306 | return 1; | |
307 | } | |
308 | ||
309 | /* | |
310 | * Clear the interrupt by writing back the same value | |
311 | */ | |
312 | writel(status, ®s->outbound_doorbell_clear); | |
313 | ||
06f579de YB |
314 | /* Dummy readl to force pci flush */ |
315 | readl(®s->outbound_doorbell_clear); | |
316 | ||
f9876f0b SP |
317 | return 0; |
318 | } | |
319 | /** | |
320 | * megasas_fire_cmd_ppc - Sends command to the FW | |
321 | * @frame_phys_addr : Physical address of cmd | |
322 | * @frame_count : Number of frames for the command | |
323 | * @regs : MFI register set | |
324 | */ | |
325 | static inline void | |
326 | megasas_fire_cmd_ppc(dma_addr_t frame_phys_addr, u32 frame_count, struct megasas_register_set __iomem *regs) | |
327 | { | |
328 | writel((frame_phys_addr | (frame_count<<1))|1, | |
329 | &(regs)->inbound_queue_port); | |
330 | } | |
331 | ||
332 | static struct megasas_instance_template megasas_instance_template_ppc = { | |
333 | ||
334 | .fire_cmd = megasas_fire_cmd_ppc, | |
335 | .enable_intr = megasas_enable_intr_ppc, | |
b274cab7 | 336 | .disable_intr = megasas_disable_intr_ppc, |
f9876f0b SP |
337 | .clear_intr = megasas_clear_intr_ppc, |
338 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, | |
339 | }; | |
340 | ||
87911122 YB |
341 | /** |
342 | * megasas_enable_intr_skinny - Enables interrupts | |
343 | * @regs: MFI register set | |
344 | */ | |
345 | static inline void | |
346 | megasas_enable_intr_skinny(struct megasas_register_set __iomem *regs) | |
347 | { | |
348 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); | |
349 | ||
350 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); | |
351 | ||
352 | /* Dummy readl to force pci flush */ | |
353 | readl(®s->outbound_intr_mask); | |
354 | } | |
355 | ||
356 | /** | |
357 | * megasas_disable_intr_skinny - Disables interrupt | |
358 | * @regs: MFI register set | |
359 | */ | |
360 | static inline void | |
361 | megasas_disable_intr_skinny(struct megasas_register_set __iomem *regs) | |
362 | { | |
363 | u32 mask = 0xFFFFFFFF; | |
364 | writel(mask, ®s->outbound_intr_mask); | |
365 | /* Dummy readl to force pci flush */ | |
366 | readl(®s->outbound_intr_mask); | |
367 | } | |
368 | ||
369 | /** | |
370 | * megasas_read_fw_status_reg_skinny - returns the current FW status value | |
371 | * @regs: MFI register set | |
372 | */ | |
373 | static u32 | |
374 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) | |
375 | { | |
376 | return readl(&(regs)->outbound_scratch_pad); | |
377 | } | |
378 | ||
379 | /** | |
380 | * megasas_clear_interrupt_skinny - Check & clear interrupt | |
381 | * @regs: MFI register set | |
382 | */ | |
383 | static int | |
384 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) | |
385 | { | |
386 | u32 status; | |
387 | /* | |
388 | * Check if it is our interrupt | |
389 | */ | |
390 | status = readl(®s->outbound_intr_status); | |
391 | ||
392 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { | |
393 | return 1; | |
394 | } | |
395 | ||
396 | /* | |
397 | * Clear the interrupt by writing back the same value | |
398 | */ | |
399 | writel(status, ®s->outbound_intr_status); | |
400 | ||
401 | /* | |
402 | * dummy read to flush PCI | |
403 | */ | |
404 | readl(®s->outbound_intr_status); | |
405 | ||
406 | return 0; | |
407 | } | |
408 | ||
409 | /** | |
410 | * megasas_fire_cmd_skinny - Sends command to the FW | |
411 | * @frame_phys_addr : Physical address of cmd | |
412 | * @frame_count : Number of frames for the command | |
413 | * @regs : MFI register set | |
414 | */ | |
415 | static inline void | |
416 | megasas_fire_cmd_skinny(dma_addr_t frame_phys_addr, u32 frame_count, | |
417 | struct megasas_register_set __iomem *regs) | |
418 | { | |
419 | writel(0, &(regs)->inbound_high_queue_port); | |
420 | writel((frame_phys_addr | (frame_count<<1))|1, | |
421 | &(regs)->inbound_low_queue_port); | |
422 | } | |
423 | ||
424 | static struct megasas_instance_template megasas_instance_template_skinny = { | |
425 | ||
426 | .fire_cmd = megasas_fire_cmd_skinny, | |
427 | .enable_intr = megasas_enable_intr_skinny, | |
428 | .disable_intr = megasas_disable_intr_skinny, | |
429 | .clear_intr = megasas_clear_intr_skinny, | |
430 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, | |
431 | }; | |
432 | ||
433 | ||
6610a6b3 YB |
434 | /** |
435 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) | |
436 | * controllers | |
437 | */ | |
438 | ||
439 | /** | |
440 | * megasas_enable_intr_gen2 - Enables interrupts | |
441 | * @regs: MFI register set | |
442 | */ | |
443 | static inline void | |
444 | megasas_enable_intr_gen2(struct megasas_register_set __iomem *regs) | |
445 | { | |
446 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); | |
447 | ||
448 | /* write ~0x00000005 (4 & 1) to the intr mask*/ | |
449 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); | |
450 | ||
451 | /* Dummy readl to force pci flush */ | |
452 | readl(®s->outbound_intr_mask); | |
453 | } | |
454 | ||
455 | /** | |
456 | * megasas_disable_intr_gen2 - Disables interrupt | |
457 | * @regs: MFI register set | |
458 | */ | |
459 | static inline void | |
460 | megasas_disable_intr_gen2(struct megasas_register_set __iomem *regs) | |
461 | { | |
462 | u32 mask = 0xFFFFFFFF; | |
463 | writel(mask, ®s->outbound_intr_mask); | |
464 | /* Dummy readl to force pci flush */ | |
465 | readl(®s->outbound_intr_mask); | |
466 | } | |
467 | ||
468 | /** | |
469 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value | |
470 | * @regs: MFI register set | |
471 | */ | |
472 | static u32 | |
473 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) | |
474 | { | |
475 | return readl(&(regs)->outbound_scratch_pad); | |
476 | } | |
477 | ||
478 | /** | |
479 | * megasas_clear_interrupt_gen2 - Check & clear interrupt | |
480 | * @regs: MFI register set | |
481 | */ | |
482 | static int | |
483 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) | |
484 | { | |
485 | u32 status; | |
486 | /* | |
487 | * Check if it is our interrupt | |
488 | */ | |
489 | status = readl(®s->outbound_intr_status); | |
490 | ||
491 | if (!(status & MFI_GEN2_ENABLE_INTERRUPT_MASK)) | |
492 | return 1; | |
493 | ||
494 | /* | |
495 | * Clear the interrupt by writing back the same value | |
496 | */ | |
497 | writel(status, ®s->outbound_doorbell_clear); | |
498 | ||
499 | /* Dummy readl to force pci flush */ | |
500 | readl(®s->outbound_intr_status); | |
501 | ||
502 | return 0; | |
503 | } | |
504 | /** | |
505 | * megasas_fire_cmd_gen2 - Sends command to the FW | |
506 | * @frame_phys_addr : Physical address of cmd | |
507 | * @frame_count : Number of frames for the command | |
508 | * @regs : MFI register set | |
509 | */ | |
510 | static inline void | |
511 | megasas_fire_cmd_gen2(dma_addr_t frame_phys_addr, u32 frame_count, | |
512 | struct megasas_register_set __iomem *regs) | |
513 | { | |
514 | writel((frame_phys_addr | (frame_count<<1))|1, | |
515 | &(regs)->inbound_queue_port); | |
516 | } | |
517 | ||
518 | static struct megasas_instance_template megasas_instance_template_gen2 = { | |
519 | ||
520 | .fire_cmd = megasas_fire_cmd_gen2, | |
521 | .enable_intr = megasas_enable_intr_gen2, | |
522 | .disable_intr = megasas_disable_intr_gen2, | |
523 | .clear_intr = megasas_clear_intr_gen2, | |
524 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, | |
525 | }; | |
526 | ||
f9876f0b SP |
527 | /** |
528 | * This is the end of set of functions & definitions | |
529 | * specific to ppc (deviceid : 0x60) controllers | |
530 | */ | |
531 | ||
c4a3e0a5 BS |
532 | /** |
533 | * megasas_issue_polled - Issues a polling command | |
534 | * @instance: Adapter soft state | |
535 | * @cmd: Command packet to be issued | |
536 | * | |
537 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. | |
538 | */ | |
539 | static int | |
540 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) | |
541 | { | |
542 | int i; | |
543 | u32 msecs = MFI_POLL_TIMEOUT_SECS * 1000; | |
544 | ||
545 | struct megasas_header *frame_hdr = &cmd->frame->hdr; | |
546 | ||
547 | frame_hdr->cmd_status = 0xFF; | |
548 | frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; | |
549 | ||
550 | /* | |
551 | * Issue the frame using inbound queue port | |
552 | */ | |
1341c939 | 553 | instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set); |
c4a3e0a5 BS |
554 | |
555 | /* | |
556 | * Wait for cmd_status to change | |
557 | */ | |
558 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i++) { | |
559 | rmb(); | |
560 | msleep(1); | |
561 | } | |
562 | ||
563 | if (frame_hdr->cmd_status == 0xff) | |
564 | return -ETIME; | |
565 | ||
566 | return 0; | |
567 | } | |
568 | ||
569 | /** | |
570 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds | |
571 | * @instance: Adapter soft state | |
572 | * @cmd: Command to be issued | |
573 | * | |
574 | * This function waits on an event for the command to be returned from ISR. | |
2a3681e5 | 575 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
c4a3e0a5 BS |
576 | * Used to issue ioctl commands. |
577 | */ | |
578 | static int | |
579 | megasas_issue_blocked_cmd(struct megasas_instance *instance, | |
580 | struct megasas_cmd *cmd) | |
581 | { | |
582 | cmd->cmd_status = ENODATA; | |
583 | ||
1341c939 | 584 | instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set); |
c4a3e0a5 | 585 | |
2a3681e5 SP |
586 | wait_event_timeout(instance->int_cmd_wait_q, (cmd->cmd_status != ENODATA), |
587 | MEGASAS_INTERNAL_CMD_WAIT_TIME*HZ); | |
c4a3e0a5 BS |
588 | |
589 | return 0; | |
590 | } | |
591 | ||
592 | /** | |
593 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd | |
594 | * @instance: Adapter soft state | |
595 | * @cmd_to_abort: Previously issued cmd to be aborted | |
596 | * | |
597 | * MFI firmware can abort previously issued AEN comamnd (automatic event | |
598 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort | |
2a3681e5 SP |
599 | * cmd and waits for return status. |
600 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs | |
c4a3e0a5 BS |
601 | */ |
602 | static int | |
603 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, | |
604 | struct megasas_cmd *cmd_to_abort) | |
605 | { | |
606 | struct megasas_cmd *cmd; | |
607 | struct megasas_abort_frame *abort_fr; | |
608 | ||
609 | cmd = megasas_get_cmd(instance); | |
610 | ||
611 | if (!cmd) | |
612 | return -1; | |
613 | ||
614 | abort_fr = &cmd->frame->abort; | |
615 | ||
616 | /* | |
617 | * Prepare and issue the abort frame | |
618 | */ | |
619 | abort_fr->cmd = MFI_CMD_ABORT; | |
620 | abort_fr->cmd_status = 0xFF; | |
621 | abort_fr->flags = 0; | |
622 | abort_fr->abort_context = cmd_to_abort->index; | |
623 | abort_fr->abort_mfi_phys_addr_lo = cmd_to_abort->frame_phys_addr; | |
624 | abort_fr->abort_mfi_phys_addr_hi = 0; | |
625 | ||
626 | cmd->sync_cmd = 1; | |
627 | cmd->cmd_status = 0xFF; | |
628 | ||
1341c939 | 629 | instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set); |
c4a3e0a5 BS |
630 | |
631 | /* | |
632 | * Wait for this cmd to complete | |
633 | */ | |
2a3681e5 SP |
634 | wait_event_timeout(instance->abort_cmd_wait_q, (cmd->cmd_status != 0xFF), |
635 | MEGASAS_INTERNAL_CMD_WAIT_TIME*HZ); | |
c4a3e0a5 BS |
636 | |
637 | megasas_return_cmd(instance, cmd); | |
638 | return 0; | |
639 | } | |
640 | ||
641 | /** | |
642 | * megasas_make_sgl32 - Prepares 32-bit SGL | |
643 | * @instance: Adapter soft state | |
644 | * @scp: SCSI command from the mid-layer | |
645 | * @mfi_sgl: SGL to be filled in | |
646 | * | |
647 | * If successful, this function returns the number of SG elements. Otherwise, | |
648 | * it returnes -1. | |
649 | */ | |
858119e1 | 650 | static int |
c4a3e0a5 BS |
651 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
652 | union megasas_sgl *mfi_sgl) | |
653 | { | |
654 | int i; | |
655 | int sge_count; | |
656 | struct scatterlist *os_sgl; | |
657 | ||
155d98f0 FT |
658 | sge_count = scsi_dma_map(scp); |
659 | BUG_ON(sge_count < 0); | |
c4a3e0a5 | 660 | |
155d98f0 FT |
661 | if (sge_count) { |
662 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { | |
663 | mfi_sgl->sge32[i].length = sg_dma_len(os_sgl); | |
664 | mfi_sgl->sge32[i].phys_addr = sg_dma_address(os_sgl); | |
665 | } | |
c4a3e0a5 | 666 | } |
c4a3e0a5 BS |
667 | return sge_count; |
668 | } | |
669 | ||
670 | /** | |
671 | * megasas_make_sgl64 - Prepares 64-bit SGL | |
672 | * @instance: Adapter soft state | |
673 | * @scp: SCSI command from the mid-layer | |
674 | * @mfi_sgl: SGL to be filled in | |
675 | * | |
676 | * If successful, this function returns the number of SG elements. Otherwise, | |
677 | * it returnes -1. | |
678 | */ | |
858119e1 | 679 | static int |
c4a3e0a5 BS |
680 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
681 | union megasas_sgl *mfi_sgl) | |
682 | { | |
683 | int i; | |
684 | int sge_count; | |
685 | struct scatterlist *os_sgl; | |
686 | ||
155d98f0 FT |
687 | sge_count = scsi_dma_map(scp); |
688 | BUG_ON(sge_count < 0); | |
c4a3e0a5 | 689 | |
155d98f0 FT |
690 | if (sge_count) { |
691 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { | |
692 | mfi_sgl->sge64[i].length = sg_dma_len(os_sgl); | |
693 | mfi_sgl->sge64[i].phys_addr = sg_dma_address(os_sgl); | |
694 | } | |
c4a3e0a5 | 695 | } |
c4a3e0a5 BS |
696 | return sge_count; |
697 | } | |
698 | ||
b1df99d9 SP |
699 | /** |
700 | * megasas_get_frame_count - Computes the number of frames | |
d532dbe2 | 701 | * @frame_type : type of frame- io or pthru frame |
b1df99d9 SP |
702 | * @sge_count : number of sg elements |
703 | * | |
704 | * Returns the number of frames required for numnber of sge's (sge_count) | |
705 | */ | |
706 | ||
d532dbe2 | 707 | static u32 megasas_get_frame_count(u8 sge_count, u8 frame_type) |
b1df99d9 SP |
708 | { |
709 | int num_cnt; | |
710 | int sge_bytes; | |
711 | u32 sge_sz; | |
712 | u32 frame_count=0; | |
713 | ||
714 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : | |
715 | sizeof(struct megasas_sge32); | |
716 | ||
717 | /* | |
d532dbe2 | 718 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
719 | * 3 SGEs for 32-bit SGLs for ldio & | |
720 | * 1 SGEs for 64-bit SGLs and | |
721 | * 2 SGEs for 32-bit SGLs for pthru frame | |
722 | */ | |
723 | if (unlikely(frame_type == PTHRU_FRAME)) { | |
724 | if (IS_DMA64) | |
725 | num_cnt = sge_count - 1; | |
726 | else | |
727 | num_cnt = sge_count - 2; | |
728 | } else { | |
729 | if (IS_DMA64) | |
730 | num_cnt = sge_count - 2; | |
731 | else | |
732 | num_cnt = sge_count - 3; | |
733 | } | |
b1df99d9 SP |
734 | |
735 | if(num_cnt>0){ | |
736 | sge_bytes = sge_sz * num_cnt; | |
737 | ||
738 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + | |
739 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; | |
740 | } | |
741 | /* Main frame */ | |
742 | frame_count +=1; | |
743 | ||
744 | if (frame_count > 7) | |
745 | frame_count = 8; | |
746 | return frame_count; | |
747 | } | |
748 | ||
c4a3e0a5 BS |
749 | /** |
750 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command | |
751 | * @instance: Adapter soft state | |
752 | * @scp: SCSI command | |
753 | * @cmd: Command to be prepared in | |
754 | * | |
755 | * This function prepares CDB commands. These are typcially pass-through | |
756 | * commands to the devices. | |
757 | */ | |
858119e1 | 758 | static int |
c4a3e0a5 BS |
759 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
760 | struct megasas_cmd *cmd) | |
761 | { | |
c4a3e0a5 BS |
762 | u32 is_logical; |
763 | u32 device_id; | |
764 | u16 flags = 0; | |
765 | struct megasas_pthru_frame *pthru; | |
766 | ||
767 | is_logical = MEGASAS_IS_LOGICAL(scp); | |
768 | device_id = MEGASAS_DEV_INDEX(instance, scp); | |
769 | pthru = (struct megasas_pthru_frame *)cmd->frame; | |
770 | ||
771 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) | |
772 | flags = MFI_FRAME_DIR_WRITE; | |
773 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | |
774 | flags = MFI_FRAME_DIR_READ; | |
775 | else if (scp->sc_data_direction == PCI_DMA_NONE) | |
776 | flags = MFI_FRAME_DIR_NONE; | |
777 | ||
778 | /* | |
779 | * Prepare the DCDB frame | |
780 | */ | |
781 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; | |
782 | pthru->cmd_status = 0x0; | |
783 | pthru->scsi_status = 0x0; | |
784 | pthru->target_id = device_id; | |
785 | pthru->lun = scp->device->lun; | |
786 | pthru->cdb_len = scp->cmd_len; | |
787 | pthru->timeout = 0; | |
788 | pthru->flags = flags; | |
155d98f0 | 789 | pthru->data_xfer_len = scsi_bufflen(scp); |
c4a3e0a5 BS |
790 | |
791 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); | |
792 | ||
8d568253 YB |
793 | /* |
794 | * If the command is for the tape device, set the | |
795 | * pthru timeout to the os layer timeout value. | |
796 | */ | |
797 | if (scp->device->type == TYPE_TAPE) { | |
798 | if ((scp->request->timeout / HZ) > 0xFFFF) | |
799 | pthru->timeout = 0xFFFF; | |
800 | else | |
801 | pthru->timeout = scp->request->timeout / HZ; | |
802 | } | |
803 | ||
c4a3e0a5 BS |
804 | /* |
805 | * Construct SGL | |
806 | */ | |
c4a3e0a5 BS |
807 | if (IS_DMA64) { |
808 | pthru->flags |= MFI_FRAME_SGL64; | |
809 | pthru->sge_count = megasas_make_sgl64(instance, scp, | |
810 | &pthru->sgl); | |
811 | } else | |
812 | pthru->sge_count = megasas_make_sgl32(instance, scp, | |
813 | &pthru->sgl); | |
814 | ||
815 | /* | |
816 | * Sense info specific | |
817 | */ | |
818 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; | |
819 | pthru->sense_buf_phys_addr_hi = 0; | |
820 | pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; | |
821 | ||
c4a3e0a5 BS |
822 | /* |
823 | * Compute the total number of frames this command consumes. FW uses | |
824 | * this number to pull sufficient number of frames from host memory. | |
825 | */ | |
d532dbe2 | 826 | cmd->frame_count = megasas_get_frame_count(pthru->sge_count, |
827 | PTHRU_FRAME); | |
c4a3e0a5 BS |
828 | |
829 | return cmd->frame_count; | |
830 | } | |
831 | ||
832 | /** | |
833 | * megasas_build_ldio - Prepares IOs to logical devices | |
834 | * @instance: Adapter soft state | |
835 | * @scp: SCSI command | |
fd589a8f | 836 | * @cmd: Command to be prepared |
c4a3e0a5 BS |
837 | * |
838 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. | |
839 | */ | |
858119e1 | 840 | static int |
c4a3e0a5 BS |
841 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
842 | struct megasas_cmd *cmd) | |
843 | { | |
c4a3e0a5 BS |
844 | u32 device_id; |
845 | u8 sc = scp->cmnd[0]; | |
846 | u16 flags = 0; | |
847 | struct megasas_io_frame *ldio; | |
848 | ||
849 | device_id = MEGASAS_DEV_INDEX(instance, scp); | |
850 | ldio = (struct megasas_io_frame *)cmd->frame; | |
851 | ||
852 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) | |
853 | flags = MFI_FRAME_DIR_WRITE; | |
854 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | |
855 | flags = MFI_FRAME_DIR_READ; | |
856 | ||
857 | /* | |
b1df99d9 | 858 | * Prepare the Logical IO frame: 2nd bit is zero for all read cmds |
c4a3e0a5 BS |
859 | */ |
860 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; | |
861 | ldio->cmd_status = 0x0; | |
862 | ldio->scsi_status = 0x0; | |
863 | ldio->target_id = device_id; | |
864 | ldio->timeout = 0; | |
865 | ldio->reserved_0 = 0; | |
866 | ldio->pad_0 = 0; | |
867 | ldio->flags = flags; | |
868 | ldio->start_lba_hi = 0; | |
869 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; | |
870 | ||
871 | /* | |
872 | * 6-byte READ(0x08) or WRITE(0x0A) cdb | |
873 | */ | |
874 | if (scp->cmd_len == 6) { | |
875 | ldio->lba_count = (u32) scp->cmnd[4]; | |
876 | ldio->start_lba_lo = ((u32) scp->cmnd[1] << 16) | | |
877 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; | |
878 | ||
879 | ldio->start_lba_lo &= 0x1FFFFF; | |
880 | } | |
881 | ||
882 | /* | |
883 | * 10-byte READ(0x28) or WRITE(0x2A) cdb | |
884 | */ | |
885 | else if (scp->cmd_len == 10) { | |
886 | ldio->lba_count = (u32) scp->cmnd[8] | | |
887 | ((u32) scp->cmnd[7] << 8); | |
888 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | | |
889 | ((u32) scp->cmnd[3] << 16) | | |
890 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
891 | } | |
892 | ||
893 | /* | |
894 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb | |
895 | */ | |
896 | else if (scp->cmd_len == 12) { | |
897 | ldio->lba_count = ((u32) scp->cmnd[6] << 24) | | |
898 | ((u32) scp->cmnd[7] << 16) | | |
899 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | |
900 | ||
901 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | | |
902 | ((u32) scp->cmnd[3] << 16) | | |
903 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
904 | } | |
905 | ||
906 | /* | |
907 | * 16-byte READ(0x88) or WRITE(0x8A) cdb | |
908 | */ | |
909 | else if (scp->cmd_len == 16) { | |
910 | ldio->lba_count = ((u32) scp->cmnd[10] << 24) | | |
911 | ((u32) scp->cmnd[11] << 16) | | |
912 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; | |
913 | ||
914 | ldio->start_lba_lo = ((u32) scp->cmnd[6] << 24) | | |
915 | ((u32) scp->cmnd[7] << 16) | | |
916 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | |
917 | ||
918 | ldio->start_lba_hi = ((u32) scp->cmnd[2] << 24) | | |
919 | ((u32) scp->cmnd[3] << 16) | | |
920 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | |
921 | ||
922 | } | |
923 | ||
924 | /* | |
925 | * Construct SGL | |
926 | */ | |
c4a3e0a5 BS |
927 | if (IS_DMA64) { |
928 | ldio->flags |= MFI_FRAME_SGL64; | |
929 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); | |
930 | } else | |
931 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); | |
932 | ||
933 | /* | |
934 | * Sense info specific | |
935 | */ | |
936 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; | |
937 | ldio->sense_buf_phys_addr_hi = 0; | |
938 | ldio->sense_buf_phys_addr_lo = cmd->sense_phys_addr; | |
939 | ||
b1df99d9 SP |
940 | /* |
941 | * Compute the total number of frames this command consumes. FW uses | |
942 | * this number to pull sufficient number of frames from host memory. | |
943 | */ | |
d532dbe2 | 944 | cmd->frame_count = megasas_get_frame_count(ldio->sge_count, IO_FRAME); |
c4a3e0a5 BS |
945 | |
946 | return cmd->frame_count; | |
947 | } | |
948 | ||
949 | /** | |
cb59aa6a SP |
950 | * megasas_is_ldio - Checks if the cmd is for logical drive |
951 | * @scmd: SCSI command | |
952 | * | |
953 | * Called by megasas_queue_command to find out if the command to be queued | |
954 | * is a logical drive command | |
c4a3e0a5 | 955 | */ |
cb59aa6a | 956 | static inline int megasas_is_ldio(struct scsi_cmnd *cmd) |
c4a3e0a5 | 957 | { |
cb59aa6a SP |
958 | if (!MEGASAS_IS_LOGICAL(cmd)) |
959 | return 0; | |
960 | switch (cmd->cmnd[0]) { | |
961 | case READ_10: | |
962 | case WRITE_10: | |
963 | case READ_12: | |
964 | case WRITE_12: | |
965 | case READ_6: | |
966 | case WRITE_6: | |
967 | case READ_16: | |
968 | case WRITE_16: | |
969 | return 1; | |
970 | default: | |
971 | return 0; | |
c4a3e0a5 | 972 | } |
c4a3e0a5 BS |
973 | } |
974 | ||
658dcedb SP |
975 | /** |
976 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds | |
977 | * in FW | |
978 | * @instance: Adapter soft state | |
979 | */ | |
980 | static inline void | |
981 | megasas_dump_pending_frames(struct megasas_instance *instance) | |
982 | { | |
983 | struct megasas_cmd *cmd; | |
984 | int i,n; | |
985 | union megasas_sgl *mfi_sgl; | |
986 | struct megasas_io_frame *ldio; | |
987 | struct megasas_pthru_frame *pthru; | |
988 | u32 sgcount; | |
989 | u32 max_cmd = instance->max_fw_cmds; | |
990 | ||
991 | printk(KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); | |
992 | printk(KERN_ERR "megasas[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding)); | |
993 | if (IS_DMA64) | |
994 | printk(KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no); | |
995 | else | |
996 | printk(KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no); | |
997 | ||
998 | printk(KERN_ERR "megasas[%d]: Pending OS cmds in FW : \n",instance->host->host_no); | |
999 | for (i = 0; i < max_cmd; i++) { | |
1000 | cmd = instance->cmd_list[i]; | |
1001 | if(!cmd->scmd) | |
1002 | continue; | |
1003 | printk(KERN_ERR "megasas[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr); | |
1004 | if (megasas_is_ldio(cmd->scmd)){ | |
1005 | ldio = (struct megasas_io_frame *)cmd->frame; | |
1006 | mfi_sgl = &ldio->sgl; | |
1007 | sgcount = ldio->sge_count; | |
1008 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->host->host_no, cmd->frame_count,ldio->cmd,ldio->target_id, ldio->start_lba_lo,ldio->start_lba_hi,ldio->sense_buf_phys_addr_lo,sgcount); | |
1009 | } | |
1010 | else { | |
1011 | pthru = (struct megasas_pthru_frame *) cmd->frame; | |
1012 | mfi_sgl = &pthru->sgl; | |
1013 | sgcount = pthru->sge_count; | |
1014 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->host->host_no,cmd->frame_count,pthru->cmd,pthru->target_id,pthru->lun,pthru->cdb_len , pthru->data_xfer_len,pthru->sense_buf_phys_addr_lo,sgcount); | |
1015 | } | |
1016 | if(megasas_dbg_lvl & MEGASAS_DBG_LVL){ | |
1017 | for (n = 0; n < sgcount; n++){ | |
1018 | if (IS_DMA64) | |
1019 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%08lx ",mfi_sgl->sge64[n].length , (unsigned long)mfi_sgl->sge64[n].phys_addr) ; | |
1020 | else | |
1021 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ",mfi_sgl->sge32[n].length , mfi_sgl->sge32[n].phys_addr) ; | |
1022 | } | |
1023 | } | |
1024 | printk(KERN_ERR "\n"); | |
1025 | } /*for max_cmd*/ | |
1026 | printk(KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->host->host_no); | |
1027 | for (i = 0; i < max_cmd; i++) { | |
1028 | ||
1029 | cmd = instance->cmd_list[i]; | |
1030 | ||
1031 | if(cmd->sync_cmd == 1){ | |
1032 | printk(KERN_ERR "0x%08lx : ", (unsigned long)cmd->frame_phys_addr); | |
1033 | } | |
1034 | } | |
1035 | printk(KERN_ERR "megasas[%d]: Dumping Done.\n\n",instance->host->host_no); | |
1036 | } | |
1037 | ||
c4a3e0a5 BS |
1038 | /** |
1039 | * megasas_queue_command - Queue entry point | |
1040 | * @scmd: SCSI command to be queued | |
1041 | * @done: Callback entry point | |
1042 | */ | |
1043 | static int | |
1044 | megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *)) | |
1045 | { | |
1046 | u32 frame_count; | |
c4a3e0a5 BS |
1047 | struct megasas_cmd *cmd; |
1048 | struct megasas_instance *instance; | |
1049 | ||
1050 | instance = (struct megasas_instance *) | |
1051 | scmd->device->host->hostdata; | |
af37acfb SP |
1052 | |
1053 | /* Don't process if we have already declared adapter dead */ | |
1054 | if (instance->hw_crit_error) | |
1055 | return SCSI_MLQUEUE_HOST_BUSY; | |
1056 | ||
c4a3e0a5 BS |
1057 | scmd->scsi_done = done; |
1058 | scmd->result = 0; | |
1059 | ||
cb59aa6a SP |
1060 | if (MEGASAS_IS_LOGICAL(scmd) && |
1061 | (scmd->device->id >= MEGASAS_MAX_LD || scmd->device->lun)) { | |
1062 | scmd->result = DID_BAD_TARGET << 16; | |
1063 | goto out_done; | |
c4a3e0a5 BS |
1064 | } |
1065 | ||
02b01e01 SP |
1066 | switch (scmd->cmnd[0]) { |
1067 | case SYNCHRONIZE_CACHE: | |
1068 | /* | |
1069 | * FW takes care of flush cache on its own | |
1070 | * No need to send it down | |
1071 | */ | |
1072 | scmd->result = DID_OK << 16; | |
1073 | goto out_done; | |
1074 | default: | |
1075 | break; | |
1076 | } | |
1077 | ||
cb59aa6a SP |
1078 | cmd = megasas_get_cmd(instance); |
1079 | if (!cmd) | |
1080 | return SCSI_MLQUEUE_HOST_BUSY; | |
1081 | ||
1082 | /* | |
1083 | * Logical drive command | |
1084 | */ | |
1085 | if (megasas_is_ldio(scmd)) | |
1086 | frame_count = megasas_build_ldio(instance, scmd, cmd); | |
1087 | else | |
1088 | frame_count = megasas_build_dcdb(instance, scmd, cmd); | |
1089 | ||
1090 | if (!frame_count) | |
1091 | goto out_return_cmd; | |
1092 | ||
c4a3e0a5 | 1093 | cmd->scmd = scmd; |
05e9ebbe | 1094 | scmd->SCp.ptr = (char *)cmd; |
c4a3e0a5 BS |
1095 | |
1096 | /* | |
1097 | * Issue the command to the FW | |
1098 | */ | |
e4a082c7 | 1099 | atomic_inc(&instance->fw_outstanding); |
c4a3e0a5 | 1100 | |
1341c939 | 1101 | instance->instancet->fire_cmd(cmd->frame_phys_addr ,cmd->frame_count-1,instance->reg_set); |
ad84db2e | 1102 | /* |
1103 | * Check if we have pend cmds to be completed | |
1104 | */ | |
1105 | if (poll_mode_io && atomic_read(&instance->fw_outstanding)) | |
1106 | tasklet_schedule(&instance->isr_tasklet); | |
1107 | ||
c4a3e0a5 BS |
1108 | |
1109 | return 0; | |
cb59aa6a SP |
1110 | |
1111 | out_return_cmd: | |
1112 | megasas_return_cmd(instance, cmd); | |
1113 | out_done: | |
1114 | done(scmd); | |
1115 | return 0; | |
c4a3e0a5 BS |
1116 | } |
1117 | ||
147aab6a CH |
1118 | static int megasas_slave_configure(struct scsi_device *sdev) |
1119 | { | |
1120 | /* | |
1121 | * Don't export physical disk devices to the disk driver. | |
1122 | * | |
1123 | * FIXME: Currently we don't export them to the midlayer at all. | |
1124 | * That will be fixed once LSI engineers have audited the | |
1125 | * firmware for possible issues. | |
1126 | */ | |
1127 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && sdev->type == TYPE_DISK) | |
1128 | return -ENXIO; | |
e5b3a65f CH |
1129 | |
1130 | /* | |
1131 | * The RAID firmware may require extended timeouts. | |
1132 | */ | |
1133 | if (sdev->channel >= MEGASAS_MAX_PD_CHANNELS) | |
ee1ab9e9 JB |
1134 | blk_queue_rq_timeout(sdev->request_queue, |
1135 | MEGASAS_DEFAULT_CMD_TIMEOUT * HZ); | |
147aab6a CH |
1136 | return 0; |
1137 | } | |
1138 | ||
7343eb65 | 1139 | /** |
1140 | * megasas_complete_cmd_dpc - Returns FW's controller structure | |
1141 | * @instance_addr: Address of adapter soft state | |
1142 | * | |
1143 | * Tasklet to complete cmds | |
1144 | */ | |
1145 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) | |
1146 | { | |
1147 | u32 producer; | |
1148 | u32 consumer; | |
1149 | u32 context; | |
1150 | struct megasas_cmd *cmd; | |
1151 | struct megasas_instance *instance = | |
1152 | (struct megasas_instance *)instance_addr; | |
1153 | unsigned long flags; | |
1154 | ||
1155 | /* If we have already declared adapter dead, donot complete cmds */ | |
1156 | if (instance->hw_crit_error) | |
1157 | return; | |
1158 | ||
1159 | spin_lock_irqsave(&instance->completion_lock, flags); | |
1160 | ||
1161 | producer = *instance->producer; | |
1162 | consumer = *instance->consumer; | |
1163 | ||
1164 | while (consumer != producer) { | |
1165 | context = instance->reply_queue[consumer]; | |
1166 | ||
1167 | cmd = instance->cmd_list[context]; | |
1168 | ||
1169 | megasas_complete_cmd(instance, cmd, DID_OK); | |
1170 | ||
1171 | consumer++; | |
1172 | if (consumer == (instance->max_fw_cmds + 1)) { | |
1173 | consumer = 0; | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | *instance->consumer = producer; | |
1178 | ||
1179 | spin_unlock_irqrestore(&instance->completion_lock, flags); | |
1180 | ||
1181 | /* | |
1182 | * Check if we can restore can_queue | |
1183 | */ | |
1184 | if (instance->flag & MEGASAS_FW_BUSY | |
1185 | && time_after(jiffies, instance->last_time + 5 * HZ) | |
1186 | && atomic_read(&instance->fw_outstanding) < 17) { | |
1187 | ||
1188 | spin_lock_irqsave(instance->host->host_lock, flags); | |
1189 | instance->flag &= ~MEGASAS_FW_BUSY; | |
1190 | instance->host->can_queue = | |
1191 | instance->max_fw_cmds - MEGASAS_INT_CMDS; | |
1192 | ||
1193 | spin_unlock_irqrestore(instance->host->host_lock, flags); | |
1194 | } | |
1195 | } | |
1196 | ||
c4a3e0a5 BS |
1197 | /** |
1198 | * megasas_wait_for_outstanding - Wait for all outstanding cmds | |
1199 | * @instance: Adapter soft state | |
1200 | * | |
1201 | * This function waits for upto MEGASAS_RESET_WAIT_TIME seconds for FW to | |
1202 | * complete all its outstanding commands. Returns error if one or more IOs | |
1203 | * are pending after this time period. It also marks the controller dead. | |
1204 | */ | |
1205 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) | |
1206 | { | |
1207 | int i; | |
1208 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; | |
1209 | ||
1210 | for (i = 0; i < wait_time; i++) { | |
1211 | ||
e4a082c7 SP |
1212 | int outstanding = atomic_read(&instance->fw_outstanding); |
1213 | ||
1214 | if (!outstanding) | |
c4a3e0a5 BS |
1215 | break; |
1216 | ||
1217 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { | |
1218 | printk(KERN_NOTICE "megasas: [%2d]waiting for %d " | |
e4a082c7 | 1219 | "commands to complete\n",i,outstanding); |
7343eb65 | 1220 | /* |
1221 | * Call cmd completion routine. Cmd to be | |
1222 | * be completed directly without depending on isr. | |
1223 | */ | |
1224 | megasas_complete_cmd_dpc((unsigned long)instance); | |
c4a3e0a5 BS |
1225 | } |
1226 | ||
1227 | msleep(1000); | |
1228 | } | |
1229 | ||
e4a082c7 | 1230 | if (atomic_read(&instance->fw_outstanding)) { |
e3bbff9f SP |
1231 | /* |
1232 | * Send signal to FW to stop processing any pending cmds. | |
1233 | * The controller will be taken offline by the OS now. | |
1234 | */ | |
1235 | writel(MFI_STOP_ADP, | |
1236 | &instance->reg_set->inbound_doorbell); | |
658dcedb | 1237 | megasas_dump_pending_frames(instance); |
c4a3e0a5 BS |
1238 | instance->hw_crit_error = 1; |
1239 | return FAILED; | |
1240 | } | |
1241 | ||
1242 | return SUCCESS; | |
1243 | } | |
1244 | ||
1245 | /** | |
1246 | * megasas_generic_reset - Generic reset routine | |
1247 | * @scmd: Mid-layer SCSI command | |
1248 | * | |
1249 | * This routine implements a generic reset handler for device, bus and host | |
1250 | * reset requests. Device, bus and host specific reset handlers can use this | |
1251 | * function after they do their specific tasks. | |
1252 | */ | |
1253 | static int megasas_generic_reset(struct scsi_cmnd *scmd) | |
1254 | { | |
1255 | int ret_val; | |
1256 | struct megasas_instance *instance; | |
1257 | ||
1258 | instance = (struct megasas_instance *)scmd->device->host->hostdata; | |
1259 | ||
05e9ebbe SP |
1260 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET -%ld cmd=%x retries=%x\n", |
1261 | scmd->serial_number, scmd->cmnd[0], scmd->retries); | |
c4a3e0a5 BS |
1262 | |
1263 | if (instance->hw_crit_error) { | |
1264 | printk(KERN_ERR "megasas: cannot recover from previous reset " | |
1265 | "failures\n"); | |
1266 | return FAILED; | |
1267 | } | |
1268 | ||
c4a3e0a5 | 1269 | ret_val = megasas_wait_for_outstanding(instance); |
c4a3e0a5 BS |
1270 | if (ret_val == SUCCESS) |
1271 | printk(KERN_NOTICE "megasas: reset successful \n"); | |
1272 | else | |
1273 | printk(KERN_ERR "megasas: failed to do reset\n"); | |
1274 | ||
c4a3e0a5 BS |
1275 | return ret_val; |
1276 | } | |
1277 | ||
05e9ebbe SP |
1278 | /** |
1279 | * megasas_reset_timer - quiesce the adapter if required | |
1280 | * @scmd: scsi cmnd | |
1281 | * | |
1282 | * Sets the FW busy flag and reduces the host->can_queue if the | |
1283 | * cmd has not been completed within the timeout period. | |
1284 | */ | |
1285 | static enum | |
242f9dcb | 1286 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
05e9ebbe SP |
1287 | { |
1288 | struct megasas_cmd *cmd = (struct megasas_cmd *)scmd->SCp.ptr; | |
1289 | struct megasas_instance *instance; | |
1290 | unsigned long flags; | |
1291 | ||
1292 | if (time_after(jiffies, scmd->jiffies_at_alloc + | |
1293 | (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) { | |
242f9dcb | 1294 | return BLK_EH_NOT_HANDLED; |
05e9ebbe SP |
1295 | } |
1296 | ||
1297 | instance = cmd->instance; | |
1298 | if (!(instance->flag & MEGASAS_FW_BUSY)) { | |
1299 | /* FW is busy, throttle IO */ | |
1300 | spin_lock_irqsave(instance->host->host_lock, flags); | |
1301 | ||
1302 | instance->host->can_queue = 16; | |
1303 | instance->last_time = jiffies; | |
1304 | instance->flag |= MEGASAS_FW_BUSY; | |
1305 | ||
1306 | spin_unlock_irqrestore(instance->host->host_lock, flags); | |
1307 | } | |
242f9dcb | 1308 | return BLK_EH_RESET_TIMER; |
05e9ebbe SP |
1309 | } |
1310 | ||
c4a3e0a5 BS |
1311 | /** |
1312 | * megasas_reset_device - Device reset handler entry point | |
1313 | */ | |
1314 | static int megasas_reset_device(struct scsi_cmnd *scmd) | |
1315 | { | |
1316 | int ret; | |
1317 | ||
1318 | /* | |
1319 | * First wait for all commands to complete | |
1320 | */ | |
1321 | ret = megasas_generic_reset(scmd); | |
1322 | ||
1323 | return ret; | |
1324 | } | |
1325 | ||
1326 | /** | |
1327 | * megasas_reset_bus_host - Bus & host reset handler entry point | |
1328 | */ | |
1329 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) | |
1330 | { | |
1331 | int ret; | |
1332 | ||
1333 | /* | |
80682fa9 | 1334 | * First wait for all commands to complete |
c4a3e0a5 BS |
1335 | */ |
1336 | ret = megasas_generic_reset(scmd); | |
1337 | ||
1338 | return ret; | |
1339 | } | |
1340 | ||
cf62a0a5 SP |
1341 | /** |
1342 | * megasas_bios_param - Returns disk geometry for a disk | |
1343 | * @sdev: device handle | |
1344 | * @bdev: block device | |
1345 | * @capacity: drive capacity | |
1346 | * @geom: geometry parameters | |
1347 | */ | |
1348 | static int | |
1349 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, | |
1350 | sector_t capacity, int geom[]) | |
1351 | { | |
1352 | int heads; | |
1353 | int sectors; | |
1354 | sector_t cylinders; | |
1355 | unsigned long tmp; | |
1356 | /* Default heads (64) & sectors (32) */ | |
1357 | heads = 64; | |
1358 | sectors = 32; | |
1359 | ||
1360 | tmp = heads * sectors; | |
1361 | cylinders = capacity; | |
1362 | ||
1363 | sector_div(cylinders, tmp); | |
1364 | ||
1365 | /* | |
1366 | * Handle extended translation size for logical drives > 1Gb | |
1367 | */ | |
1368 | ||
1369 | if (capacity >= 0x200000) { | |
1370 | heads = 255; | |
1371 | sectors = 63; | |
1372 | tmp = heads*sectors; | |
1373 | cylinders = capacity; | |
1374 | sector_div(cylinders, tmp); | |
1375 | } | |
1376 | ||
1377 | geom[0] = heads; | |
1378 | geom[1] = sectors; | |
1379 | geom[2] = cylinders; | |
1380 | ||
1381 | return 0; | |
1382 | } | |
1383 | ||
c4a3e0a5 BS |
1384 | /** |
1385 | * megasas_service_aen - Processes an event notification | |
1386 | * @instance: Adapter soft state | |
1387 | * @cmd: AEN command completed by the ISR | |
1388 | * | |
1389 | * For AEN, driver sends a command down to FW that is held by the FW till an | |
1390 | * event occurs. When an event of interest occurs, FW completes the command | |
1391 | * that it was previously holding. | |
1392 | * | |
1393 | * This routines sends SIGIO signal to processes that have registered with the | |
1394 | * driver for AEN. | |
1395 | */ | |
1396 | static void | |
1397 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) | |
1398 | { | |
c3518837 | 1399 | unsigned long flags; |
c4a3e0a5 BS |
1400 | /* |
1401 | * Don't signal app if it is just an aborted previously registered aen | |
1402 | */ | |
c3518837 YB |
1403 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
1404 | spin_lock_irqsave(&poll_aen_lock, flags); | |
1405 | megasas_poll_wait_aen = 1; | |
1406 | spin_unlock_irqrestore(&poll_aen_lock, flags); | |
1407 | wake_up(&megasas_poll_wait); | |
c4a3e0a5 | 1408 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
c3518837 | 1409 | } |
c4a3e0a5 BS |
1410 | else |
1411 | cmd->abort_aen = 0; | |
1412 | ||
1413 | instance->aen_cmd = NULL; | |
1414 | megasas_return_cmd(instance, cmd); | |
1415 | } | |
1416 | ||
1417 | /* | |
1418 | * Scsi host template for megaraid_sas driver | |
1419 | */ | |
1420 | static struct scsi_host_template megasas_template = { | |
1421 | ||
1422 | .module = THIS_MODULE, | |
f28cd7cf | 1423 | .name = "LSI SAS based MegaRAID driver", |
c4a3e0a5 | 1424 | .proc_name = "megaraid_sas", |
147aab6a | 1425 | .slave_configure = megasas_slave_configure, |
c4a3e0a5 BS |
1426 | .queuecommand = megasas_queue_command, |
1427 | .eh_device_reset_handler = megasas_reset_device, | |
1428 | .eh_bus_reset_handler = megasas_reset_bus_host, | |
1429 | .eh_host_reset_handler = megasas_reset_bus_host, | |
05e9ebbe | 1430 | .eh_timed_out = megasas_reset_timer, |
cf62a0a5 | 1431 | .bios_param = megasas_bios_param, |
c4a3e0a5 BS |
1432 | .use_clustering = ENABLE_CLUSTERING, |
1433 | }; | |
1434 | ||
1435 | /** | |
1436 | * megasas_complete_int_cmd - Completes an internal command | |
1437 | * @instance: Adapter soft state | |
1438 | * @cmd: Command to be completed | |
1439 | * | |
1440 | * The megasas_issue_blocked_cmd() function waits for a command to complete | |
1441 | * after it issues a command. This function wakes up that waiting routine by | |
1442 | * calling wake_up() on the wait queue. | |
1443 | */ | |
1444 | static void | |
1445 | megasas_complete_int_cmd(struct megasas_instance *instance, | |
1446 | struct megasas_cmd *cmd) | |
1447 | { | |
1448 | cmd->cmd_status = cmd->frame->io.cmd_status; | |
1449 | ||
1450 | if (cmd->cmd_status == ENODATA) { | |
1451 | cmd->cmd_status = 0; | |
1452 | } | |
1453 | wake_up(&instance->int_cmd_wait_q); | |
1454 | } | |
1455 | ||
1456 | /** | |
1457 | * megasas_complete_abort - Completes aborting a command | |
1458 | * @instance: Adapter soft state | |
1459 | * @cmd: Cmd that was issued to abort another cmd | |
1460 | * | |
1461 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q | |
1462 | * after it issues an abort on a previously issued command. This function | |
1463 | * wakes up all functions waiting on the same wait queue. | |
1464 | */ | |
1465 | static void | |
1466 | megasas_complete_abort(struct megasas_instance *instance, | |
1467 | struct megasas_cmd *cmd) | |
1468 | { | |
1469 | if (cmd->sync_cmd) { | |
1470 | cmd->sync_cmd = 0; | |
1471 | cmd->cmd_status = 0; | |
1472 | wake_up(&instance->abort_cmd_wait_q); | |
1473 | } | |
1474 | ||
1475 | return; | |
1476 | } | |
1477 | ||
c4a3e0a5 BS |
1478 | /** |
1479 | * megasas_complete_cmd - Completes a command | |
1480 | * @instance: Adapter soft state | |
1481 | * @cmd: Command to be completed | |
1482 | * @alt_status: If non-zero, use this value as status to | |
1483 | * SCSI mid-layer instead of the value returned | |
1484 | * by the FW. This should be used if caller wants | |
1485 | * an alternate status (as in the case of aborted | |
1486 | * commands) | |
1487 | */ | |
858119e1 | 1488 | static void |
c4a3e0a5 BS |
1489 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
1490 | u8 alt_status) | |
1491 | { | |
1492 | int exception = 0; | |
1493 | struct megasas_header *hdr = &cmd->frame->hdr; | |
c3518837 | 1494 | unsigned long flags; |
c4a3e0a5 | 1495 | |
05e9ebbe SP |
1496 | if (cmd->scmd) |
1497 | cmd->scmd->SCp.ptr = NULL; | |
c4a3e0a5 BS |
1498 | |
1499 | switch (hdr->cmd) { | |
1500 | ||
1501 | case MFI_CMD_PD_SCSI_IO: | |
1502 | case MFI_CMD_LD_SCSI_IO: | |
1503 | ||
1504 | /* | |
1505 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been | |
1506 | * issued either through an IO path or an IOCTL path. If it | |
1507 | * was via IOCTL, we will send it to internal completion. | |
1508 | */ | |
1509 | if (cmd->sync_cmd) { | |
1510 | cmd->sync_cmd = 0; | |
1511 | megasas_complete_int_cmd(instance, cmd); | |
1512 | break; | |
1513 | } | |
1514 | ||
c4a3e0a5 BS |
1515 | case MFI_CMD_LD_READ: |
1516 | case MFI_CMD_LD_WRITE: | |
1517 | ||
1518 | if (alt_status) { | |
1519 | cmd->scmd->result = alt_status << 16; | |
1520 | exception = 1; | |
1521 | } | |
1522 | ||
1523 | if (exception) { | |
1524 | ||
e4a082c7 | 1525 | atomic_dec(&instance->fw_outstanding); |
c4a3e0a5 | 1526 | |
155d98f0 | 1527 | scsi_dma_unmap(cmd->scmd); |
c4a3e0a5 BS |
1528 | cmd->scmd->scsi_done(cmd->scmd); |
1529 | megasas_return_cmd(instance, cmd); | |
1530 | ||
1531 | break; | |
1532 | } | |
1533 | ||
1534 | switch (hdr->cmd_status) { | |
1535 | ||
1536 | case MFI_STAT_OK: | |
1537 | cmd->scmd->result = DID_OK << 16; | |
1538 | break; | |
1539 | ||
1540 | case MFI_STAT_SCSI_IO_FAILED: | |
1541 | case MFI_STAT_LD_INIT_IN_PROGRESS: | |
1542 | cmd->scmd->result = | |
1543 | (DID_ERROR << 16) | hdr->scsi_status; | |
1544 | break; | |
1545 | ||
1546 | case MFI_STAT_SCSI_DONE_WITH_ERROR: | |
1547 | ||
1548 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; | |
1549 | ||
1550 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { | |
1551 | memset(cmd->scmd->sense_buffer, 0, | |
1552 | SCSI_SENSE_BUFFERSIZE); | |
1553 | memcpy(cmd->scmd->sense_buffer, cmd->sense, | |
1554 | hdr->sense_len); | |
1555 | ||
1556 | cmd->scmd->result |= DRIVER_SENSE << 24; | |
1557 | } | |
1558 | ||
1559 | break; | |
1560 | ||
1561 | case MFI_STAT_LD_OFFLINE: | |
1562 | case MFI_STAT_DEVICE_NOT_FOUND: | |
1563 | cmd->scmd->result = DID_BAD_TARGET << 16; | |
1564 | break; | |
1565 | ||
1566 | default: | |
1567 | printk(KERN_DEBUG "megasas: MFI FW status %#x\n", | |
1568 | hdr->cmd_status); | |
1569 | cmd->scmd->result = DID_ERROR << 16; | |
1570 | break; | |
1571 | } | |
1572 | ||
e4a082c7 | 1573 | atomic_dec(&instance->fw_outstanding); |
c4a3e0a5 | 1574 | |
155d98f0 | 1575 | scsi_dma_unmap(cmd->scmd); |
c4a3e0a5 BS |
1576 | cmd->scmd->scsi_done(cmd->scmd); |
1577 | megasas_return_cmd(instance, cmd); | |
1578 | ||
1579 | break; | |
1580 | ||
1581 | case MFI_CMD_SMP: | |
1582 | case MFI_CMD_STP: | |
1583 | case MFI_CMD_DCMD: | |
c3518837 YB |
1584 | if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
1585 | cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET) { | |
1586 | spin_lock_irqsave(&poll_aen_lock, flags); | |
1587 | megasas_poll_wait_aen = 0; | |
1588 | spin_unlock_irqrestore(&poll_aen_lock, flags); | |
1589 | } | |
c4a3e0a5 BS |
1590 | |
1591 | /* | |
1592 | * See if got an event notification | |
1593 | */ | |
1594 | if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_WAIT) | |
1595 | megasas_service_aen(instance, cmd); | |
1596 | else | |
1597 | megasas_complete_int_cmd(instance, cmd); | |
1598 | ||
1599 | break; | |
1600 | ||
1601 | case MFI_CMD_ABORT: | |
1602 | /* | |
1603 | * Cmd issued to abort another cmd returned | |
1604 | */ | |
1605 | megasas_complete_abort(instance, cmd); | |
1606 | break; | |
1607 | ||
1608 | default: | |
1609 | printk("megasas: Unknown command completed! [0x%X]\n", | |
1610 | hdr->cmd); | |
1611 | break; | |
1612 | } | |
1613 | } | |
1614 | ||
1615 | /** | |
1616 | * megasas_deplete_reply_queue - Processes all completed commands | |
1617 | * @instance: Adapter soft state | |
1618 | * @alt_status: Alternate status to be returned to | |
1619 | * SCSI mid-layer instead of the status | |
1620 | * returned by the FW | |
1621 | */ | |
858119e1 | 1622 | static int |
c4a3e0a5 BS |
1623 | megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status) |
1624 | { | |
c4a3e0a5 BS |
1625 | /* |
1626 | * Check if it is our interrupt | |
1341c939 | 1627 | * Clear the interrupt |
c4a3e0a5 | 1628 | */ |
1341c939 | 1629 | if(instance->instancet->clear_intr(instance->reg_set)) |
c4a3e0a5 | 1630 | return IRQ_NONE; |
c4a3e0a5 | 1631 | |
af37acfb SP |
1632 | if (instance->hw_crit_error) |
1633 | goto out_done; | |
5d018ad0 SP |
1634 | /* |
1635 | * Schedule the tasklet for cmd completion | |
1636 | */ | |
1637 | tasklet_schedule(&instance->isr_tasklet); | |
af37acfb | 1638 | out_done: |
c4a3e0a5 BS |
1639 | return IRQ_HANDLED; |
1640 | } | |
1641 | ||
1642 | /** | |
1643 | * megasas_isr - isr entry point | |
1644 | */ | |
7d12e780 | 1645 | static irqreturn_t megasas_isr(int irq, void *devp) |
c4a3e0a5 BS |
1646 | { |
1647 | return megasas_deplete_reply_queue((struct megasas_instance *)devp, | |
1648 | DID_OK); | |
1649 | } | |
1650 | ||
1651 | /** | |
1652 | * megasas_transition_to_ready - Move the FW to READY state | |
1341c939 | 1653 | * @instance: Adapter soft state |
c4a3e0a5 BS |
1654 | * |
1655 | * During the initialization, FW passes can potentially be in any one of | |
1656 | * several possible states. If the FW in operational, waiting-for-handshake | |
1657 | * states, driver must take steps to bring it to ready state. Otherwise, it | |
1658 | * has to wait for the ready state. | |
1659 | */ | |
1660 | static int | |
1341c939 | 1661 | megasas_transition_to_ready(struct megasas_instance* instance) |
c4a3e0a5 BS |
1662 | { |
1663 | int i; | |
1664 | u8 max_wait; | |
1665 | u32 fw_state; | |
1666 | u32 cur_state; | |
1667 | ||
1341c939 | 1668 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
c4a3e0a5 | 1669 | |
e3bbff9f SP |
1670 | if (fw_state != MFI_STATE_READY) |
1671 | printk(KERN_INFO "megasas: Waiting for FW to come to ready" | |
1672 | " state\n"); | |
1673 | ||
c4a3e0a5 BS |
1674 | while (fw_state != MFI_STATE_READY) { |
1675 | ||
c4a3e0a5 BS |
1676 | switch (fw_state) { |
1677 | ||
1678 | case MFI_STATE_FAULT: | |
1679 | ||
1680 | printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); | |
1681 | return -ENODEV; | |
1682 | ||
1683 | case MFI_STATE_WAIT_HANDSHAKE: | |
1684 | /* | |
1685 | * Set the CLR bit in inbound doorbell | |
1686 | */ | |
87911122 YB |
1687 | if ((instance->pdev->device == \ |
1688 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || | |
1689 | (instance->pdev->device == | |
1690 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { | |
1691 | ||
1692 | writel( | |
1693 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, | |
1694 | &instance->reg_set->reserved_0[0]); | |
1695 | } else { | |
1696 | writel( | |
1697 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, | |
1698 | &instance->reg_set->inbound_doorbell); | |
1699 | } | |
c4a3e0a5 BS |
1700 | |
1701 | max_wait = 2; | |
1702 | cur_state = MFI_STATE_WAIT_HANDSHAKE; | |
1703 | break; | |
1704 | ||
e3bbff9f | 1705 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
87911122 YB |
1706 | if ((instance->pdev->device == |
1707 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || | |
1708 | (instance->pdev->device == | |
1709 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { | |
1710 | writel(MFI_INIT_HOTPLUG, | |
1711 | &instance->reg_set->reserved_0[0]); | |
1712 | } else | |
1713 | writel(MFI_INIT_HOTPLUG, | |
1714 | &instance->reg_set->inbound_doorbell); | |
e3bbff9f SP |
1715 | |
1716 | max_wait = 10; | |
1717 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; | |
1718 | break; | |
1719 | ||
c4a3e0a5 BS |
1720 | case MFI_STATE_OPERATIONAL: |
1721 | /* | |
e3bbff9f | 1722 | * Bring it to READY state; assuming max wait 10 secs |
c4a3e0a5 | 1723 | */ |
b274cab7 | 1724 | instance->instancet->disable_intr(instance->reg_set); |
87911122 YB |
1725 | if ((instance->pdev->device == |
1726 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || | |
1727 | (instance->pdev->device == | |
1728 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { | |
1729 | writel(MFI_RESET_FLAGS, | |
1730 | &instance->reg_set->reserved_0[0]); | |
1731 | } else | |
1732 | writel(MFI_RESET_FLAGS, | |
1733 | &instance->reg_set->inbound_doorbell); | |
c4a3e0a5 | 1734 | |
af7a5647 | 1735 | max_wait = 60; |
c4a3e0a5 BS |
1736 | cur_state = MFI_STATE_OPERATIONAL; |
1737 | break; | |
1738 | ||
1739 | case MFI_STATE_UNDEFINED: | |
1740 | /* | |
1741 | * This state should not last for more than 2 seconds | |
1742 | */ | |
1743 | max_wait = 2; | |
1744 | cur_state = MFI_STATE_UNDEFINED; | |
1745 | break; | |
1746 | ||
1747 | case MFI_STATE_BB_INIT: | |
1748 | max_wait = 2; | |
1749 | cur_state = MFI_STATE_BB_INIT; | |
1750 | break; | |
1751 | ||
1752 | case MFI_STATE_FW_INIT: | |
1753 | max_wait = 20; | |
1754 | cur_state = MFI_STATE_FW_INIT; | |
1755 | break; | |
1756 | ||
1757 | case MFI_STATE_FW_INIT_2: | |
1758 | max_wait = 20; | |
1759 | cur_state = MFI_STATE_FW_INIT_2; | |
1760 | break; | |
1761 | ||
1762 | case MFI_STATE_DEVICE_SCAN: | |
1763 | max_wait = 20; | |
1764 | cur_state = MFI_STATE_DEVICE_SCAN; | |
1765 | break; | |
1766 | ||
1767 | case MFI_STATE_FLUSH_CACHE: | |
1768 | max_wait = 20; | |
1769 | cur_state = MFI_STATE_FLUSH_CACHE; | |
1770 | break; | |
1771 | ||
1772 | default: | |
1773 | printk(KERN_DEBUG "megasas: Unknown state 0x%x\n", | |
1774 | fw_state); | |
1775 | return -ENODEV; | |
1776 | } | |
1777 | ||
1778 | /* | |
1779 | * The cur_state should not last for more than max_wait secs | |
1780 | */ | |
1781 | for (i = 0; i < (max_wait * 1000); i++) { | |
1341c939 SP |
1782 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & |
1783 | MFI_STATE_MASK ; | |
c4a3e0a5 BS |
1784 | |
1785 | if (fw_state == cur_state) { | |
1786 | msleep(1); | |
1787 | } else | |
1788 | break; | |
1789 | } | |
1790 | ||
1791 | /* | |
1792 | * Return error if fw_state hasn't changed after max_wait | |
1793 | */ | |
1794 | if (fw_state == cur_state) { | |
1795 | printk(KERN_DEBUG "FW state [%d] hasn't changed " | |
1796 | "in %d secs\n", fw_state, max_wait); | |
1797 | return -ENODEV; | |
1798 | } | |
1799 | }; | |
e3bbff9f | 1800 | printk(KERN_INFO "megasas: FW now in Ready state\n"); |
c4a3e0a5 BS |
1801 | |
1802 | return 0; | |
1803 | } | |
1804 | ||
1805 | /** | |
1806 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool | |
1807 | * @instance: Adapter soft state | |
1808 | */ | |
1809 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) | |
1810 | { | |
1811 | int i; | |
1812 | u32 max_cmd = instance->max_fw_cmds; | |
1813 | struct megasas_cmd *cmd; | |
1814 | ||
1815 | if (!instance->frame_dma_pool) | |
1816 | return; | |
1817 | ||
1818 | /* | |
1819 | * Return all frames to pool | |
1820 | */ | |
1821 | for (i = 0; i < max_cmd; i++) { | |
1822 | ||
1823 | cmd = instance->cmd_list[i]; | |
1824 | ||
1825 | if (cmd->frame) | |
1826 | pci_pool_free(instance->frame_dma_pool, cmd->frame, | |
1827 | cmd->frame_phys_addr); | |
1828 | ||
1829 | if (cmd->sense) | |
e3bbff9f | 1830 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
c4a3e0a5 BS |
1831 | cmd->sense_phys_addr); |
1832 | } | |
1833 | ||
1834 | /* | |
1835 | * Now destroy the pool itself | |
1836 | */ | |
1837 | pci_pool_destroy(instance->frame_dma_pool); | |
1838 | pci_pool_destroy(instance->sense_dma_pool); | |
1839 | ||
1840 | instance->frame_dma_pool = NULL; | |
1841 | instance->sense_dma_pool = NULL; | |
1842 | } | |
1843 | ||
1844 | /** | |
1845 | * megasas_create_frame_pool - Creates DMA pool for cmd frames | |
1846 | * @instance: Adapter soft state | |
1847 | * | |
1848 | * Each command packet has an embedded DMA memory buffer that is used for | |
1849 | * filling MFI frame and the SG list that immediately follows the frame. This | |
1850 | * function creates those DMA memory buffers for each command packet by using | |
1851 | * PCI pool facility. | |
1852 | */ | |
1853 | static int megasas_create_frame_pool(struct megasas_instance *instance) | |
1854 | { | |
1855 | int i; | |
1856 | u32 max_cmd; | |
1857 | u32 sge_sz; | |
1858 | u32 sgl_sz; | |
1859 | u32 total_sz; | |
1860 | u32 frame_count; | |
1861 | struct megasas_cmd *cmd; | |
1862 | ||
1863 | max_cmd = instance->max_fw_cmds; | |
1864 | ||
1865 | /* | |
1866 | * Size of our frame is 64 bytes for MFI frame, followed by max SG | |
1867 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer | |
1868 | */ | |
1869 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : | |
1870 | sizeof(struct megasas_sge32); | |
1871 | ||
1872 | /* | |
1873 | * Calculated the number of 64byte frames required for SGL | |
1874 | */ | |
1875 | sgl_sz = sge_sz * instance->max_num_sge; | |
1876 | frame_count = (sgl_sz + MEGAMFI_FRAME_SIZE - 1) / MEGAMFI_FRAME_SIZE; | |
1877 | ||
1878 | /* | |
1879 | * We need one extra frame for the MFI command | |
1880 | */ | |
1881 | frame_count++; | |
1882 | ||
1883 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; | |
1884 | /* | |
1885 | * Use DMA pool facility provided by PCI layer | |
1886 | */ | |
1887 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", | |
1888 | instance->pdev, total_sz, 64, | |
1889 | 0); | |
1890 | ||
1891 | if (!instance->frame_dma_pool) { | |
1892 | printk(KERN_DEBUG "megasas: failed to setup frame pool\n"); | |
1893 | return -ENOMEM; | |
1894 | } | |
1895 | ||
1896 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", | |
1897 | instance->pdev, 128, 4, 0); | |
1898 | ||
1899 | if (!instance->sense_dma_pool) { | |
1900 | printk(KERN_DEBUG "megasas: failed to setup sense pool\n"); | |
1901 | ||
1902 | pci_pool_destroy(instance->frame_dma_pool); | |
1903 | instance->frame_dma_pool = NULL; | |
1904 | ||
1905 | return -ENOMEM; | |
1906 | } | |
1907 | ||
1908 | /* | |
1909 | * Allocate and attach a frame to each of the commands in cmd_list. | |
1910 | * By making cmd->index as the context instead of the &cmd, we can | |
1911 | * always use 32bit context regardless of the architecture | |
1912 | */ | |
1913 | for (i = 0; i < max_cmd; i++) { | |
1914 | ||
1915 | cmd = instance->cmd_list[i]; | |
1916 | ||
1917 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, | |
1918 | GFP_KERNEL, &cmd->frame_phys_addr); | |
1919 | ||
1920 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, | |
1921 | GFP_KERNEL, &cmd->sense_phys_addr); | |
1922 | ||
1923 | /* | |
1924 | * megasas_teardown_frame_pool() takes care of freeing | |
1925 | * whatever has been allocated | |
1926 | */ | |
1927 | if (!cmd->frame || !cmd->sense) { | |
1928 | printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n"); | |
1929 | megasas_teardown_frame_pool(instance); | |
1930 | return -ENOMEM; | |
1931 | } | |
1932 | ||
1933 | cmd->frame->io.context = cmd->index; | |
1934 | } | |
1935 | ||
1936 | return 0; | |
1937 | } | |
1938 | ||
1939 | /** | |
1940 | * megasas_free_cmds - Free all the cmds in the free cmd pool | |
1941 | * @instance: Adapter soft state | |
1942 | */ | |
1943 | static void megasas_free_cmds(struct megasas_instance *instance) | |
1944 | { | |
1945 | int i; | |
1946 | /* First free the MFI frame pool */ | |
1947 | megasas_teardown_frame_pool(instance); | |
1948 | ||
1949 | /* Free all the commands in the cmd_list */ | |
1950 | for (i = 0; i < instance->max_fw_cmds; i++) | |
1951 | kfree(instance->cmd_list[i]); | |
1952 | ||
1953 | /* Free the cmd_list buffer itself */ | |
1954 | kfree(instance->cmd_list); | |
1955 | instance->cmd_list = NULL; | |
1956 | ||
1957 | INIT_LIST_HEAD(&instance->cmd_pool); | |
1958 | } | |
1959 | ||
1960 | /** | |
1961 | * megasas_alloc_cmds - Allocates the command packets | |
1962 | * @instance: Adapter soft state | |
1963 | * | |
1964 | * Each command that is issued to the FW, whether IO commands from the OS or | |
1965 | * internal commands like IOCTLs, are wrapped in local data structure called | |
1966 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to | |
1967 | * the FW. | |
1968 | * | |
1969 | * Each frame has a 32-bit field called context (tag). This context is used | |
1970 | * to get back the megasas_cmd from the frame when a frame gets completed in | |
1971 | * the ISR. Typically the address of the megasas_cmd itself would be used as | |
1972 | * the context. But we wanted to keep the differences between 32 and 64 bit | |
1973 | * systems to the mininum. We always use 32 bit integers for the context. In | |
1974 | * this driver, the 32 bit values are the indices into an array cmd_list. | |
1975 | * This array is used only to look up the megasas_cmd given the context. The | |
1976 | * free commands themselves are maintained in a linked list called cmd_pool. | |
1977 | */ | |
1978 | static int megasas_alloc_cmds(struct megasas_instance *instance) | |
1979 | { | |
1980 | int i; | |
1981 | int j; | |
1982 | u32 max_cmd; | |
1983 | struct megasas_cmd *cmd; | |
1984 | ||
1985 | max_cmd = instance->max_fw_cmds; | |
1986 | ||
1987 | /* | |
1988 | * instance->cmd_list is an array of struct megasas_cmd pointers. | |
1989 | * Allocate the dynamic array first and then allocate individual | |
1990 | * commands. | |
1991 | */ | |
dd00cc48 | 1992 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
c4a3e0a5 BS |
1993 | |
1994 | if (!instance->cmd_list) { | |
1995 | printk(KERN_DEBUG "megasas: out of memory\n"); | |
1996 | return -ENOMEM; | |
1997 | } | |
1998 | ||
c4a3e0a5 BS |
1999 | |
2000 | for (i = 0; i < max_cmd; i++) { | |
2001 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), | |
2002 | GFP_KERNEL); | |
2003 | ||
2004 | if (!instance->cmd_list[i]) { | |
2005 | ||
2006 | for (j = 0; j < i; j++) | |
2007 | kfree(instance->cmd_list[j]); | |
2008 | ||
2009 | kfree(instance->cmd_list); | |
2010 | instance->cmd_list = NULL; | |
2011 | ||
2012 | return -ENOMEM; | |
2013 | } | |
2014 | } | |
2015 | ||
2016 | /* | |
2017 | * Add all the commands to command pool (instance->cmd_pool) | |
2018 | */ | |
2019 | for (i = 0; i < max_cmd; i++) { | |
2020 | cmd = instance->cmd_list[i]; | |
2021 | memset(cmd, 0, sizeof(struct megasas_cmd)); | |
2022 | cmd->index = i; | |
2023 | cmd->instance = instance; | |
2024 | ||
2025 | list_add_tail(&cmd->list, &instance->cmd_pool); | |
2026 | } | |
2027 | ||
2028 | /* | |
2029 | * Create a frame pool and assign one frame to each cmd | |
2030 | */ | |
2031 | if (megasas_create_frame_pool(instance)) { | |
2032 | printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n"); | |
2033 | megasas_free_cmds(instance); | |
2034 | } | |
2035 | ||
2036 | return 0; | |
2037 | } | |
2038 | ||
2039 | /** | |
2040 | * megasas_get_controller_info - Returns FW's controller structure | |
2041 | * @instance: Adapter soft state | |
2042 | * @ctrl_info: Controller information structure | |
2043 | * | |
2044 | * Issues an internal command (DCMD) to get the FW's controller structure. | |
2045 | * This information is mainly used to find out the maximum IO transfer per | |
2046 | * command supported by the FW. | |
2047 | */ | |
2048 | static int | |
2049 | megasas_get_ctrl_info(struct megasas_instance *instance, | |
2050 | struct megasas_ctrl_info *ctrl_info) | |
2051 | { | |
2052 | int ret = 0; | |
2053 | struct megasas_cmd *cmd; | |
2054 | struct megasas_dcmd_frame *dcmd; | |
2055 | struct megasas_ctrl_info *ci; | |
2056 | dma_addr_t ci_h = 0; | |
2057 | ||
2058 | cmd = megasas_get_cmd(instance); | |
2059 | ||
2060 | if (!cmd) { | |
2061 | printk(KERN_DEBUG "megasas: Failed to get a free cmd\n"); | |
2062 | return -ENOMEM; | |
2063 | } | |
2064 | ||
2065 | dcmd = &cmd->frame->dcmd; | |
2066 | ||
2067 | ci = pci_alloc_consistent(instance->pdev, | |
2068 | sizeof(struct megasas_ctrl_info), &ci_h); | |
2069 | ||
2070 | if (!ci) { | |
2071 | printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n"); | |
2072 | megasas_return_cmd(instance, cmd); | |
2073 | return -ENOMEM; | |
2074 | } | |
2075 | ||
2076 | memset(ci, 0, sizeof(*ci)); | |
2077 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
2078 | ||
2079 | dcmd->cmd = MFI_CMD_DCMD; | |
2080 | dcmd->cmd_status = 0xFF; | |
2081 | dcmd->sge_count = 1; | |
2082 | dcmd->flags = MFI_FRAME_DIR_READ; | |
2083 | dcmd->timeout = 0; | |
2084 | dcmd->data_xfer_len = sizeof(struct megasas_ctrl_info); | |
2085 | dcmd->opcode = MR_DCMD_CTRL_GET_INFO; | |
2086 | dcmd->sgl.sge32[0].phys_addr = ci_h; | |
2087 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_ctrl_info); | |
2088 | ||
2089 | if (!megasas_issue_polled(instance, cmd)) { | |
2090 | ret = 0; | |
2091 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); | |
2092 | } else { | |
2093 | ret = -1; | |
2094 | } | |
2095 | ||
2096 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), | |
2097 | ci, ci_h); | |
2098 | ||
2099 | megasas_return_cmd(instance, cmd); | |
2100 | return ret; | |
2101 | } | |
2102 | ||
31ea7088 | 2103 | /** |
2104 | * megasas_issue_init_mfi - Initializes the FW | |
2105 | * @instance: Adapter soft state | |
2106 | * | |
2107 | * Issues the INIT MFI cmd | |
2108 | */ | |
2109 | static int | |
2110 | megasas_issue_init_mfi(struct megasas_instance *instance) | |
2111 | { | |
2112 | u32 context; | |
2113 | ||
2114 | struct megasas_cmd *cmd; | |
2115 | ||
2116 | struct megasas_init_frame *init_frame; | |
2117 | struct megasas_init_queue_info *initq_info; | |
2118 | dma_addr_t init_frame_h; | |
2119 | dma_addr_t initq_info_h; | |
2120 | ||
2121 | /* | |
2122 | * Prepare a init frame. Note the init frame points to queue info | |
2123 | * structure. Each frame has SGL allocated after first 64 bytes. For | |
2124 | * this frame - since we don't need any SGL - we use SGL's space as | |
2125 | * queue info structure | |
2126 | * | |
2127 | * We will not get a NULL command below. We just created the pool. | |
2128 | */ | |
2129 | cmd = megasas_get_cmd(instance); | |
2130 | ||
2131 | init_frame = (struct megasas_init_frame *)cmd->frame; | |
2132 | initq_info = (struct megasas_init_queue_info *) | |
2133 | ((unsigned long)init_frame + 64); | |
2134 | ||
2135 | init_frame_h = cmd->frame_phys_addr; | |
2136 | initq_info_h = init_frame_h + 64; | |
2137 | ||
2138 | context = init_frame->context; | |
2139 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); | |
2140 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); | |
2141 | init_frame->context = context; | |
2142 | ||
2143 | initq_info->reply_queue_entries = instance->max_fw_cmds + 1; | |
2144 | initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h; | |
2145 | ||
2146 | initq_info->producer_index_phys_addr_lo = instance->producer_h; | |
2147 | initq_info->consumer_index_phys_addr_lo = instance->consumer_h; | |
2148 | ||
2149 | init_frame->cmd = MFI_CMD_INIT; | |
2150 | init_frame->cmd_status = 0xFF; | |
2151 | init_frame->queue_info_new_phys_addr_lo = initq_info_h; | |
2152 | ||
2153 | init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info); | |
2154 | ||
2155 | /* | |
2156 | * disable the intr before firing the init frame to FW | |
2157 | */ | |
2158 | instance->instancet->disable_intr(instance->reg_set); | |
2159 | ||
2160 | /* | |
2161 | * Issue the init frame in polled mode | |
2162 | */ | |
2163 | ||
2164 | if (megasas_issue_polled(instance, cmd)) { | |
2165 | printk(KERN_ERR "megasas: Failed to init firmware\n"); | |
2166 | megasas_return_cmd(instance, cmd); | |
2167 | goto fail_fw_init; | |
2168 | } | |
2169 | ||
2170 | megasas_return_cmd(instance, cmd); | |
2171 | ||
2172 | return 0; | |
2173 | ||
2174 | fail_fw_init: | |
2175 | return -EINVAL; | |
2176 | } | |
2177 | ||
ad84db2e | 2178 | /** |
2179 | * megasas_start_timer - Initializes a timer object | |
2180 | * @instance: Adapter soft state | |
2181 | * @timer: timer object to be initialized | |
2182 | * @fn: timer function | |
2183 | * @interval: time interval between timer function call | |
2184 | */ | |
2185 | static inline void | |
2186 | megasas_start_timer(struct megasas_instance *instance, | |
2187 | struct timer_list *timer, | |
2188 | void *fn, unsigned long interval) | |
2189 | { | |
2190 | init_timer(timer); | |
2191 | timer->expires = jiffies + interval; | |
2192 | timer->data = (unsigned long)instance; | |
2193 | timer->function = fn; | |
2194 | add_timer(timer); | |
2195 | } | |
2196 | ||
2197 | /** | |
2198 | * megasas_io_completion_timer - Timer fn | |
2199 | * @instance_addr: Address of adapter soft state | |
2200 | * | |
2201 | * Schedules tasklet for cmd completion | |
2202 | * if poll_mode_io is set | |
2203 | */ | |
2204 | static void | |
2205 | megasas_io_completion_timer(unsigned long instance_addr) | |
2206 | { | |
2207 | struct megasas_instance *instance = | |
2208 | (struct megasas_instance *)instance_addr; | |
2209 | ||
2210 | if (atomic_read(&instance->fw_outstanding)) | |
2211 | tasklet_schedule(&instance->isr_tasklet); | |
2212 | ||
2213 | /* Restart timer */ | |
2214 | if (poll_mode_io) | |
2215 | mod_timer(&instance->io_completion_timer, | |
2216 | jiffies + MEGASAS_COMPLETION_TIMER_INTERVAL); | |
2217 | } | |
2218 | ||
c4a3e0a5 BS |
2219 | /** |
2220 | * megasas_init_mfi - Initializes the FW | |
2221 | * @instance: Adapter soft state | |
2222 | * | |
2223 | * This is the main function for initializing MFI firmware. | |
2224 | */ | |
2225 | static int megasas_init_mfi(struct megasas_instance *instance) | |
2226 | { | |
2227 | u32 context_sz; | |
2228 | u32 reply_q_sz; | |
2229 | u32 max_sectors_1; | |
2230 | u32 max_sectors_2; | |
14faea9f | 2231 | u32 tmp_sectors; |
c4a3e0a5 | 2232 | struct megasas_register_set __iomem *reg_set; |
c4a3e0a5 | 2233 | struct megasas_ctrl_info *ctrl_info; |
c4a3e0a5 BS |
2234 | /* |
2235 | * Map the message registers | |
2236 | */ | |
6610a6b3 | 2237 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
87911122 YB |
2238 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
2239 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || | |
6610a6b3 YB |
2240 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0079GEN2)) { |
2241 | instance->base_addr = pci_resource_start(instance->pdev, 1); | |
2242 | } else { | |
2243 | instance->base_addr = pci_resource_start(instance->pdev, 0); | |
2244 | } | |
c4a3e0a5 | 2245 | |
f28cd7cf | 2246 | if (pci_request_regions(instance->pdev, "megasas: LSI")) { |
c4a3e0a5 BS |
2247 | printk(KERN_DEBUG "megasas: IO memory region busy!\n"); |
2248 | return -EBUSY; | |
2249 | } | |
2250 | ||
2251 | instance->reg_set = ioremap_nocache(instance->base_addr, 8192); | |
2252 | ||
2253 | if (!instance->reg_set) { | |
2254 | printk(KERN_DEBUG "megasas: Failed to map IO mem\n"); | |
2255 | goto fail_ioremap; | |
2256 | } | |
2257 | ||
2258 | reg_set = instance->reg_set; | |
2259 | ||
f9876f0b SP |
2260 | switch(instance->pdev->device) |
2261 | { | |
af7a5647 | 2262 | case PCI_DEVICE_ID_LSI_SAS1078R: |
2263 | case PCI_DEVICE_ID_LSI_SAS1078DE: | |
f9876f0b SP |
2264 | instance->instancet = &megasas_instance_template_ppc; |
2265 | break; | |
6610a6b3 YB |
2266 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
2267 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: | |
2268 | instance->instancet = &megasas_instance_template_gen2; | |
2269 | break; | |
87911122 YB |
2270 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
2271 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: | |
2272 | instance->instancet = &megasas_instance_template_skinny; | |
2273 | break; | |
f9876f0b SP |
2274 | case PCI_DEVICE_ID_LSI_SAS1064R: |
2275 | case PCI_DEVICE_ID_DELL_PERC5: | |
2276 | default: | |
2277 | instance->instancet = &megasas_instance_template_xscale; | |
2278 | break; | |
2279 | } | |
1341c939 | 2280 | |
c4a3e0a5 BS |
2281 | /* |
2282 | * We expect the FW state to be READY | |
2283 | */ | |
1341c939 | 2284 | if (megasas_transition_to_ready(instance)) |
c4a3e0a5 BS |
2285 | goto fail_ready_state; |
2286 | ||
2287 | /* | |
2288 | * Get various operational parameters from status register | |
2289 | */ | |
1341c939 | 2290 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
e3bbff9f SP |
2291 | /* |
2292 | * Reduce the max supported cmds by 1. This is to ensure that the | |
2293 | * reply_q_sz (1 more than the max cmd that driver may send) | |
2294 | * does not exceed max cmds that the FW can support | |
2295 | */ | |
2296 | instance->max_fw_cmds = instance->max_fw_cmds-1; | |
1341c939 SP |
2297 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >> |
2298 | 0x10; | |
c4a3e0a5 BS |
2299 | /* |
2300 | * Create a pool of commands | |
2301 | */ | |
2302 | if (megasas_alloc_cmds(instance)) | |
2303 | goto fail_alloc_cmds; | |
2304 | ||
2305 | /* | |
2306 | * Allocate memory for reply queue. Length of reply queue should | |
2307 | * be _one_ more than the maximum commands handled by the firmware. | |
2308 | * | |
2309 | * Note: When FW completes commands, it places corresponding contex | |
2310 | * values in this circular reply queue. This circular queue is a fairly | |
2311 | * typical producer-consumer queue. FW is the producer (of completed | |
2312 | * commands) and the driver is the consumer. | |
2313 | */ | |
2314 | context_sz = sizeof(u32); | |
2315 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); | |
2316 | ||
2317 | instance->reply_queue = pci_alloc_consistent(instance->pdev, | |
2318 | reply_q_sz, | |
2319 | &instance->reply_queue_h); | |
2320 | ||
2321 | if (!instance->reply_queue) { | |
2322 | printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n"); | |
2323 | goto fail_reply_queue; | |
2324 | } | |
2325 | ||
31ea7088 | 2326 | if (megasas_issue_init_mfi(instance)) |
c4a3e0a5 | 2327 | goto fail_fw_init; |
c4a3e0a5 BS |
2328 | |
2329 | ctrl_info = kmalloc(sizeof(struct megasas_ctrl_info), GFP_KERNEL); | |
2330 | ||
2331 | /* | |
2332 | * Compute the max allowed sectors per IO: The controller info has two | |
2333 | * limits on max sectors. Driver should use the minimum of these two. | |
2334 | * | |
2335 | * 1 << stripe_sz_ops.min = max sectors per strip | |
2336 | * | |
2337 | * Note that older firmwares ( < FW ver 30) didn't report information | |
2338 | * to calculate max_sectors_1. So the number ended up as zero always. | |
2339 | */ | |
14faea9f | 2340 | tmp_sectors = 0; |
c4a3e0a5 BS |
2341 | if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) { |
2342 | ||
2343 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * | |
2344 | ctrl_info->max_strips_per_io; | |
2345 | max_sectors_2 = ctrl_info->max_request_size; | |
2346 | ||
14faea9f | 2347 | tmp_sectors = min_t(u32, max_sectors_1 , max_sectors_2); |
2348 | } | |
2349 | ||
2350 | instance->max_sectors_per_req = instance->max_num_sge * | |
2351 | PAGE_SIZE / 512; | |
2352 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) | |
2353 | instance->max_sectors_per_req = tmp_sectors; | |
c4a3e0a5 BS |
2354 | |
2355 | kfree(ctrl_info); | |
2356 | ||
5d018ad0 SP |
2357 | /* |
2358 | * Setup tasklet for cmd completion | |
2359 | */ | |
2360 | ||
ad84db2e | 2361 | tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc, |
2362 | (unsigned long)instance); | |
2363 | ||
2364 | /* Initialize the cmd completion timer */ | |
2365 | if (poll_mode_io) | |
2366 | megasas_start_timer(instance, &instance->io_completion_timer, | |
2367 | megasas_io_completion_timer, | |
2368 | MEGASAS_COMPLETION_TIMER_INTERVAL); | |
c4a3e0a5 BS |
2369 | return 0; |
2370 | ||
2371 | fail_fw_init: | |
c4a3e0a5 BS |
2372 | |
2373 | pci_free_consistent(instance->pdev, reply_q_sz, | |
2374 | instance->reply_queue, instance->reply_queue_h); | |
2375 | fail_reply_queue: | |
2376 | megasas_free_cmds(instance); | |
2377 | ||
2378 | fail_alloc_cmds: | |
2379 | fail_ready_state: | |
2380 | iounmap(instance->reg_set); | |
2381 | ||
2382 | fail_ioremap: | |
2383 | pci_release_regions(instance->pdev); | |
2384 | ||
2385 | return -EINVAL; | |
2386 | } | |
2387 | ||
2388 | /** | |
2389 | * megasas_release_mfi - Reverses the FW initialization | |
2390 | * @intance: Adapter soft state | |
2391 | */ | |
2392 | static void megasas_release_mfi(struct megasas_instance *instance) | |
2393 | { | |
2394 | u32 reply_q_sz = sizeof(u32) * (instance->max_fw_cmds + 1); | |
2395 | ||
2396 | pci_free_consistent(instance->pdev, reply_q_sz, | |
2397 | instance->reply_queue, instance->reply_queue_h); | |
2398 | ||
2399 | megasas_free_cmds(instance); | |
2400 | ||
2401 | iounmap(instance->reg_set); | |
2402 | ||
2403 | pci_release_regions(instance->pdev); | |
2404 | } | |
2405 | ||
2406 | /** | |
2407 | * megasas_get_seq_num - Gets latest event sequence numbers | |
2408 | * @instance: Adapter soft state | |
2409 | * @eli: FW event log sequence numbers information | |
2410 | * | |
2411 | * FW maintains a log of all events in a non-volatile area. Upper layers would | |
2412 | * usually find out the latest sequence number of the events, the seq number at | |
2413 | * the boot etc. They would "read" all the events below the latest seq number | |
2414 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq | |
2415 | * number), they would subsribe to AEN (asynchronous event notification) and | |
2416 | * wait for the events to happen. | |
2417 | */ | |
2418 | static int | |
2419 | megasas_get_seq_num(struct megasas_instance *instance, | |
2420 | struct megasas_evt_log_info *eli) | |
2421 | { | |
2422 | struct megasas_cmd *cmd; | |
2423 | struct megasas_dcmd_frame *dcmd; | |
2424 | struct megasas_evt_log_info *el_info; | |
2425 | dma_addr_t el_info_h = 0; | |
2426 | ||
2427 | cmd = megasas_get_cmd(instance); | |
2428 | ||
2429 | if (!cmd) { | |
2430 | return -ENOMEM; | |
2431 | } | |
2432 | ||
2433 | dcmd = &cmd->frame->dcmd; | |
2434 | el_info = pci_alloc_consistent(instance->pdev, | |
2435 | sizeof(struct megasas_evt_log_info), | |
2436 | &el_info_h); | |
2437 | ||
2438 | if (!el_info) { | |
2439 | megasas_return_cmd(instance, cmd); | |
2440 | return -ENOMEM; | |
2441 | } | |
2442 | ||
2443 | memset(el_info, 0, sizeof(*el_info)); | |
2444 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
2445 | ||
2446 | dcmd->cmd = MFI_CMD_DCMD; | |
2447 | dcmd->cmd_status = 0x0; | |
2448 | dcmd->sge_count = 1; | |
2449 | dcmd->flags = MFI_FRAME_DIR_READ; | |
2450 | dcmd->timeout = 0; | |
2451 | dcmd->data_xfer_len = sizeof(struct megasas_evt_log_info); | |
2452 | dcmd->opcode = MR_DCMD_CTRL_EVENT_GET_INFO; | |
2453 | dcmd->sgl.sge32[0].phys_addr = el_info_h; | |
2454 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_log_info); | |
2455 | ||
2456 | megasas_issue_blocked_cmd(instance, cmd); | |
2457 | ||
2458 | /* | |
2459 | * Copy the data back into callers buffer | |
2460 | */ | |
2461 | memcpy(eli, el_info, sizeof(struct megasas_evt_log_info)); | |
2462 | ||
2463 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), | |
2464 | el_info, el_info_h); | |
2465 | ||
2466 | megasas_return_cmd(instance, cmd); | |
2467 | ||
2468 | return 0; | |
2469 | } | |
2470 | ||
2471 | /** | |
2472 | * megasas_register_aen - Registers for asynchronous event notification | |
2473 | * @instance: Adapter soft state | |
2474 | * @seq_num: The starting sequence number | |
2475 | * @class_locale: Class of the event | |
2476 | * | |
2477 | * This function subscribes for AEN for events beyond the @seq_num. It requests | |
2478 | * to be notified if and only if the event is of type @class_locale | |
2479 | */ | |
2480 | static int | |
2481 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, | |
2482 | u32 class_locale_word) | |
2483 | { | |
2484 | int ret_val; | |
2485 | struct megasas_cmd *cmd; | |
2486 | struct megasas_dcmd_frame *dcmd; | |
2487 | union megasas_evt_class_locale curr_aen; | |
2488 | union megasas_evt_class_locale prev_aen; | |
2489 | ||
2490 | /* | |
2491 | * If there an AEN pending already (aen_cmd), check if the | |
2492 | * class_locale of that pending AEN is inclusive of the new | |
2493 | * AEN request we currently have. If it is, then we don't have | |
2494 | * to do anything. In other words, whichever events the current | |
2495 | * AEN request is subscribing to, have already been subscribed | |
2496 | * to. | |
2497 | * | |
2498 | * If the old_cmd is _not_ inclusive, then we have to abort | |
2499 | * that command, form a class_locale that is superset of both | |
2500 | * old and current and re-issue to the FW | |
2501 | */ | |
2502 | ||
2503 | curr_aen.word = class_locale_word; | |
2504 | ||
2505 | if (instance->aen_cmd) { | |
2506 | ||
2507 | prev_aen.word = instance->aen_cmd->frame->dcmd.mbox.w[1]; | |
2508 | ||
2509 | /* | |
2510 | * A class whose enum value is smaller is inclusive of all | |
2511 | * higher values. If a PROGRESS (= -1) was previously | |
2512 | * registered, then a new registration requests for higher | |
2513 | * classes need not be sent to FW. They are automatically | |
2514 | * included. | |
2515 | * | |
2516 | * Locale numbers don't have such hierarchy. They are bitmap | |
2517 | * values | |
2518 | */ | |
2519 | if ((prev_aen.members.class <= curr_aen.members.class) && | |
2520 | !((prev_aen.members.locale & curr_aen.members.locale) ^ | |
2521 | curr_aen.members.locale)) { | |
2522 | /* | |
2523 | * Previously issued event registration includes | |
2524 | * current request. Nothing to do. | |
2525 | */ | |
2526 | return 0; | |
2527 | } else { | |
2528 | curr_aen.members.locale |= prev_aen.members.locale; | |
2529 | ||
2530 | if (prev_aen.members.class < curr_aen.members.class) | |
2531 | curr_aen.members.class = prev_aen.members.class; | |
2532 | ||
2533 | instance->aen_cmd->abort_aen = 1; | |
2534 | ret_val = megasas_issue_blocked_abort_cmd(instance, | |
2535 | instance-> | |
2536 | aen_cmd); | |
2537 | ||
2538 | if (ret_val) { | |
2539 | printk(KERN_DEBUG "megasas: Failed to abort " | |
2540 | "previous AEN command\n"); | |
2541 | return ret_val; | |
2542 | } | |
2543 | } | |
2544 | } | |
2545 | ||
2546 | cmd = megasas_get_cmd(instance); | |
2547 | ||
2548 | if (!cmd) | |
2549 | return -ENOMEM; | |
2550 | ||
2551 | dcmd = &cmd->frame->dcmd; | |
2552 | ||
2553 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); | |
2554 | ||
2555 | /* | |
2556 | * Prepare DCMD for aen registration | |
2557 | */ | |
2558 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
2559 | ||
2560 | dcmd->cmd = MFI_CMD_DCMD; | |
2561 | dcmd->cmd_status = 0x0; | |
2562 | dcmd->sge_count = 1; | |
2563 | dcmd->flags = MFI_FRAME_DIR_READ; | |
2564 | dcmd->timeout = 0; | |
2565 | dcmd->data_xfer_len = sizeof(struct megasas_evt_detail); | |
2566 | dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT; | |
2567 | dcmd->mbox.w[0] = seq_num; | |
2568 | dcmd->mbox.w[1] = curr_aen.word; | |
2569 | dcmd->sgl.sge32[0].phys_addr = (u32) instance->evt_detail_h; | |
2570 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_detail); | |
2571 | ||
2572 | /* | |
2573 | * Store reference to the cmd used to register for AEN. When an | |
2574 | * application wants us to register for AEN, we have to abort this | |
2575 | * cmd and re-register with a new EVENT LOCALE supplied by that app | |
2576 | */ | |
2577 | instance->aen_cmd = cmd; | |
2578 | ||
2579 | /* | |
2580 | * Issue the aen registration frame | |
2581 | */ | |
1341c939 | 2582 | instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set); |
c4a3e0a5 BS |
2583 | |
2584 | return 0; | |
2585 | } | |
2586 | ||
2587 | /** | |
2588 | * megasas_start_aen - Subscribes to AEN during driver load time | |
2589 | * @instance: Adapter soft state | |
2590 | */ | |
2591 | static int megasas_start_aen(struct megasas_instance *instance) | |
2592 | { | |
2593 | struct megasas_evt_log_info eli; | |
2594 | union megasas_evt_class_locale class_locale; | |
2595 | ||
2596 | /* | |
2597 | * Get the latest sequence number from FW | |
2598 | */ | |
2599 | memset(&eli, 0, sizeof(eli)); | |
2600 | ||
2601 | if (megasas_get_seq_num(instance, &eli)) | |
2602 | return -1; | |
2603 | ||
2604 | /* | |
2605 | * Register AEN with FW for latest sequence number plus 1 | |
2606 | */ | |
2607 | class_locale.members.reserved = 0; | |
2608 | class_locale.members.locale = MR_EVT_LOCALE_ALL; | |
2609 | class_locale.members.class = MR_EVT_CLASS_DEBUG; | |
2610 | ||
2611 | return megasas_register_aen(instance, eli.newest_seq_num + 1, | |
2612 | class_locale.word); | |
2613 | } | |
2614 | ||
2615 | /** | |
2616 | * megasas_io_attach - Attaches this driver to SCSI mid-layer | |
2617 | * @instance: Adapter soft state | |
2618 | */ | |
2619 | static int megasas_io_attach(struct megasas_instance *instance) | |
2620 | { | |
2621 | struct Scsi_Host *host = instance->host; | |
2622 | ||
2623 | /* | |
2624 | * Export parameters required by SCSI mid-layer | |
2625 | */ | |
2626 | host->irq = instance->pdev->irq; | |
2627 | host->unique_id = instance->unique_id; | |
2628 | host->can_queue = instance->max_fw_cmds - MEGASAS_INT_CMDS; | |
2629 | host->this_id = instance->init_id; | |
2630 | host->sg_tablesize = instance->max_num_sge; | |
2631 | host->max_sectors = instance->max_sectors_per_req; | |
2632 | host->cmd_per_lun = 128; | |
2633 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; | |
2634 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; | |
2635 | host->max_lun = MEGASAS_MAX_LUN; | |
122da302 | 2636 | host->max_cmd_len = 16; |
c4a3e0a5 BS |
2637 | |
2638 | /* | |
2639 | * Notify the mid-layer about the new controller | |
2640 | */ | |
2641 | if (scsi_add_host(host, &instance->pdev->dev)) { | |
2642 | printk(KERN_DEBUG "megasas: scsi_add_host failed\n"); | |
2643 | return -ENODEV; | |
2644 | } | |
2645 | ||
2646 | /* | |
2647 | * Trigger SCSI to scan our drives | |
2648 | */ | |
2649 | scsi_scan_host(host); | |
2650 | return 0; | |
2651 | } | |
2652 | ||
31ea7088 | 2653 | static int |
2654 | megasas_set_dma_mask(struct pci_dev *pdev) | |
2655 | { | |
2656 | /* | |
2657 | * All our contollers are capable of performing 64-bit DMA | |
2658 | */ | |
2659 | if (IS_DMA64) { | |
6a35528a | 2660 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
31ea7088 | 2661 | |
284901a9 | 2662 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
31ea7088 | 2663 | goto fail_set_dma_mask; |
2664 | } | |
2665 | } else { | |
284901a9 | 2666 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
31ea7088 | 2667 | goto fail_set_dma_mask; |
2668 | } | |
2669 | return 0; | |
2670 | ||
2671 | fail_set_dma_mask: | |
2672 | return 1; | |
2673 | } | |
2674 | ||
c4a3e0a5 BS |
2675 | /** |
2676 | * megasas_probe_one - PCI hotplug entry point | |
2677 | * @pdev: PCI device structure | |
2678 | * @id: PCI ids of supported hotplugged adapter | |
2679 | */ | |
2680 | static int __devinit | |
2681 | megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | |
2682 | { | |
2683 | int rval; | |
2684 | struct Scsi_Host *host; | |
2685 | struct megasas_instance *instance; | |
2686 | ||
2687 | /* | |
2688 | * Announce PCI information | |
2689 | */ | |
2690 | printk(KERN_INFO "megasas: %#4.04x:%#4.04x:%#4.04x:%#4.04x: ", | |
2691 | pdev->vendor, pdev->device, pdev->subsystem_vendor, | |
2692 | pdev->subsystem_device); | |
2693 | ||
2694 | printk("bus %d:slot %d:func %d\n", | |
2695 | pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); | |
2696 | ||
2697 | /* | |
2698 | * PCI prepping: enable device set bus mastering and dma mask | |
2699 | */ | |
2700 | rval = pci_enable_device(pdev); | |
2701 | ||
2702 | if (rval) { | |
2703 | return rval; | |
2704 | } | |
2705 | ||
2706 | pci_set_master(pdev); | |
2707 | ||
31ea7088 | 2708 | if (megasas_set_dma_mask(pdev)) |
2709 | goto fail_set_dma_mask; | |
c4a3e0a5 BS |
2710 | |
2711 | host = scsi_host_alloc(&megasas_template, | |
2712 | sizeof(struct megasas_instance)); | |
2713 | ||
2714 | if (!host) { | |
2715 | printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n"); | |
2716 | goto fail_alloc_instance; | |
2717 | } | |
2718 | ||
2719 | instance = (struct megasas_instance *)host->hostdata; | |
2720 | memset(instance, 0, sizeof(*instance)); | |
2721 | ||
2722 | instance->producer = pci_alloc_consistent(pdev, sizeof(u32), | |
2723 | &instance->producer_h); | |
2724 | instance->consumer = pci_alloc_consistent(pdev, sizeof(u32), | |
2725 | &instance->consumer_h); | |
2726 | ||
2727 | if (!instance->producer || !instance->consumer) { | |
2728 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " | |
2729 | "producer, consumer\n"); | |
2730 | goto fail_alloc_dma_buf; | |
2731 | } | |
2732 | ||
2733 | *instance->producer = 0; | |
2734 | *instance->consumer = 0; | |
c3518837 | 2735 | megasas_poll_wait_aen = 0; |
c4a3e0a5 BS |
2736 | |
2737 | instance->evt_detail = pci_alloc_consistent(pdev, | |
2738 | sizeof(struct | |
2739 | megasas_evt_detail), | |
2740 | &instance->evt_detail_h); | |
2741 | ||
2742 | if (!instance->evt_detail) { | |
2743 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " | |
2744 | "event detail structure\n"); | |
2745 | goto fail_alloc_dma_buf; | |
2746 | } | |
2747 | ||
2748 | /* | |
2749 | * Initialize locks and queues | |
2750 | */ | |
2751 | INIT_LIST_HEAD(&instance->cmd_pool); | |
2752 | ||
e4a082c7 SP |
2753 | atomic_set(&instance->fw_outstanding,0); |
2754 | ||
c4a3e0a5 BS |
2755 | init_waitqueue_head(&instance->int_cmd_wait_q); |
2756 | init_waitqueue_head(&instance->abort_cmd_wait_q); | |
2757 | ||
2758 | spin_lock_init(&instance->cmd_pool_lock); | |
7343eb65 | 2759 | spin_lock_init(&instance->completion_lock); |
c3518837 | 2760 | spin_lock_init(&poll_aen_lock); |
c4a3e0a5 | 2761 | |
e5a69e27 | 2762 | mutex_init(&instance->aen_mutex); |
c4a3e0a5 BS |
2763 | sema_init(&instance->ioctl_sem, MEGASAS_INT_CMDS); |
2764 | ||
2765 | /* | |
2766 | * Initialize PCI related and misc parameters | |
2767 | */ | |
2768 | instance->pdev = pdev; | |
2769 | instance->host = host; | |
2770 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; | |
2771 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; | |
2772 | ||
658dcedb | 2773 | megasas_dbg_lvl = 0; |
05e9ebbe | 2774 | instance->flag = 0; |
c3518837 | 2775 | instance->unload = 0; |
05e9ebbe | 2776 | instance->last_time = 0; |
658dcedb | 2777 | |
c4a3e0a5 BS |
2778 | /* |
2779 | * Initialize MFI Firmware | |
2780 | */ | |
2781 | if (megasas_init_mfi(instance)) | |
2782 | goto fail_init_mfi; | |
2783 | ||
2784 | /* | |
2785 | * Register IRQ | |
2786 | */ | |
1d6f359a | 2787 | if (request_irq(pdev->irq, megasas_isr, IRQF_SHARED, "megasas", instance)) { |
c4a3e0a5 BS |
2788 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); |
2789 | goto fail_irq; | |
2790 | } | |
2791 | ||
1341c939 | 2792 | instance->instancet->enable_intr(instance->reg_set); |
c4a3e0a5 BS |
2793 | |
2794 | /* | |
2795 | * Store instance in PCI softstate | |
2796 | */ | |
2797 | pci_set_drvdata(pdev, instance); | |
2798 | ||
2799 | /* | |
2800 | * Add this controller to megasas_mgmt_info structure so that it | |
2801 | * can be exported to management applications | |
2802 | */ | |
2803 | megasas_mgmt_info.count++; | |
2804 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; | |
2805 | megasas_mgmt_info.max_index++; | |
2806 | ||
2807 | /* | |
2808 | * Initiate AEN (Asynchronous Event Notification) | |
2809 | */ | |
2810 | if (megasas_start_aen(instance)) { | |
2811 | printk(KERN_DEBUG "megasas: start aen failed\n"); | |
2812 | goto fail_start_aen; | |
2813 | } | |
2814 | ||
2815 | /* | |
2816 | * Register with SCSI mid-layer | |
2817 | */ | |
2818 | if (megasas_io_attach(instance)) | |
2819 | goto fail_io_attach; | |
2820 | ||
2821 | return 0; | |
2822 | ||
2823 | fail_start_aen: | |
2824 | fail_io_attach: | |
2825 | megasas_mgmt_info.count--; | |
2826 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; | |
2827 | megasas_mgmt_info.max_index--; | |
2828 | ||
2829 | pci_set_drvdata(pdev, NULL); | |
b274cab7 | 2830 | instance->instancet->disable_intr(instance->reg_set); |
c4a3e0a5 BS |
2831 | free_irq(instance->pdev->irq, instance); |
2832 | ||
2833 | megasas_release_mfi(instance); | |
2834 | ||
2835 | fail_irq: | |
2836 | fail_init_mfi: | |
2837 | fail_alloc_dma_buf: | |
2838 | if (instance->evt_detail) | |
2839 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), | |
2840 | instance->evt_detail, | |
2841 | instance->evt_detail_h); | |
2842 | ||
2843 | if (instance->producer) | |
2844 | pci_free_consistent(pdev, sizeof(u32), instance->producer, | |
2845 | instance->producer_h); | |
2846 | if (instance->consumer) | |
2847 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, | |
2848 | instance->consumer_h); | |
2849 | scsi_host_put(host); | |
2850 | ||
2851 | fail_alloc_instance: | |
2852 | fail_set_dma_mask: | |
2853 | pci_disable_device(pdev); | |
2854 | ||
2855 | return -ENODEV; | |
2856 | } | |
2857 | ||
2858 | /** | |
2859 | * megasas_flush_cache - Requests FW to flush all its caches | |
2860 | * @instance: Adapter soft state | |
2861 | */ | |
2862 | static void megasas_flush_cache(struct megasas_instance *instance) | |
2863 | { | |
2864 | struct megasas_cmd *cmd; | |
2865 | struct megasas_dcmd_frame *dcmd; | |
2866 | ||
2867 | cmd = megasas_get_cmd(instance); | |
2868 | ||
2869 | if (!cmd) | |
2870 | return; | |
2871 | ||
2872 | dcmd = &cmd->frame->dcmd; | |
2873 | ||
2874 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
2875 | ||
2876 | dcmd->cmd = MFI_CMD_DCMD; | |
2877 | dcmd->cmd_status = 0x0; | |
2878 | dcmd->sge_count = 0; | |
2879 | dcmd->flags = MFI_FRAME_DIR_NONE; | |
2880 | dcmd->timeout = 0; | |
2881 | dcmd->data_xfer_len = 0; | |
2882 | dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH; | |
2883 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; | |
2884 | ||
2885 | megasas_issue_blocked_cmd(instance, cmd); | |
2886 | ||
2887 | megasas_return_cmd(instance, cmd); | |
2888 | ||
2889 | return; | |
2890 | } | |
2891 | ||
2892 | /** | |
2893 | * megasas_shutdown_controller - Instructs FW to shutdown the controller | |
2894 | * @instance: Adapter soft state | |
31ea7088 | 2895 | * @opcode: Shutdown/Hibernate |
c4a3e0a5 | 2896 | */ |
31ea7088 | 2897 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
2898 | u32 opcode) | |
c4a3e0a5 BS |
2899 | { |
2900 | struct megasas_cmd *cmd; | |
2901 | struct megasas_dcmd_frame *dcmd; | |
2902 | ||
2903 | cmd = megasas_get_cmd(instance); | |
2904 | ||
2905 | if (!cmd) | |
2906 | return; | |
2907 | ||
2908 | if (instance->aen_cmd) | |
2909 | megasas_issue_blocked_abort_cmd(instance, instance->aen_cmd); | |
2910 | ||
2911 | dcmd = &cmd->frame->dcmd; | |
2912 | ||
2913 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | |
2914 | ||
2915 | dcmd->cmd = MFI_CMD_DCMD; | |
2916 | dcmd->cmd_status = 0x0; | |
2917 | dcmd->sge_count = 0; | |
2918 | dcmd->flags = MFI_FRAME_DIR_NONE; | |
2919 | dcmd->timeout = 0; | |
2920 | dcmd->data_xfer_len = 0; | |
31ea7088 | 2921 | dcmd->opcode = opcode; |
c4a3e0a5 BS |
2922 | |
2923 | megasas_issue_blocked_cmd(instance, cmd); | |
2924 | ||
2925 | megasas_return_cmd(instance, cmd); | |
2926 | ||
2927 | return; | |
2928 | } | |
2929 | ||
33139b21 | 2930 | #ifdef CONFIG_PM |
31ea7088 | 2931 | /** |
ad84db2e | 2932 | * megasas_suspend - driver suspend entry point |
2933 | * @pdev: PCI device structure | |
31ea7088 | 2934 | * @state: PCI power state to suspend routine |
2935 | */ | |
33139b21 | 2936 | static int |
31ea7088 | 2937 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
2938 | { | |
2939 | struct Scsi_Host *host; | |
2940 | struct megasas_instance *instance; | |
2941 | ||
2942 | instance = pci_get_drvdata(pdev); | |
2943 | host = instance->host; | |
2944 | ||
ad84db2e | 2945 | if (poll_mode_io) |
2946 | del_timer_sync(&instance->io_completion_timer); | |
2947 | ||
31ea7088 | 2948 | megasas_flush_cache(instance); |
2949 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); | |
2950 | tasklet_kill(&instance->isr_tasklet); | |
2951 | ||
2952 | pci_set_drvdata(instance->pdev, instance); | |
2953 | instance->instancet->disable_intr(instance->reg_set); | |
2954 | free_irq(instance->pdev->irq, instance); | |
2955 | ||
2956 | pci_save_state(pdev); | |
2957 | pci_disable_device(pdev); | |
2958 | ||
2959 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
2960 | ||
2961 | return 0; | |
2962 | } | |
2963 | ||
2964 | /** | |
2965 | * megasas_resume- driver resume entry point | |
2966 | * @pdev: PCI device structure | |
2967 | */ | |
33139b21 | 2968 | static int |
31ea7088 | 2969 | megasas_resume(struct pci_dev *pdev) |
2970 | { | |
2971 | int rval; | |
2972 | struct Scsi_Host *host; | |
2973 | struct megasas_instance *instance; | |
2974 | ||
2975 | instance = pci_get_drvdata(pdev); | |
2976 | host = instance->host; | |
2977 | pci_set_power_state(pdev, PCI_D0); | |
2978 | pci_enable_wake(pdev, PCI_D0, 0); | |
2979 | pci_restore_state(pdev); | |
2980 | ||
2981 | /* | |
2982 | * PCI prepping: enable device set bus mastering and dma mask | |
2983 | */ | |
2984 | rval = pci_enable_device(pdev); | |
2985 | ||
2986 | if (rval) { | |
2987 | printk(KERN_ERR "megasas: Enable device failed\n"); | |
2988 | return rval; | |
2989 | } | |
2990 | ||
2991 | pci_set_master(pdev); | |
2992 | ||
2993 | if (megasas_set_dma_mask(pdev)) | |
2994 | goto fail_set_dma_mask; | |
2995 | ||
2996 | /* | |
2997 | * Initialize MFI Firmware | |
2998 | */ | |
2999 | ||
3000 | *instance->producer = 0; | |
3001 | *instance->consumer = 0; | |
3002 | ||
3003 | atomic_set(&instance->fw_outstanding, 0); | |
3004 | ||
3005 | /* | |
3006 | * We expect the FW state to be READY | |
3007 | */ | |
3008 | if (megasas_transition_to_ready(instance)) | |
3009 | goto fail_ready_state; | |
3010 | ||
3011 | if (megasas_issue_init_mfi(instance)) | |
3012 | goto fail_init_mfi; | |
3013 | ||
3014 | tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc, | |
3015 | (unsigned long)instance); | |
3016 | ||
3017 | /* | |
3018 | * Register IRQ | |
3019 | */ | |
3020 | if (request_irq(pdev->irq, megasas_isr, IRQF_SHARED, | |
3021 | "megasas", instance)) { | |
3022 | printk(KERN_ERR "megasas: Failed to register IRQ\n"); | |
3023 | goto fail_irq; | |
3024 | } | |
3025 | ||
3026 | instance->instancet->enable_intr(instance->reg_set); | |
3027 | ||
3028 | /* | |
3029 | * Initiate AEN (Asynchronous Event Notification) | |
3030 | */ | |
3031 | if (megasas_start_aen(instance)) | |
3032 | printk(KERN_ERR "megasas: Start AEN failed\n"); | |
3033 | ||
ad84db2e | 3034 | /* Initialize the cmd completion timer */ |
3035 | if (poll_mode_io) | |
3036 | megasas_start_timer(instance, &instance->io_completion_timer, | |
3037 | megasas_io_completion_timer, | |
3038 | MEGASAS_COMPLETION_TIMER_INTERVAL); | |
31ea7088 | 3039 | return 0; |
3040 | ||
3041 | fail_irq: | |
3042 | fail_init_mfi: | |
3043 | if (instance->evt_detail) | |
3044 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), | |
3045 | instance->evt_detail, | |
3046 | instance->evt_detail_h); | |
3047 | ||
3048 | if (instance->producer) | |
3049 | pci_free_consistent(pdev, sizeof(u32), instance->producer, | |
3050 | instance->producer_h); | |
3051 | if (instance->consumer) | |
3052 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, | |
3053 | instance->consumer_h); | |
3054 | scsi_host_put(host); | |
3055 | ||
3056 | fail_set_dma_mask: | |
3057 | fail_ready_state: | |
3058 | ||
3059 | pci_disable_device(pdev); | |
3060 | ||
3061 | return -ENODEV; | |
3062 | } | |
33139b21 JS |
3063 | #else |
3064 | #define megasas_suspend NULL | |
3065 | #define megasas_resume NULL | |
3066 | #endif | |
31ea7088 | 3067 | |
c4a3e0a5 BS |
3068 | /** |
3069 | * megasas_detach_one - PCI hot"un"plug entry point | |
3070 | * @pdev: PCI device structure | |
3071 | */ | |
33139b21 | 3072 | static void __devexit megasas_detach_one(struct pci_dev *pdev) |
c4a3e0a5 BS |
3073 | { |
3074 | int i; | |
3075 | struct Scsi_Host *host; | |
3076 | struct megasas_instance *instance; | |
3077 | ||
3078 | instance = pci_get_drvdata(pdev); | |
c3518837 | 3079 | instance->unload = 1; |
c4a3e0a5 BS |
3080 | host = instance->host; |
3081 | ||
ad84db2e | 3082 | if (poll_mode_io) |
3083 | del_timer_sync(&instance->io_completion_timer); | |
3084 | ||
c4a3e0a5 BS |
3085 | scsi_remove_host(instance->host); |
3086 | megasas_flush_cache(instance); | |
31ea7088 | 3087 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
5d018ad0 | 3088 | tasklet_kill(&instance->isr_tasklet); |
c4a3e0a5 BS |
3089 | |
3090 | /* | |
3091 | * Take the instance off the instance array. Note that we will not | |
3092 | * decrement the max_index. We let this array be sparse array | |
3093 | */ | |
3094 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | |
3095 | if (megasas_mgmt_info.instance[i] == instance) { | |
3096 | megasas_mgmt_info.count--; | |
3097 | megasas_mgmt_info.instance[i] = NULL; | |
3098 | ||
3099 | break; | |
3100 | } | |
3101 | } | |
3102 | ||
3103 | pci_set_drvdata(instance->pdev, NULL); | |
3104 | ||
b274cab7 | 3105 | instance->instancet->disable_intr(instance->reg_set); |
c4a3e0a5 BS |
3106 | |
3107 | free_irq(instance->pdev->irq, instance); | |
3108 | ||
3109 | megasas_release_mfi(instance); | |
3110 | ||
3111 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), | |
3112 | instance->evt_detail, instance->evt_detail_h); | |
3113 | ||
3114 | pci_free_consistent(pdev, sizeof(u32), instance->producer, | |
3115 | instance->producer_h); | |
3116 | ||
3117 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, | |
3118 | instance->consumer_h); | |
3119 | ||
3120 | scsi_host_put(host); | |
3121 | ||
3122 | pci_set_drvdata(pdev, NULL); | |
3123 | ||
3124 | pci_disable_device(pdev); | |
3125 | ||
3126 | return; | |
3127 | } | |
3128 | ||
3129 | /** | |
3130 | * megasas_shutdown - Shutdown entry point | |
3131 | * @device: Generic device structure | |
3132 | */ | |
3133 | static void megasas_shutdown(struct pci_dev *pdev) | |
3134 | { | |
3135 | struct megasas_instance *instance = pci_get_drvdata(pdev); | |
3136 | megasas_flush_cache(instance); | |
530e6fc1 | 3137 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
c4a3e0a5 BS |
3138 | } |
3139 | ||
3140 | /** | |
3141 | * megasas_mgmt_open - char node "open" entry point | |
3142 | */ | |
3143 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) | |
3144 | { | |
f2b9857e | 3145 | cycle_kernel_lock(); |
c4a3e0a5 BS |
3146 | /* |
3147 | * Allow only those users with admin rights | |
3148 | */ | |
3149 | if (!capable(CAP_SYS_ADMIN)) | |
3150 | return -EACCES; | |
3151 | ||
3152 | return 0; | |
3153 | } | |
3154 | ||
c4a3e0a5 BS |
3155 | /** |
3156 | * megasas_mgmt_fasync - Async notifier registration from applications | |
3157 | * | |
3158 | * This function adds the calling process to a driver global queue. When an | |
3159 | * event occurs, SIGIO will be sent to all processes in this queue. | |
3160 | */ | |
3161 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) | |
3162 | { | |
3163 | int rc; | |
3164 | ||
0b950672 | 3165 | mutex_lock(&megasas_async_queue_mutex); |
c4a3e0a5 BS |
3166 | |
3167 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); | |
3168 | ||
0b950672 | 3169 | mutex_unlock(&megasas_async_queue_mutex); |
c4a3e0a5 BS |
3170 | |
3171 | if (rc >= 0) { | |
3172 | /* For sanity check when we get ioctl */ | |
3173 | filep->private_data = filep; | |
3174 | return 0; | |
3175 | } | |
3176 | ||
3177 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); | |
3178 | ||
3179 | return rc; | |
3180 | } | |
3181 | ||
c3518837 YB |
3182 | /** |
3183 | * megasas_mgmt_poll - char node "poll" entry point | |
3184 | * */ | |
3185 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) | |
3186 | { | |
3187 | unsigned int mask; | |
3188 | unsigned long flags; | |
3189 | poll_wait(file, &megasas_poll_wait, wait); | |
3190 | spin_lock_irqsave(&poll_aen_lock, flags); | |
3191 | if (megasas_poll_wait_aen) | |
3192 | mask = (POLLIN | POLLRDNORM); | |
3193 | else | |
3194 | mask = 0; | |
3195 | spin_unlock_irqrestore(&poll_aen_lock, flags); | |
3196 | return mask; | |
3197 | } | |
3198 | ||
c4a3e0a5 BS |
3199 | /** |
3200 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW | |
3201 | * @instance: Adapter soft state | |
3202 | * @argp: User's ioctl packet | |
3203 | */ | |
3204 | static int | |
3205 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, | |
3206 | struct megasas_iocpacket __user * user_ioc, | |
3207 | struct megasas_iocpacket *ioc) | |
3208 | { | |
3209 | struct megasas_sge32 *kern_sge32; | |
3210 | struct megasas_cmd *cmd; | |
3211 | void *kbuff_arr[MAX_IOCTL_SGE]; | |
3212 | dma_addr_t buf_handle = 0; | |
3213 | int error = 0, i; | |
3214 | void *sense = NULL; | |
3215 | dma_addr_t sense_handle; | |
3216 | u32 *sense_ptr; | |
3217 | ||
3218 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); | |
3219 | ||
3220 | if (ioc->sge_count > MAX_IOCTL_SGE) { | |
3221 | printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n", | |
3222 | ioc->sge_count, MAX_IOCTL_SGE); | |
3223 | return -EINVAL; | |
3224 | } | |
3225 | ||
3226 | cmd = megasas_get_cmd(instance); | |
3227 | if (!cmd) { | |
3228 | printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n"); | |
3229 | return -ENOMEM; | |
3230 | } | |
3231 | ||
3232 | /* | |
3233 | * User's IOCTL packet has 2 frames (maximum). Copy those two | |
3234 | * frames into our cmd's frames. cmd->frame's context will get | |
3235 | * overwritten when we copy from user's frames. So set that value | |
3236 | * alone separately | |
3237 | */ | |
3238 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); | |
3239 | cmd->frame->hdr.context = cmd->index; | |
c3518837 | 3240 | cmd->frame->hdr.pad_0 = 0; |
c4a3e0a5 BS |
3241 | |
3242 | /* | |
3243 | * The management interface between applications and the fw uses | |
3244 | * MFI frames. E.g, RAID configuration changes, LD property changes | |
3245 | * etc are accomplishes through different kinds of MFI frames. The | |
3246 | * driver needs to care only about substituting user buffers with | |
3247 | * kernel buffers in SGLs. The location of SGL is embedded in the | |
3248 | * struct iocpacket itself. | |
3249 | */ | |
3250 | kern_sge32 = (struct megasas_sge32 *) | |
3251 | ((unsigned long)cmd->frame + ioc->sgl_off); | |
3252 | ||
3253 | /* | |
3254 | * For each user buffer, create a mirror buffer and copy in | |
3255 | */ | |
3256 | for (i = 0; i < ioc->sge_count; i++) { | |
9f35fa8a | 3257 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
c4a3e0a5 | 3258 | ioc->sgl[i].iov_len, |
9f35fa8a | 3259 | &buf_handle, GFP_KERNEL); |
c4a3e0a5 BS |
3260 | if (!kbuff_arr[i]) { |
3261 | printk(KERN_DEBUG "megasas: Failed to alloc " | |
3262 | "kernel SGL buffer for IOCTL \n"); | |
3263 | error = -ENOMEM; | |
3264 | goto out; | |
3265 | } | |
3266 | ||
3267 | /* | |
3268 | * We don't change the dma_coherent_mask, so | |
3269 | * pci_alloc_consistent only returns 32bit addresses | |
3270 | */ | |
3271 | kern_sge32[i].phys_addr = (u32) buf_handle; | |
3272 | kern_sge32[i].length = ioc->sgl[i].iov_len; | |
3273 | ||
3274 | /* | |
3275 | * We created a kernel buffer corresponding to the | |
3276 | * user buffer. Now copy in from the user buffer | |
3277 | */ | |
3278 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, | |
3279 | (u32) (ioc->sgl[i].iov_len))) { | |
3280 | error = -EFAULT; | |
3281 | goto out; | |
3282 | } | |
3283 | } | |
3284 | ||
3285 | if (ioc->sense_len) { | |
9f35fa8a SP |
3286 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
3287 | &sense_handle, GFP_KERNEL); | |
c4a3e0a5 BS |
3288 | if (!sense) { |
3289 | error = -ENOMEM; | |
3290 | goto out; | |
3291 | } | |
3292 | ||
3293 | sense_ptr = | |
3294 | (u32 *) ((unsigned long)cmd->frame + ioc->sense_off); | |
3295 | *sense_ptr = sense_handle; | |
3296 | } | |
3297 | ||
3298 | /* | |
3299 | * Set the sync_cmd flag so that the ISR knows not to complete this | |
3300 | * cmd to the SCSI mid-layer | |
3301 | */ | |
3302 | cmd->sync_cmd = 1; | |
3303 | megasas_issue_blocked_cmd(instance, cmd); | |
3304 | cmd->sync_cmd = 0; | |
3305 | ||
3306 | /* | |
3307 | * copy out the kernel buffers to user buffers | |
3308 | */ | |
3309 | for (i = 0; i < ioc->sge_count; i++) { | |
3310 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], | |
3311 | ioc->sgl[i].iov_len)) { | |
3312 | error = -EFAULT; | |
3313 | goto out; | |
3314 | } | |
3315 | } | |
3316 | ||
3317 | /* | |
3318 | * copy out the sense | |
3319 | */ | |
3320 | if (ioc->sense_len) { | |
3321 | /* | |
b70a41e0 | 3322 | * sense_ptr points to the location that has the user |
c4a3e0a5 BS |
3323 | * sense buffer address |
3324 | */ | |
b70a41e0 | 3325 | sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw + |
3326 | ioc->sense_off); | |
c4a3e0a5 | 3327 | |
b70a41e0 | 3328 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
3329 | sense, ioc->sense_len)) { | |
b10c36a5 | 3330 | printk(KERN_ERR "megasas: Failed to copy out to user " |
3331 | "sense data\n"); | |
c4a3e0a5 BS |
3332 | error = -EFAULT; |
3333 | goto out; | |
3334 | } | |
3335 | } | |
3336 | ||
3337 | /* | |
3338 | * copy the status codes returned by the fw | |
3339 | */ | |
3340 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, | |
3341 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { | |
3342 | printk(KERN_DEBUG "megasas: Error copying out cmd_status\n"); | |
3343 | error = -EFAULT; | |
3344 | } | |
3345 | ||
3346 | out: | |
3347 | if (sense) { | |
9f35fa8a | 3348 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
c4a3e0a5 BS |
3349 | sense, sense_handle); |
3350 | } | |
3351 | ||
3352 | for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) { | |
9f35fa8a | 3353 | dma_free_coherent(&instance->pdev->dev, |
c4a3e0a5 BS |
3354 | kern_sge32[i].length, |
3355 | kbuff_arr[i], kern_sge32[i].phys_addr); | |
3356 | } | |
3357 | ||
3358 | megasas_return_cmd(instance, cmd); | |
3359 | return error; | |
3360 | } | |
3361 | ||
3362 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) | |
3363 | { | |
3364 | int i; | |
3365 | ||
3366 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | |
3367 | ||
3368 | if ((megasas_mgmt_info.instance[i]) && | |
3369 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) | |
3370 | return megasas_mgmt_info.instance[i]; | |
3371 | } | |
3372 | ||
3373 | return NULL; | |
3374 | } | |
3375 | ||
3376 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) | |
3377 | { | |
3378 | struct megasas_iocpacket __user *user_ioc = | |
3379 | (struct megasas_iocpacket __user *)arg; | |
3380 | struct megasas_iocpacket *ioc; | |
3381 | struct megasas_instance *instance; | |
3382 | int error; | |
3383 | ||
3384 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); | |
3385 | if (!ioc) | |
3386 | return -ENOMEM; | |
3387 | ||
3388 | if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { | |
3389 | error = -EFAULT; | |
3390 | goto out_kfree_ioc; | |
3391 | } | |
3392 | ||
3393 | instance = megasas_lookup_instance(ioc->host_no); | |
3394 | if (!instance) { | |
3395 | error = -ENODEV; | |
3396 | goto out_kfree_ioc; | |
3397 | } | |
3398 | ||
3399 | /* | |
3400 | * We will allow only MEGASAS_INT_CMDS number of parallel ioctl cmds | |
3401 | */ | |
3402 | if (down_interruptible(&instance->ioctl_sem)) { | |
3403 | error = -ERESTARTSYS; | |
3404 | goto out_kfree_ioc; | |
3405 | } | |
3406 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); | |
3407 | up(&instance->ioctl_sem); | |
3408 | ||
3409 | out_kfree_ioc: | |
3410 | kfree(ioc); | |
3411 | return error; | |
3412 | } | |
3413 | ||
3414 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) | |
3415 | { | |
3416 | struct megasas_instance *instance; | |
3417 | struct megasas_aen aen; | |
3418 | int error; | |
3419 | ||
3420 | if (file->private_data != file) { | |
3421 | printk(KERN_DEBUG "megasas: fasync_helper was not " | |
3422 | "called first\n"); | |
3423 | return -EINVAL; | |
3424 | } | |
3425 | ||
3426 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) | |
3427 | return -EFAULT; | |
3428 | ||
3429 | instance = megasas_lookup_instance(aen.host_no); | |
3430 | ||
3431 | if (!instance) | |
3432 | return -ENODEV; | |
3433 | ||
e5a69e27 | 3434 | mutex_lock(&instance->aen_mutex); |
c4a3e0a5 BS |
3435 | error = megasas_register_aen(instance, aen.seq_num, |
3436 | aen.class_locale_word); | |
e5a69e27 | 3437 | mutex_unlock(&instance->aen_mutex); |
c4a3e0a5 BS |
3438 | return error; |
3439 | } | |
3440 | ||
3441 | /** | |
3442 | * megasas_mgmt_ioctl - char node ioctl entry point | |
3443 | */ | |
3444 | static long | |
3445 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
3446 | { | |
3447 | switch (cmd) { | |
3448 | case MEGASAS_IOC_FIRMWARE: | |
3449 | return megasas_mgmt_ioctl_fw(file, arg); | |
3450 | ||
3451 | case MEGASAS_IOC_GET_AEN: | |
3452 | return megasas_mgmt_ioctl_aen(file, arg); | |
3453 | } | |
3454 | ||
3455 | return -ENOTTY; | |
3456 | } | |
3457 | ||
3458 | #ifdef CONFIG_COMPAT | |
3459 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) | |
3460 | { | |
3461 | struct compat_megasas_iocpacket __user *cioc = | |
3462 | (struct compat_megasas_iocpacket __user *)arg; | |
3463 | struct megasas_iocpacket __user *ioc = | |
3464 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); | |
3465 | int i; | |
3466 | int error = 0; | |
3467 | ||
83aabc1b JG |
3468 | if (clear_user(ioc, sizeof(*ioc))) |
3469 | return -EFAULT; | |
c4a3e0a5 BS |
3470 | |
3471 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || | |
3472 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || | |
3473 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || | |
3474 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || | |
3475 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || | |
3476 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) | |
3477 | return -EFAULT; | |
3478 | ||
3479 | for (i = 0; i < MAX_IOCTL_SGE; i++) { | |
3480 | compat_uptr_t ptr; | |
3481 | ||
3482 | if (get_user(ptr, &cioc->sgl[i].iov_base) || | |
3483 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || | |
3484 | copy_in_user(&ioc->sgl[i].iov_len, | |
3485 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) | |
3486 | return -EFAULT; | |
3487 | } | |
3488 | ||
3489 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); | |
3490 | ||
3491 | if (copy_in_user(&cioc->frame.hdr.cmd_status, | |
3492 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { | |
3493 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); | |
3494 | return -EFAULT; | |
3495 | } | |
3496 | return error; | |
3497 | } | |
3498 | ||
3499 | static long | |
3500 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, | |
3501 | unsigned long arg) | |
3502 | { | |
3503 | switch (cmd) { | |
cb59aa6a SP |
3504 | case MEGASAS_IOC_FIRMWARE32: |
3505 | return megasas_mgmt_compat_ioctl_fw(file, arg); | |
c4a3e0a5 BS |
3506 | case MEGASAS_IOC_GET_AEN: |
3507 | return megasas_mgmt_ioctl_aen(file, arg); | |
3508 | } | |
3509 | ||
3510 | return -ENOTTY; | |
3511 | } | |
3512 | #endif | |
3513 | ||
3514 | /* | |
3515 | * File operations structure for management interface | |
3516 | */ | |
00977a59 | 3517 | static const struct file_operations megasas_mgmt_fops = { |
c4a3e0a5 BS |
3518 | .owner = THIS_MODULE, |
3519 | .open = megasas_mgmt_open, | |
c4a3e0a5 BS |
3520 | .fasync = megasas_mgmt_fasync, |
3521 | .unlocked_ioctl = megasas_mgmt_ioctl, | |
c3518837 | 3522 | .poll = megasas_mgmt_poll, |
c4a3e0a5 BS |
3523 | #ifdef CONFIG_COMPAT |
3524 | .compat_ioctl = megasas_mgmt_compat_ioctl, | |
3525 | #endif | |
3526 | }; | |
3527 | ||
3528 | /* | |
3529 | * PCI hotplug support registration structure | |
3530 | */ | |
3531 | static struct pci_driver megasas_pci_driver = { | |
3532 | ||
3533 | .name = "megaraid_sas", | |
3534 | .id_table = megasas_pci_table, | |
3535 | .probe = megasas_probe_one, | |
3536 | .remove = __devexit_p(megasas_detach_one), | |
31ea7088 | 3537 | .suspend = megasas_suspend, |
3538 | .resume = megasas_resume, | |
c4a3e0a5 BS |
3539 | .shutdown = megasas_shutdown, |
3540 | }; | |
3541 | ||
3542 | /* | |
3543 | * Sysfs driver attributes | |
3544 | */ | |
3545 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) | |
3546 | { | |
3547 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", | |
3548 | MEGASAS_VERSION); | |
3549 | } | |
3550 | ||
3551 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); | |
3552 | ||
3553 | static ssize_t | |
3554 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) | |
3555 | { | |
3556 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", | |
3557 | MEGASAS_RELDATE); | |
3558 | } | |
3559 | ||
3560 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, | |
3561 | NULL); | |
3562 | ||
72c4fd36 YB |
3563 | static ssize_t |
3564 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) | |
3565 | { | |
3566 | return sprintf(buf, "%u\n", support_poll_for_event); | |
3567 | } | |
3568 | ||
3569 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, | |
3570 | megasas_sysfs_show_support_poll_for_event, NULL); | |
3571 | ||
658dcedb SP |
3572 | static ssize_t |
3573 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) | |
3574 | { | |
ad84db2e | 3575 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
658dcedb SP |
3576 | } |
3577 | ||
3578 | static ssize_t | |
3579 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) | |
3580 | { | |
3581 | int retval = count; | |
3582 | if(sscanf(buf,"%u",&megasas_dbg_lvl)<1){ | |
3583 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); | |
3584 | retval = -EINVAL; | |
3585 | } | |
3586 | return retval; | |
3587 | } | |
3588 | ||
66dca9b8 | 3589 | static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl, |
ad84db2e | 3590 | megasas_sysfs_set_dbg_lvl); |
3591 | ||
3592 | static ssize_t | |
3593 | megasas_sysfs_show_poll_mode_io(struct device_driver *dd, char *buf) | |
3594 | { | |
3595 | return sprintf(buf, "%u\n", poll_mode_io); | |
3596 | } | |
3597 | ||
3598 | static ssize_t | |
3599 | megasas_sysfs_set_poll_mode_io(struct device_driver *dd, | |
3600 | const char *buf, size_t count) | |
3601 | { | |
3602 | int retval = count; | |
3603 | int tmp = poll_mode_io; | |
3604 | int i; | |
3605 | struct megasas_instance *instance; | |
3606 | ||
3607 | if (sscanf(buf, "%u", &poll_mode_io) < 1) { | |
3608 | printk(KERN_ERR "megasas: could not set poll_mode_io\n"); | |
3609 | retval = -EINVAL; | |
3610 | } | |
3611 | ||
3612 | /* | |
3613 | * Check if poll_mode_io is already set or is same as previous value | |
3614 | */ | |
3615 | if ((tmp && poll_mode_io) || (tmp == poll_mode_io)) | |
3616 | goto out; | |
3617 | ||
3618 | if (poll_mode_io) { | |
3619 | /* | |
3620 | * Start timers for all adapters | |
3621 | */ | |
3622 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | |
3623 | instance = megasas_mgmt_info.instance[i]; | |
3624 | if (instance) { | |
3625 | megasas_start_timer(instance, | |
3626 | &instance->io_completion_timer, | |
3627 | megasas_io_completion_timer, | |
3628 | MEGASAS_COMPLETION_TIMER_INTERVAL); | |
3629 | } | |
3630 | } | |
3631 | } else { | |
3632 | /* | |
3633 | * Delete timers for all adapters | |
3634 | */ | |
3635 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | |
3636 | instance = megasas_mgmt_info.instance[i]; | |
3637 | if (instance) | |
3638 | del_timer_sync(&instance->io_completion_timer); | |
3639 | } | |
3640 | } | |
3641 | ||
3642 | out: | |
3643 | return retval; | |
3644 | } | |
3645 | ||
3646 | static DRIVER_ATTR(poll_mode_io, S_IRUGO|S_IWUGO, | |
3647 | megasas_sysfs_show_poll_mode_io, | |
3648 | megasas_sysfs_set_poll_mode_io); | |
658dcedb | 3649 | |
c4a3e0a5 BS |
3650 | /** |
3651 | * megasas_init - Driver load entry point | |
3652 | */ | |
3653 | static int __init megasas_init(void) | |
3654 | { | |
3655 | int rval; | |
3656 | ||
3657 | /* | |
3658 | * Announce driver version and other information | |
3659 | */ | |
3660 | printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, | |
3661 | MEGASAS_EXT_VERSION); | |
3662 | ||
72c4fd36 YB |
3663 | support_poll_for_event = 2; |
3664 | ||
c4a3e0a5 BS |
3665 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
3666 | ||
3667 | /* | |
3668 | * Register character device node | |
3669 | */ | |
3670 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); | |
3671 | ||
3672 | if (rval < 0) { | |
3673 | printk(KERN_DEBUG "megasas: failed to open device node\n"); | |
3674 | return rval; | |
3675 | } | |
3676 | ||
3677 | megasas_mgmt_majorno = rval; | |
3678 | ||
3679 | /* | |
3680 | * Register ourselves as PCI hotplug module | |
3681 | */ | |
4041b9cd | 3682 | rval = pci_register_driver(&megasas_pci_driver); |
c4a3e0a5 BS |
3683 | |
3684 | if (rval) { | |
3685 | printk(KERN_DEBUG "megasas: PCI hotplug regisration failed \n"); | |
83aabc1b JG |
3686 | goto err_pcidrv; |
3687 | } | |
3688 | ||
3689 | rval = driver_create_file(&megasas_pci_driver.driver, | |
3690 | &driver_attr_version); | |
3691 | if (rval) | |
3692 | goto err_dcf_attr_ver; | |
3693 | rval = driver_create_file(&megasas_pci_driver.driver, | |
3694 | &driver_attr_release_date); | |
3695 | if (rval) | |
3696 | goto err_dcf_rel_date; | |
72c4fd36 YB |
3697 | |
3698 | rval = driver_create_file(&megasas_pci_driver.driver, | |
3699 | &driver_attr_support_poll_for_event); | |
3700 | if (rval) | |
3701 | goto err_dcf_support_poll_for_event; | |
3702 | ||
83aabc1b JG |
3703 | rval = driver_create_file(&megasas_pci_driver.driver, |
3704 | &driver_attr_dbg_lvl); | |
3705 | if (rval) | |
3706 | goto err_dcf_dbg_lvl; | |
ad84db2e | 3707 | rval = driver_create_file(&megasas_pci_driver.driver, |
3708 | &driver_attr_poll_mode_io); | |
3709 | if (rval) | |
3710 | goto err_dcf_poll_mode_io; | |
c4a3e0a5 BS |
3711 | |
3712 | return rval; | |
ad84db2e | 3713 | |
3714 | err_dcf_poll_mode_io: | |
3715 | driver_remove_file(&megasas_pci_driver.driver, | |
3716 | &driver_attr_dbg_lvl); | |
83aabc1b | 3717 | err_dcf_dbg_lvl: |
72c4fd36 YB |
3718 | driver_remove_file(&megasas_pci_driver.driver, |
3719 | &driver_attr_support_poll_for_event); | |
3720 | ||
3721 | err_dcf_support_poll_for_event: | |
83aabc1b JG |
3722 | driver_remove_file(&megasas_pci_driver.driver, |
3723 | &driver_attr_release_date); | |
72c4fd36 | 3724 | |
83aabc1b JG |
3725 | err_dcf_rel_date: |
3726 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); | |
3727 | err_dcf_attr_ver: | |
3728 | pci_unregister_driver(&megasas_pci_driver); | |
3729 | err_pcidrv: | |
3730 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); | |
3731 | return rval; | |
c4a3e0a5 BS |
3732 | } |
3733 | ||
3734 | /** | |
3735 | * megasas_exit - Driver unload entry point | |
3736 | */ | |
3737 | static void __exit megasas_exit(void) | |
3738 | { | |
ad84db2e | 3739 | driver_remove_file(&megasas_pci_driver.driver, |
3740 | &driver_attr_poll_mode_io); | |
658dcedb SP |
3741 | driver_remove_file(&megasas_pci_driver.driver, |
3742 | &driver_attr_dbg_lvl); | |
83aabc1b JG |
3743 | driver_remove_file(&megasas_pci_driver.driver, |
3744 | &driver_attr_release_date); | |
3745 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); | |
c4a3e0a5 BS |
3746 | |
3747 | pci_unregister_driver(&megasas_pci_driver); | |
3748 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); | |
3749 | } | |
3750 | ||
3751 | module_init(megasas_init); | |
3752 | module_exit(megasas_exit); |