2 * linux/drivers/scsi/esas2r/esas2r_main.c
3 * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
5 * Copyright (c) 2001-2013 ATTO Technology, Inc.
6 * (mailto:linuxdrivers@attotech.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 MODULE_DESCRIPTION(ESAS2R_DRVR_NAME
": " ESAS2R_LONGNAME
" driver");
47 MODULE_AUTHOR("ATTO Technology, Inc.");
48 MODULE_LICENSE("GPL");
49 MODULE_VERSION(ESAS2R_VERSION_STR
);
51 /* global definitions */
53 static int found_adapters
;
54 struct esas2r_adapter
*esas2r_adapters
[MAX_ADAPTERS
];
56 #define ESAS2R_VDA_EVENT_PORT1 54414
57 #define ESAS2R_VDA_EVENT_PORT2 54415
58 #define ESAS2R_VDA_EVENT_SOCK_COUNT 2
60 static struct esas2r_adapter
*esas2r_adapter_from_kobj(struct kobject
*kobj
)
62 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
63 struct Scsi_Host
*host
= class_to_shost(dev
);
65 return (struct esas2r_adapter
*)host
->hostdata
;
68 static ssize_t
read_fw(struct file
*file
, struct kobject
*kobj
,
69 struct bin_attribute
*attr
,
70 char *buf
, loff_t off
, size_t count
)
72 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
74 return esas2r_read_fw(a
, buf
, off
, count
);
77 static ssize_t
write_fw(struct file
*file
, struct kobject
*kobj
,
78 struct bin_attribute
*attr
,
79 char *buf
, loff_t off
, size_t count
)
81 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
83 return esas2r_write_fw(a
, buf
, off
, count
);
86 static ssize_t
read_fs(struct file
*file
, struct kobject
*kobj
,
87 struct bin_attribute
*attr
,
88 char *buf
, loff_t off
, size_t count
)
90 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
92 return esas2r_read_fs(a
, buf
, off
, count
);
95 static ssize_t
write_fs(struct file
*file
, struct kobject
*kobj
,
96 struct bin_attribute
*attr
,
97 char *buf
, loff_t off
, size_t count
)
99 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
100 int length
= min(sizeof(struct esas2r_ioctl_fs
), count
);
103 result
= esas2r_write_fs(a
, buf
, off
, count
);
111 static ssize_t
read_vda(struct file
*file
, struct kobject
*kobj
,
112 struct bin_attribute
*attr
,
113 char *buf
, loff_t off
, size_t count
)
115 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
117 return esas2r_read_vda(a
, buf
, off
, count
);
120 static ssize_t
write_vda(struct file
*file
, struct kobject
*kobj
,
121 struct bin_attribute
*attr
,
122 char *buf
, loff_t off
, size_t count
)
124 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
126 return esas2r_write_vda(a
, buf
, off
, count
);
129 static ssize_t
read_live_nvram(struct file
*file
, struct kobject
*kobj
,
130 struct bin_attribute
*attr
,
131 char *buf
, loff_t off
, size_t count
)
133 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
134 int length
= min_t(size_t, sizeof(struct esas2r_sas_nvram
), PAGE_SIZE
);
136 memcpy(buf
, a
->nvram
, length
);
140 static ssize_t
write_live_nvram(struct file
*file
, struct kobject
*kobj
,
141 struct bin_attribute
*attr
,
142 char *buf
, loff_t off
, size_t count
)
144 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
145 struct esas2r_request
*rq
;
146 int result
= -EFAULT
;
148 rq
= esas2r_alloc_request(a
);
152 if (esas2r_write_params(a
, rq
, (struct esas2r_sas_nvram
*)buf
))
155 esas2r_free_request(a
, rq
);
160 static ssize_t
read_default_nvram(struct file
*file
, struct kobject
*kobj
,
161 struct bin_attribute
*attr
,
162 char *buf
, loff_t off
, size_t count
)
164 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
166 esas2r_nvram_get_defaults(a
, (struct esas2r_sas_nvram
*)buf
);
168 return sizeof(struct esas2r_sas_nvram
);
171 static ssize_t
read_hw(struct file
*file
, struct kobject
*kobj
,
172 struct bin_attribute
*attr
,
173 char *buf
, loff_t off
, size_t count
)
175 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
176 int length
= min_t(size_t, sizeof(struct atto_ioctl
), PAGE_SIZE
);
178 if (!a
->local_atto_ioctl
)
181 if (handle_hba_ioctl(a
, a
->local_atto_ioctl
) != IOCTL_SUCCESS
)
184 memcpy(buf
, a
->local_atto_ioctl
, length
);
189 static ssize_t
write_hw(struct file
*file
, struct kobject
*kobj
,
190 struct bin_attribute
*attr
,
191 char *buf
, loff_t off
, size_t count
)
193 struct esas2r_adapter
*a
= esas2r_adapter_from_kobj(kobj
);
194 int length
= min(sizeof(struct atto_ioctl
), count
);
196 if (!a
->local_atto_ioctl
) {
197 a
->local_atto_ioctl
= kmalloc(sizeof(struct atto_ioctl
),
199 if (a
->local_atto_ioctl
== NULL
) {
200 esas2r_log(ESAS2R_LOG_WARN
,
201 "write_hw kzalloc failed for %zu bytes",
202 sizeof(struct atto_ioctl
));
207 memset(a
->local_atto_ioctl
, 0, sizeof(struct atto_ioctl
));
208 memcpy(a
->local_atto_ioctl
, buf
, length
);
213 #define ESAS2R_RW_BIN_ATTR(_name) \
214 struct bin_attribute bin_attr_ ## _name = { \
216 { .name = __stringify(_name), .mode = S_IRUSR | S_IWUSR }, \
218 .read = read_ ## _name, \
219 .write = write_ ## _name }
221 ESAS2R_RW_BIN_ATTR(fw
);
222 ESAS2R_RW_BIN_ATTR(fs
);
223 ESAS2R_RW_BIN_ATTR(vda
);
224 ESAS2R_RW_BIN_ATTR(hw
);
225 ESAS2R_RW_BIN_ATTR(live_nvram
);
227 struct bin_attribute bin_attr_default_nvram
= {
228 .attr
= { .name
= "default_nvram", .mode
= S_IRUGO
},
230 .read
= read_default_nvram
,
234 static struct scsi_host_template driver_template
= {
235 .module
= THIS_MODULE
,
236 .show_info
= esas2r_show_info
,
237 .name
= ESAS2R_LONGNAME
,
239 .ioctl
= esas2r_ioctl
,
240 .queuecommand
= esas2r_queuecommand
,
241 .eh_abort_handler
= esas2r_eh_abort
,
242 .eh_device_reset_handler
= esas2r_device_reset
,
243 .eh_bus_reset_handler
= esas2r_bus_reset
,
244 .eh_host_reset_handler
= esas2r_host_reset
,
245 .eh_target_reset_handler
= esas2r_target_reset
,
248 .sg_tablesize
= SG_CHUNK_SIZE
,
250 ESAS2R_DEFAULT_CMD_PER_LUN
,
252 .unchecked_isa_dma
= 0,
254 .proc_name
= ESAS2R_DRVR_NAME
,
255 .change_queue_depth
= scsi_change_queue_depth
,
256 .max_sectors
= 0xFFFF,
259 int sgl_page_size
= 512;
260 module_param(sgl_page_size
, int, 0);
261 MODULE_PARM_DESC(sgl_page_size
,
262 "Scatter/gather list (SGL) page size in number of S/G "
263 "entries. If your application is doing a lot of very large "
264 "transfers, you may want to increase the SGL page size. "
267 int num_sg_lists
= 1024;
268 module_param(num_sg_lists
, int, 0);
269 MODULE_PARM_DESC(num_sg_lists
,
270 "Number of scatter/gather lists. Default 1024.");
272 int sg_tablesize
= SG_CHUNK_SIZE
;
273 module_param(sg_tablesize
, int, 0);
274 MODULE_PARM_DESC(sg_tablesize
,
275 "Maximum number of entries in a scatter/gather table.");
277 int num_requests
= 256;
278 module_param(num_requests
, int, 0);
279 MODULE_PARM_DESC(num_requests
,
280 "Number of requests. Default 256.");
282 int num_ae_requests
= 4;
283 module_param(num_ae_requests
, int, 0);
284 MODULE_PARM_DESC(num_ae_requests
,
285 "Number of VDA asynchronous event requests. Default 4.");
287 int cmd_per_lun
= ESAS2R_DEFAULT_CMD_PER_LUN
;
288 module_param(cmd_per_lun
, int, 0);
289 MODULE_PARM_DESC(cmd_per_lun
,
290 "Maximum number of commands per LUN. Default "
291 DEFINED_NUM_TO_STR(ESAS2R_DEFAULT_CMD_PER_LUN
) ".");
294 module_param(can_queue
, int, 0);
295 MODULE_PARM_DESC(can_queue
,
296 "Maximum number of commands per adapter. Default 128.");
298 int esas2r_max_sectors
= 0xFFFF;
299 module_param(esas2r_max_sectors
, int, 0);
300 MODULE_PARM_DESC(esas2r_max_sectors
,
301 "Maximum number of disk sectors in a single data transfer. "
302 "Default 65535 (largest possible setting).");
304 int interrupt_mode
= 1;
305 module_param(interrupt_mode
, int, 0);
306 MODULE_PARM_DESC(interrupt_mode
,
307 "Defines the interrupt mode to use. 0 for legacy"
308 ", 1 for MSI. Default is MSI (1).");
310 static const struct pci_device_id
311 esas2r_pci_table
[] = {
312 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x0049,
315 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004A,
318 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004B,
321 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004C,
324 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004D,
327 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004E,
335 MODULE_DEVICE_TABLE(pci
, esas2r_pci_table
);
338 esas2r_probe(struct pci_dev
*pcid
, const struct pci_device_id
*id
);
341 esas2r_remove(struct pci_dev
*pcid
);
343 static struct pci_driver
344 esas2r_pci_driver
= {
345 .name
= ESAS2R_DRVR_NAME
,
346 .id_table
= esas2r_pci_table
,
347 .probe
= esas2r_probe
,
348 .remove
= esas2r_remove
,
349 .driver
.pm
= &esas2r_pm_ops
,
352 static int esas2r_probe(struct pci_dev
*pcid
,
353 const struct pci_device_id
*id
)
355 struct Scsi_Host
*host
= NULL
;
356 struct esas2r_adapter
*a
;
359 size_t host_alloc_size
= sizeof(struct esas2r_adapter
)
361 1) * sizeof(struct esas2r_request
);
363 esas2r_log_dev(ESAS2R_LOG_DEBG
, &(pcid
->dev
),
364 "esas2r_probe() 0x%02x 0x%02x 0x%02x 0x%02x",
367 pcid
->subsystem_vendor
,
368 pcid
->subsystem_device
);
370 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
371 "before pci_enable_device() "
373 pcid
->enable_cnt
.counter
);
375 err
= pci_enable_device(pcid
);
377 esas2r_log_dev(ESAS2R_LOG_CRIT
, &(pcid
->dev
),
378 "pci_enable_device() FAIL (%d)",
383 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
384 "pci_enable_device() OK");
385 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
386 "after pci_enable_device() enable_cnt: %d",
387 pcid
->enable_cnt
.counter
);
389 host
= scsi_host_alloc(&driver_template
, host_alloc_size
);
391 esas2r_log(ESAS2R_LOG_CRIT
, "scsi_host_alloc() FAIL");
395 memset(host
->hostdata
, 0, host_alloc_size
);
397 a
= (struct esas2r_adapter
*)host
->hostdata
;
399 esas2r_log(ESAS2R_LOG_INFO
, "scsi_host_alloc() OK host: %p", host
);
401 /* override max LUN and max target id */
403 host
->max_id
= ESAS2R_MAX_ID
+ 1;
406 /* we can handle 16-byte CDbs */
408 host
->max_cmd_len
= 16;
410 host
->can_queue
= can_queue
;
411 host
->cmd_per_lun
= cmd_per_lun
;
412 host
->this_id
= host
->max_id
+ 1;
413 host
->max_channel
= 0;
414 host
->unique_id
= found_adapters
;
415 host
->sg_tablesize
= sg_tablesize
;
416 host
->max_sectors
= esas2r_max_sectors
;
418 /* set to bus master for BIOses that don't do it for us */
420 esas2r_log(ESAS2R_LOG_INFO
, "pci_set_master() called");
422 pci_set_master(pcid
);
424 if (!esas2r_init_adapter(host
, pcid
, found_adapters
)) {
425 esas2r_log(ESAS2R_LOG_CRIT
,
426 "unable to initialize device at PCI bus %x:%x",
430 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
431 "scsi_host_put() called");
439 esas2r_log(ESAS2R_LOG_INFO
, "pci_set_drvdata(%p, %p) called", pcid
,
442 pci_set_drvdata(pcid
, host
);
444 esas2r_log(ESAS2R_LOG_INFO
, "scsi_add_host() called");
446 err
= scsi_add_host(host
, &pcid
->dev
);
449 esas2r_log(ESAS2R_LOG_CRIT
, "scsi_add_host returned %d", err
);
450 esas2r_log_dev(ESAS2R_LOG_CRIT
, &(host
->shost_gendev
),
451 "scsi_add_host() FAIL");
453 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
454 "scsi_host_put() called");
458 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
459 "pci_set_drvdata(%p, NULL) called",
462 pci_set_drvdata(pcid
, NULL
);
468 esas2r_fw_event_on(a
);
470 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
471 "scsi_scan_host() called");
473 scsi_scan_host(host
);
475 /* Add sysfs binary files */
476 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_fw
))
477 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
478 "Failed to create sysfs binary file: fw");
480 a
->sysfs_fw_created
= 1;
482 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_fs
))
483 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
484 "Failed to create sysfs binary file: fs");
486 a
->sysfs_fs_created
= 1;
488 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_vda
))
489 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
490 "Failed to create sysfs binary file: vda");
492 a
->sysfs_vda_created
= 1;
494 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_hw
))
495 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
496 "Failed to create sysfs binary file: hw");
498 a
->sysfs_hw_created
= 1;
500 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_live_nvram
))
501 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
502 "Failed to create sysfs binary file: live_nvram");
504 a
->sysfs_live_nvram_created
= 1;
506 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
,
507 &bin_attr_default_nvram
))
508 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
509 "Failed to create sysfs binary file: default_nvram");
511 a
->sysfs_default_nvram_created
= 1;
518 static void esas2r_remove(struct pci_dev
*pdev
)
520 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
521 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)host
->hostdata
;
523 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pdev
->dev
),
524 "esas2r_remove(%p) called; "
528 esas2r_kill_adapter(a
->index
);
532 static int __init
esas2r_init(void)
536 esas2r_log(ESAS2R_LOG_INFO
, "%s called", __func__
);
538 /* verify valid parameters */
541 esas2r_log(ESAS2R_LOG_WARN
,
542 "warning: can_queue must be at least 1, value "
545 } else if (can_queue
> 2048) {
546 esas2r_log(ESAS2R_LOG_WARN
,
547 "warning: can_queue must be no larger than 2048, "
552 if (cmd_per_lun
< 1) {
553 esas2r_log(ESAS2R_LOG_WARN
,
554 "warning: cmd_per_lun must be at least 1, value "
557 } else if (cmd_per_lun
> 2048) {
558 esas2r_log(ESAS2R_LOG_WARN
,
559 "warning: cmd_per_lun must be no larger than "
560 "2048, value forced.");
564 if (sg_tablesize
< 32) {
565 esas2r_log(ESAS2R_LOG_WARN
,
566 "warning: sg_tablesize must be at least 32, "
571 if (esas2r_max_sectors
< 1) {
572 esas2r_log(ESAS2R_LOG_WARN
,
573 "warning: esas2r_max_sectors must be at least "
575 esas2r_max_sectors
= 1;
576 } else if (esas2r_max_sectors
> 0xffff) {
577 esas2r_log(ESAS2R_LOG_WARN
,
578 "warning: esas2r_max_sectors must be no larger "
579 "than 0xffff, value forced.");
580 esas2r_max_sectors
= 0xffff;
583 sgl_page_size
&= ~(ESAS2R_SGL_ALIGN
- 1);
585 if (sgl_page_size
< SGL_PG_SZ_MIN
)
586 sgl_page_size
= SGL_PG_SZ_MIN
;
587 else if (sgl_page_size
> SGL_PG_SZ_MAX
)
588 sgl_page_size
= SGL_PG_SZ_MAX
;
590 if (num_sg_lists
< NUM_SGL_MIN
)
591 num_sg_lists
= NUM_SGL_MIN
;
592 else if (num_sg_lists
> NUM_SGL_MAX
)
593 num_sg_lists
= NUM_SGL_MAX
;
595 if (num_requests
< NUM_REQ_MIN
)
596 num_requests
= NUM_REQ_MIN
;
597 else if (num_requests
> NUM_REQ_MAX
)
598 num_requests
= NUM_REQ_MAX
;
600 if (num_ae_requests
< NUM_AE_MIN
)
601 num_ae_requests
= NUM_AE_MIN
;
602 else if (num_ae_requests
> NUM_AE_MAX
)
603 num_ae_requests
= NUM_AE_MAX
;
605 /* set up other globals */
607 for (i
= 0; i
< MAX_ADAPTERS
; i
++)
608 esas2r_adapters
[i
] = NULL
;
610 return pci_register_driver(&esas2r_pci_driver
);
613 /* Handle ioctl calls to "/proc/scsi/esas2r/ATTOnode" */
614 static const struct file_operations esas2r_proc_fops
= {
615 .compat_ioctl
= compat_ptr_ioctl
,
616 .unlocked_ioctl
= esas2r_proc_ioctl
,
619 static const struct proc_ops esas2r_proc_ops
= {
620 .proc_ioctl
= esas2r_proc_ioctl
,
622 .proc_compat_ioctl
= compat_ptr_ioctl
,
626 static struct Scsi_Host
*esas2r_proc_host
;
627 static int esas2r_proc_major
;
629 long esas2r_proc_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
631 return esas2r_ioctl_handler(esas2r_proc_host
->hostdata
,
632 cmd
, (void __user
*)arg
);
635 static void __exit
esas2r_exit(void)
637 esas2r_log(ESAS2R_LOG_INFO
, "%s called", __func__
);
639 if (esas2r_proc_major
> 0) {
640 esas2r_log(ESAS2R_LOG_INFO
, "unregister proc");
642 remove_proc_entry(ATTONODE_NAME
,
643 esas2r_proc_host
->hostt
->proc_dir
);
644 unregister_chrdev(esas2r_proc_major
, ESAS2R_DRVR_NAME
);
646 esas2r_proc_major
= 0;
649 esas2r_log(ESAS2R_LOG_INFO
, "pci_unregister_driver() called");
651 pci_unregister_driver(&esas2r_pci_driver
);
654 int esas2r_show_info(struct seq_file
*m
, struct Scsi_Host
*sh
)
656 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)sh
->hostdata
;
658 struct esas2r_target
*t
;
661 esas2r_log(ESAS2R_LOG_DEBG
, "esas2r_show_info (%p,%d)", m
, sh
->host_no
);
663 seq_printf(m
, ESAS2R_LONGNAME
"\n"
664 "Driver version: "ESAS2R_VERSION_STR
"\n"
665 "Flash version: %s\n"
666 "Firmware version: %s\n"
667 "Copyright "ESAS2R_COPYRIGHT_YEARS
"\n"
668 "http://www.attotech.com\n"
671 a
->fw_rev
[0] ? a
->fw_rev
: "(none)");
674 seq_printf(m
, "Adapter information:\n"
675 "--------------------\n"
677 "SAS address: %02X%02X%02X%02X:%02X%02X%02X%02X\n",
678 esas2r_get_model_name(a
),
679 a
->nvram
->sas_addr
[0],
680 a
->nvram
->sas_addr
[1],
681 a
->nvram
->sas_addr
[2],
682 a
->nvram
->sas_addr
[3],
683 a
->nvram
->sas_addr
[4],
684 a
->nvram
->sas_addr
[5],
685 a
->nvram
->sas_addr
[6],
686 a
->nvram
->sas_addr
[7]);
689 "Discovered devices:\n"
692 "---------------\n");
694 for (t
= a
->targetdb
; t
< a
->targetdb_end
; t
++)
695 if (t
->buffered_target_state
== TS_PRESENT
) {
696 seq_printf(m
, " %3d %3d\n",
698 (u16
)(uintptr_t)(t
- a
->targetdb
));
702 seq_puts(m
, "none\n");
709 const char *esas2r_info(struct Scsi_Host
*sh
)
711 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)sh
->hostdata
;
712 static char esas2r_info_str
[512];
714 esas2r_log_dev(ESAS2R_LOG_INFO
, &(sh
->shost_gendev
),
715 "esas2r_info() called");
718 * if we haven't done so already, register as a char driver
719 * and stick a node under "/proc/scsi/esas2r/ATTOnode"
722 if (esas2r_proc_major
<= 0) {
723 esas2r_proc_host
= sh
;
725 esas2r_proc_major
= register_chrdev(0, ESAS2R_DRVR_NAME
,
728 esas2r_log_dev(ESAS2R_LOG_DEBG
, &(sh
->shost_gendev
),
729 "register_chrdev (major %d)",
732 if (esas2r_proc_major
> 0) {
733 struct proc_dir_entry
*pde
;
735 pde
= proc_create(ATTONODE_NAME
, 0,
740 esas2r_log_dev(ESAS2R_LOG_WARN
,
742 "failed to create_proc_entry");
743 esas2r_proc_major
= -1;
748 sprintf(esas2r_info_str
,
749 ESAS2R_LONGNAME
" (bus 0x%02X, device 0x%02X, IRQ 0x%02X)"
750 " driver version: "ESAS2R_VERSION_STR
" firmware version: "
752 a
->pcid
->bus
->number
, a
->pcid
->devfn
, a
->pcid
->irq
,
753 a
->fw_rev
[0] ? a
->fw_rev
: "(none)");
755 return esas2r_info_str
;
758 /* Callback for building a request scatter/gather list */
759 static u32
get_physaddr_from_sgc(struct esas2r_sg_context
*sgc
, u64
*addr
)
763 if (likely(sgc
->cur_offset
== sgc
->exp_offset
)) {
765 * the normal case: caller used all bytes from previous call, so
766 * expected offset is the same as the current offset.
769 if (sgc
->sgel_count
< sgc
->num_sgel
) {
770 /* retrieve next segment, except for first time */
771 if (sgc
->exp_offset
> (u8
*)0) {
772 /* advance current segment */
773 sgc
->cur_sgel
= sg_next(sgc
->cur_sgel
);
778 len
= sg_dma_len(sgc
->cur_sgel
);
779 (*addr
) = sg_dma_address(sgc
->cur_sgel
);
781 /* save the total # bytes returned to caller so far */
782 sgc
->exp_offset
+= len
;
787 } else if (sgc
->cur_offset
< sgc
->exp_offset
) {
789 * caller did not use all bytes from previous call. need to
790 * compute the address based on current segment.
793 len
= sg_dma_len(sgc
->cur_sgel
);
794 (*addr
) = sg_dma_address(sgc
->cur_sgel
);
796 sgc
->exp_offset
-= len
;
798 /* calculate PA based on prev segment address and offsets */
800 (sgc
->cur_offset
- sgc
->exp_offset
);
802 sgc
->exp_offset
+= len
;
804 /* re-calculate length based on offset */
806 sgc
->exp_offset
- sgc
->cur_offset
);
807 } else { /* if ( sgc->cur_offset > sgc->exp_offset ) */
809 * we don't expect the caller to skip ahead.
810 * cur_offset will never exceed the len we return
818 int esas2r_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
820 struct esas2r_adapter
*a
=
821 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
822 struct esas2r_request
*rq
;
823 struct esas2r_sg_context sgc
;
826 /* Assume success, if it fails we will fix the result later. */
827 cmd
->result
= DID_OK
<< 16;
829 if (unlikely(test_bit(AF_DEGRADED_MODE
, &a
->flags
))) {
830 cmd
->result
= DID_NO_CONNECT
<< 16;
835 rq
= esas2r_alloc_request(a
);
836 if (unlikely(rq
== NULL
)) {
837 esas2r_debug("esas2r_alloc_request failed");
838 return SCSI_MLQUEUE_HOST_BUSY
;
842 bufflen
= scsi_bufflen(cmd
);
844 if (likely(bufflen
!= 0)) {
845 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
846 rq
->vrq
->scsi
.flags
|= cpu_to_le32(FCP_CMND_WRD
);
847 else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
848 rq
->vrq
->scsi
.flags
|= cpu_to_le32(FCP_CMND_RDD
);
851 memcpy(rq
->vrq
->scsi
.cdb
, cmd
->cmnd
, cmd
->cmd_len
);
852 rq
->vrq
->scsi
.length
= cpu_to_le32(bufflen
);
853 rq
->target_id
= cmd
->device
->id
;
854 rq
->vrq
->scsi
.flags
|= cpu_to_le32(cmd
->device
->lun
);
855 rq
->sense_buf
= cmd
->sense_buffer
;
856 rq
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
858 esas2r_sgc_init(&sgc
, a
, rq
, NULL
);
860 sgc
.length
= bufflen
;
861 sgc
.cur_offset
= NULL
;
863 sgc
.cur_sgel
= scsi_sglist(cmd
);
864 sgc
.exp_offset
= NULL
;
865 sgc
.num_sgel
= scsi_dma_map(cmd
);
868 if (unlikely(sgc
.num_sgel
< 0)) {
869 esas2r_free_request(a
, rq
);
870 return SCSI_MLQUEUE_HOST_BUSY
;
873 sgc
.get_phys_addr
= (PGETPHYSADDR
)get_physaddr_from_sgc
;
875 if (unlikely(!esas2r_build_sg_list(a
, rq
, &sgc
))) {
877 esas2r_free_request(a
, rq
);
878 return SCSI_MLQUEUE_HOST_BUSY
;
881 esas2r_debug("start request %p to %d:%d\n", rq
, (int)cmd
->device
->id
,
882 (int)cmd
->device
->lun
);
884 esas2r_start_request(a
, rq
);
889 static void complete_task_management_request(struct esas2r_adapter
*a
,
890 struct esas2r_request
*rq
)
892 (*rq
->task_management_status_ptr
) = rq
->req_stat
;
893 esas2r_free_request(a
, rq
);
897 * Searches the specified queue for the specified queue for the command
900 * Return 0 on failure, 1 if command was not found, 2 if command was found
902 static int esas2r_check_active_queue(struct esas2r_adapter
*a
,
903 struct esas2r_request
**abort_request
,
904 struct scsi_cmnd
*cmd
,
905 struct list_head
*queue
)
908 struct esas2r_request
*ar
= *abort_request
;
909 struct esas2r_request
*rq
;
910 struct list_head
*element
, *next
;
912 list_for_each_safe(element
, next
, queue
) {
914 rq
= list_entry(element
, struct esas2r_request
, req_list
);
916 if (rq
->cmd
== cmd
) {
918 /* Found the request. See what to do with it. */
919 if (queue
== &a
->active_list
) {
921 * We are searching the active queue, which
922 * means that we need to send an abort request
925 ar
= esas2r_alloc_request(a
);
927 esas2r_log_dev(ESAS2R_LOG_WARN
,
928 &(a
->host
->shost_gendev
),
929 "unable to allocate an abort request for cmd %p",
931 return 0; /* Failure */
935 * Task management request must be formatted
939 ar
->vrq
->scsi
.length
= 0;
940 ar
->target_id
= rq
->target_id
;
941 ar
->vrq
->scsi
.flags
|= cpu_to_le32(
942 (u8
)le32_to_cpu(rq
->vrq
->scsi
.flags
));
944 memset(ar
->vrq
->scsi
.cdb
, 0,
945 sizeof(ar
->vrq
->scsi
.cdb
));
947 ar
->vrq
->scsi
.flags
|= cpu_to_le32(
949 ar
->vrq
->scsi
.u
.abort_handle
=
950 rq
->vrq
->scsi
.handle
;
953 * The request is pending but not active on
954 * the firmware. Just free it now and we'll
955 * report the successful abort below.
957 list_del_init(&rq
->req_list
);
958 esas2r_free_request(a
, rq
);
968 return 1; /* Not found */
970 return 2; /* found */
975 int esas2r_eh_abort(struct scsi_cmnd
*cmd
)
977 struct esas2r_adapter
*a
=
978 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
979 struct esas2r_request
*abort_request
= NULL
;
981 struct list_head
*queue
;
984 esas2r_log(ESAS2R_LOG_INFO
, "eh_abort (%p)", cmd
);
986 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
)) {
987 cmd
->result
= DID_ABORT
<< 16;
989 scsi_set_resid(cmd
, 0);
996 spin_lock_irqsave(&a
->queue_lock
, flags
);
999 * Run through the defer and active queues looking for the request
1003 queue
= &a
->defer_list
;
1007 result
= esas2r_check_active_queue(a
, &abort_request
, cmd
, queue
);
1010 spin_unlock_irqrestore(&a
->queue_lock
, flags
);
1012 } else if (result
== 2 && (queue
== &a
->defer_list
)) {
1013 queue
= &a
->active_list
;
1014 goto check_active_queue
;
1017 spin_unlock_irqrestore(&a
->queue_lock
, flags
);
1019 if (abort_request
) {
1020 u8 task_management_status
= RS_PENDING
;
1023 * the request is already active, so we need to tell
1024 * the firmware to abort it and wait for the response.
1027 abort_request
->comp_cb
= complete_task_management_request
;
1028 abort_request
->task_management_status_ptr
=
1029 &task_management_status
;
1031 esas2r_start_request(a
, abort_request
);
1033 if (atomic_read(&a
->disable_cnt
) == 0)
1034 esas2r_do_deferred_processes(a
);
1036 while (task_management_status
== RS_PENDING
)
1040 * Once we get here, the original request will have been
1041 * completed by the firmware and the abort request will have
1042 * been cleaned up. we're done!
1049 * If we get here, either we found the inactive request and
1050 * freed it, or we didn't find it at all. Either way, success!
1053 cmd
->result
= DID_ABORT
<< 16;
1055 scsi_set_resid(cmd
, 0);
1057 cmd
->scsi_done(cmd
);
1062 static int esas2r_host_bus_reset(struct scsi_cmnd
*cmd
, bool host_reset
)
1064 struct esas2r_adapter
*a
=
1065 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
1067 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1071 esas2r_reset_adapter(a
);
1073 esas2r_reset_bus(a
);
1075 /* above call sets the AF_OS_RESET flag. wait for it to clear. */
1077 while (test_bit(AF_OS_RESET
, &a
->flags
)) {
1080 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1084 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1090 int esas2r_host_reset(struct scsi_cmnd
*cmd
)
1092 esas2r_log(ESAS2R_LOG_INFO
, "host_reset (%p)", cmd
);
1094 return esas2r_host_bus_reset(cmd
, true);
1097 int esas2r_bus_reset(struct scsi_cmnd
*cmd
)
1099 esas2r_log(ESAS2R_LOG_INFO
, "bus_reset (%p)", cmd
);
1101 return esas2r_host_bus_reset(cmd
, false);
1104 static int esas2r_dev_targ_reset(struct scsi_cmnd
*cmd
, bool target_reset
)
1106 struct esas2r_adapter
*a
=
1107 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
1108 struct esas2r_request
*rq
;
1109 u8 task_management_status
= RS_PENDING
;
1112 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1116 rq
= esas2r_alloc_request(a
);
1119 esas2r_log(ESAS2R_LOG_CRIT
,
1120 "unable to allocate a request for a "
1121 "target reset (%d)!",
1124 esas2r_log(ESAS2R_LOG_CRIT
,
1125 "unable to allocate a request for a "
1126 "device reset (%d:%llu)!",
1135 rq
->target_id
= cmd
->device
->id
;
1136 rq
->vrq
->scsi
.flags
|= cpu_to_le32(cmd
->device
->lun
);
1137 rq
->req_stat
= RS_PENDING
;
1139 rq
->comp_cb
= complete_task_management_request
;
1140 rq
->task_management_status_ptr
= &task_management_status
;
1143 esas2r_debug("issuing target reset (%p) to id %d", rq
,
1145 completed
= esas2r_send_task_mgmt(a
, rq
, 0x20);
1147 esas2r_debug("issuing device reset (%p) to id %d lun %d", rq
,
1148 cmd
->device
->id
, cmd
->device
->lun
);
1149 completed
= esas2r_send_task_mgmt(a
, rq
, 0x10);
1153 /* Task management cmd completed right away, need to free it. */
1155 esas2r_free_request(a
, rq
);
1158 * Wait for firmware to complete the request. Completion
1159 * callback will free it.
1161 while (task_management_status
== RS_PENDING
)
1165 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1168 if (task_management_status
== RS_BUSY
) {
1170 * Busy, probably because we are flashing. Wait a bit and
1180 int esas2r_device_reset(struct scsi_cmnd
*cmd
)
1182 esas2r_log(ESAS2R_LOG_INFO
, "device_reset (%p)", cmd
);
1184 return esas2r_dev_targ_reset(cmd
, false);
1188 int esas2r_target_reset(struct scsi_cmnd
*cmd
)
1190 esas2r_log(ESAS2R_LOG_INFO
, "target_reset (%p)", cmd
);
1192 return esas2r_dev_targ_reset(cmd
, true);
1195 void esas2r_log_request_failure(struct esas2r_adapter
*a
,
1196 struct esas2r_request
*rq
)
1198 u8 reqstatus
= rq
->req_stat
;
1200 if (reqstatus
== RS_SUCCESS
)
1203 if (rq
->vrq
->scsi
.function
== VDA_FUNC_SCSI
) {
1204 if (reqstatus
== RS_SCSI_ERROR
) {
1205 if (rq
->func_rsp
.scsi_rsp
.sense_len
>= 13) {
1206 esas2r_log(ESAS2R_LOG_WARN
,
1207 "request failure - SCSI error %x ASC:%x ASCQ:%x CDB:%x",
1208 rq
->sense_buf
[2], rq
->sense_buf
[12],
1210 rq
->vrq
->scsi
.cdb
[0]);
1212 esas2r_log(ESAS2R_LOG_WARN
,
1213 "request failure - SCSI error CDB:%x\n",
1214 rq
->vrq
->scsi
.cdb
[0]);
1216 } else if ((rq
->vrq
->scsi
.cdb
[0] != INQUIRY
1217 && rq
->vrq
->scsi
.cdb
[0] != REPORT_LUNS
)
1218 || (reqstatus
!= RS_SEL
1219 && reqstatus
!= RS_SEL2
)) {
1220 if ((reqstatus
== RS_UNDERRUN
) &&
1221 (rq
->vrq
->scsi
.cdb
[0] == INQUIRY
)) {
1222 /* Don't log inquiry underruns */
1224 esas2r_log(ESAS2R_LOG_WARN
,
1225 "request failure - cdb:%x reqstatus:%d target:%d",
1226 rq
->vrq
->scsi
.cdb
[0], reqstatus
,
1233 void esas2r_wait_request(struct esas2r_adapter
*a
, struct esas2r_request
*rq
)
1238 starttime
= jiffies_to_msecs(jiffies
);
1239 timeout
= rq
->timeout
? rq
->timeout
: 5000;
1242 esas2r_polled_interrupt(a
);
1244 if (rq
->req_stat
!= RS_STARTED
)
1247 schedule_timeout_interruptible(msecs_to_jiffies(100));
1249 if ((jiffies_to_msecs(jiffies
) - starttime
) > timeout
) {
1250 esas2r_hdebug("request TMO");
1253 rq
->req_stat
= RS_TIMEOUT
;
1255 esas2r_local_reset_adapter(a
);
1261 u32
esas2r_map_data_window(struct esas2r_adapter
*a
, u32 addr_lo
)
1263 u32 offset
= addr_lo
& (MW_DATA_WINDOW_SIZE
- 1);
1264 u32 base
= addr_lo
& -(signed int)MW_DATA_WINDOW_SIZE
;
1266 if (a
->window_base
!= base
) {
1267 esas2r_write_register_dword(a
, MVR_PCI_WIN1_REMAP
,
1268 base
| MVRPW1R_ENABLE
);
1269 esas2r_flush_register_dword(a
, MVR_PCI_WIN1_REMAP
);
1270 a
->window_base
= base
;
1276 /* Read a block of data from chip memory */
1277 bool esas2r_read_mem_block(struct esas2r_adapter
*a
,
1289 iatvr
= (from
& -(signed int)MW_DATA_WINDOW_SIZE
);
1291 esas2r_map_data_window(a
, iatvr
);
1293 offset
= from
& (MW_DATA_WINDOW_SIZE
- 1);
1296 if (len
> MW_DATA_WINDOW_SIZE
- offset
)
1297 len
= MW_DATA_WINDOW_SIZE
- offset
;
1303 *end
++ = esas2r_read_data_byte(a
, offset
);
1311 void esas2r_nuxi_mgt_data(u8 function
, void *data
)
1313 struct atto_vda_grp_info
*g
;
1314 struct atto_vda_devinfo
*d
;
1315 struct atto_vdapart_info
*p
;
1316 struct atto_vda_dh_info
*h
;
1317 struct atto_vda_metrics_info
*m
;
1318 struct atto_vda_schedule_info
*s
;
1319 struct atto_vda_buzzer_info
*b
;
1323 case VDAMGT_BUZZER_INFO
:
1324 case VDAMGT_BUZZER_SET
:
1326 b
= (struct atto_vda_buzzer_info
*)data
;
1328 b
->duration
= le32_to_cpu(b
->duration
);
1331 case VDAMGT_SCHEDULE_INFO
:
1332 case VDAMGT_SCHEDULE_EVENT
:
1334 s
= (struct atto_vda_schedule_info
*)data
;
1336 s
->id
= le32_to_cpu(s
->id
);
1340 case VDAMGT_DEV_INFO
:
1341 case VDAMGT_DEV_CLEAN
:
1342 case VDAMGT_DEV_PT_INFO
:
1343 case VDAMGT_DEV_FEATURES
:
1344 case VDAMGT_DEV_PT_FEATURES
:
1345 case VDAMGT_DEV_OPERATION
:
1347 d
= (struct atto_vda_devinfo
*)data
;
1349 d
->capacity
= le64_to_cpu(d
->capacity
);
1350 d
->block_size
= le32_to_cpu(d
->block_size
);
1351 d
->ses_dev_index
= le16_to_cpu(d
->ses_dev_index
);
1352 d
->target_id
= le16_to_cpu(d
->target_id
);
1353 d
->lun
= le16_to_cpu(d
->lun
);
1354 d
->features
= le16_to_cpu(d
->features
);
1357 case VDAMGT_GRP_INFO
:
1358 case VDAMGT_GRP_CREATE
:
1359 case VDAMGT_GRP_DELETE
:
1360 case VDAMGT_ADD_STORAGE
:
1361 case VDAMGT_MEMBER_ADD
:
1362 case VDAMGT_GRP_COMMIT
:
1363 case VDAMGT_GRP_REBUILD
:
1364 case VDAMGT_GRP_COMMIT_INIT
:
1365 case VDAMGT_QUICK_RAID
:
1366 case VDAMGT_GRP_FEATURES
:
1367 case VDAMGT_GRP_COMMIT_INIT_AUTOMAP
:
1368 case VDAMGT_QUICK_RAID_INIT_AUTOMAP
:
1369 case VDAMGT_SPARE_LIST
:
1370 case VDAMGT_SPARE_ADD
:
1371 case VDAMGT_SPARE_REMOVE
:
1372 case VDAMGT_LOCAL_SPARE_ADD
:
1373 case VDAMGT_GRP_OPERATION
:
1375 g
= (struct atto_vda_grp_info
*)data
;
1377 g
->capacity
= le64_to_cpu(g
->capacity
);
1378 g
->block_size
= le32_to_cpu(g
->block_size
);
1379 g
->interleave
= le32_to_cpu(g
->interleave
);
1380 g
->features
= le16_to_cpu(g
->features
);
1382 for (i
= 0; i
< 32; i
++)
1383 g
->members
[i
] = le16_to_cpu(g
->members
[i
]);
1387 case VDAMGT_PART_INFO
:
1388 case VDAMGT_PART_MAP
:
1389 case VDAMGT_PART_UNMAP
:
1390 case VDAMGT_PART_AUTOMAP
:
1391 case VDAMGT_PART_SPLIT
:
1392 case VDAMGT_PART_MERGE
:
1394 p
= (struct atto_vdapart_info
*)data
;
1396 p
->part_size
= le64_to_cpu(p
->part_size
);
1397 p
->start_lba
= le32_to_cpu(p
->start_lba
);
1398 p
->block_size
= le32_to_cpu(p
->block_size
);
1399 p
->target_id
= le16_to_cpu(p
->target_id
);
1402 case VDAMGT_DEV_HEALTH_REQ
:
1404 h
= (struct atto_vda_dh_info
*)data
;
1406 h
->med_defect_cnt
= le32_to_cpu(h
->med_defect_cnt
);
1407 h
->info_exc_cnt
= le32_to_cpu(h
->info_exc_cnt
);
1410 case VDAMGT_DEV_METRICS
:
1412 m
= (struct atto_vda_metrics_info
*)data
;
1414 for (i
= 0; i
< 32; i
++)
1415 m
->dev_indexes
[i
] = le16_to_cpu(m
->dev_indexes
[i
]);
1424 void esas2r_nuxi_cfg_data(u8 function
, void *data
)
1426 struct atto_vda_cfg_init
*ci
;
1430 case VDA_CFG_GET_INIT
:
1431 case VDA_CFG_GET_INIT2
:
1433 ci
= (struct atto_vda_cfg_init
*)data
;
1435 ci
->date_time
.year
= le16_to_cpu(ci
->date_time
.year
);
1436 ci
->sgl_page_size
= le32_to_cpu(ci
->sgl_page_size
);
1437 ci
->vda_version
= le32_to_cpu(ci
->vda_version
);
1438 ci
->epoch_time
= le32_to_cpu(ci
->epoch_time
);
1439 ci
->ioctl_tunnel
= le32_to_cpu(ci
->ioctl_tunnel
);
1440 ci
->num_targets_backend
= le32_to_cpu(ci
->num_targets_backend
);
1448 void esas2r_nuxi_ae_data(union atto_vda_ae
*ae
)
1450 struct atto_vda_ae_raid
*r
= &ae
->raid
;
1451 struct atto_vda_ae_lu
*l
= &ae
->lu
;
1453 switch (ae
->hdr
.bytype
) {
1454 case VDAAE_HDR_TYPE_RAID
:
1456 r
->dwflags
= le32_to_cpu(r
->dwflags
);
1459 case VDAAE_HDR_TYPE_LU
:
1461 l
->dwevent
= le32_to_cpu(l
->dwevent
);
1462 l
->wphys_target_id
= le16_to_cpu(l
->wphys_target_id
);
1463 l
->id
.tgtlun
.wtarget_id
= le16_to_cpu(l
->id
.tgtlun
.wtarget_id
);
1465 if (l
->hdr
.bylength
>= offsetof(struct atto_vda_ae_lu
, id
)
1466 + sizeof(struct atto_vda_ae_lu_tgt_lun_raid
)) {
1467 l
->id
.tgtlun_raid
.dwinterleave
1468 = le32_to_cpu(l
->id
.tgtlun_raid
.dwinterleave
);
1469 l
->id
.tgtlun_raid
.dwblock_size
1470 = le32_to_cpu(l
->id
.tgtlun_raid
.dwblock_size
);
1475 case VDAAE_HDR_TYPE_DISK
:
1481 void esas2r_free_request(struct esas2r_adapter
*a
, struct esas2r_request
*rq
)
1483 unsigned long flags
;
1485 esas2r_rq_destroy_request(rq
, a
);
1486 spin_lock_irqsave(&a
->request_lock
, flags
);
1487 list_add(&rq
->comp_list
, &a
->avail_request
);
1488 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1491 struct esas2r_request
*esas2r_alloc_request(struct esas2r_adapter
*a
)
1493 struct esas2r_request
*rq
;
1494 unsigned long flags
;
1496 spin_lock_irqsave(&a
->request_lock
, flags
);
1498 if (unlikely(list_empty(&a
->avail_request
))) {
1499 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1503 rq
= list_first_entry(&a
->avail_request
, struct esas2r_request
,
1505 list_del(&rq
->comp_list
);
1506 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1507 esas2r_rq_init_request(rq
, a
);
1513 void esas2r_complete_request_cb(struct esas2r_adapter
*a
,
1514 struct esas2r_request
*rq
)
1516 esas2r_debug("completing request %p\n", rq
);
1518 scsi_dma_unmap(rq
->cmd
);
1520 if (unlikely(rq
->req_stat
!= RS_SUCCESS
)) {
1521 esas2r_debug("[%x STATUS %x:%x (%x)]", rq
->target_id
,
1523 rq
->func_rsp
.scsi_rsp
.scsi_stat
,
1527 ((esas2r_req_status_to_error(rq
->req_stat
) << 16)
1528 | (rq
->func_rsp
.scsi_rsp
.scsi_stat
& STATUS_MASK
));
1530 if (rq
->req_stat
== RS_UNDERRUN
)
1531 scsi_set_resid(rq
->cmd
,
1532 le32_to_cpu(rq
->func_rsp
.scsi_rsp
.
1535 scsi_set_resid(rq
->cmd
, 0);
1538 rq
->cmd
->scsi_done(rq
->cmd
);
1540 esas2r_free_request(a
, rq
);
1543 /* Run tasklet to handle stuff outside of interrupt context. */
1544 void esas2r_adapter_tasklet(unsigned long context
)
1546 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)context
;
1548 if (unlikely(test_bit(AF2_TIMER_TICK
, &a
->flags2
))) {
1549 clear_bit(AF2_TIMER_TICK
, &a
->flags2
);
1550 esas2r_timer_tick(a
);
1553 if (likely(test_bit(AF2_INT_PENDING
, &a
->flags2
))) {
1554 clear_bit(AF2_INT_PENDING
, &a
->flags2
);
1555 esas2r_adapter_interrupt(a
);
1558 if (esas2r_is_tasklet_pending(a
))
1559 esas2r_do_tasklet_tasks(a
);
1561 if (esas2r_is_tasklet_pending(a
)
1562 || (test_bit(AF2_INT_PENDING
, &a
->flags2
))
1563 || (test_bit(AF2_TIMER_TICK
, &a
->flags2
))) {
1564 clear_bit(AF_TASKLET_SCHEDULED
, &a
->flags
);
1565 esas2r_schedule_tasklet(a
);
1567 clear_bit(AF_TASKLET_SCHEDULED
, &a
->flags
);
1571 static void esas2r_timer_callback(struct timer_list
*t
);
1573 void esas2r_kickoff_timer(struct esas2r_adapter
*a
)
1575 timer_setup(&a
->timer
, esas2r_timer_callback
, 0);
1577 a
->timer
.expires
= jiffies
+
1578 msecs_to_jiffies(100);
1580 add_timer(&a
->timer
);
1583 static void esas2r_timer_callback(struct timer_list
*t
)
1585 struct esas2r_adapter
*a
= from_timer(a
, t
, timer
);
1587 set_bit(AF2_TIMER_TICK
, &a
->flags2
);
1589 esas2r_schedule_tasklet(a
);
1591 esas2r_kickoff_timer(a
);
1595 * Firmware events need to be handled outside of interrupt context
1596 * so we schedule a delayed_work to handle them.
1600 esas2r_free_fw_event(struct esas2r_fw_event_work
*fw_event
)
1602 unsigned long flags
;
1603 struct esas2r_adapter
*a
= fw_event
->a
;
1605 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1606 list_del(&fw_event
->list
);
1608 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1612 esas2r_fw_event_off(struct esas2r_adapter
*a
)
1614 unsigned long flags
;
1616 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1617 a
->fw_events_off
= 1;
1618 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1622 esas2r_fw_event_on(struct esas2r_adapter
*a
)
1624 unsigned long flags
;
1626 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1627 a
->fw_events_off
= 0;
1628 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1631 static void esas2r_add_device(struct esas2r_adapter
*a
, u16 target_id
)
1634 struct scsi_device
*scsi_dev
;
1636 scsi_dev
= scsi_device_lookup(a
->host
, 0, target_id
, 0);
1643 "scsi device already exists at id %d", target_id
);
1645 scsi_device_put(scsi_dev
);
1651 "scsi_add_device() called for 0:%d:0",
1654 ret
= scsi_add_device(a
->host
, 0, target_id
, 0);
1660 "scsi_add_device failed with %d for id %d",
1666 static void esas2r_remove_device(struct esas2r_adapter
*a
, u16 target_id
)
1668 struct scsi_device
*scsi_dev
;
1670 scsi_dev
= scsi_device_lookup(a
->host
, 0, target_id
, 0);
1673 scsi_device_set_state(scsi_dev
, SDEV_OFFLINE
);
1679 "scsi_remove_device() called for 0:%d:0",
1682 scsi_remove_device(scsi_dev
);
1688 "scsi_device_put() called");
1690 scsi_device_put(scsi_dev
);
1694 &(a
->host
->shost_gendev
),
1695 "no target found at id %d",
1701 * Sends a firmware asynchronous event to anyone who happens to be
1702 * listening on the defined ATTO VDA event ports.
1704 static void esas2r_send_ae_event(struct esas2r_fw_event_work
*fw_event
)
1706 struct esas2r_vda_ae
*ae
= (struct esas2r_vda_ae
*)fw_event
->data
;
1709 switch (ae
->vda_ae
.hdr
.bytype
) {
1710 case VDAAE_HDR_TYPE_RAID
:
1711 type
= "RAID group state change";
1714 case VDAAE_HDR_TYPE_LU
:
1715 type
= "Mapped destination LU change";
1718 case VDAAE_HDR_TYPE_DISK
:
1719 type
= "Physical disk inventory change";
1722 case VDAAE_HDR_TYPE_RESET
:
1723 type
= "Firmware reset";
1726 case VDAAE_HDR_TYPE_LOG_INFO
:
1727 type
= "Event Log message (INFO level)";
1730 case VDAAE_HDR_TYPE_LOG_WARN
:
1731 type
= "Event Log message (WARN level)";
1734 case VDAAE_HDR_TYPE_LOG_CRIT
:
1735 type
= "Event Log message (CRIT level)";
1738 case VDAAE_HDR_TYPE_LOG_FAIL
:
1739 type
= "Event Log message (FAIL level)";
1742 case VDAAE_HDR_TYPE_NVC
:
1743 type
= "NVCache change";
1746 case VDAAE_HDR_TYPE_TLG_INFO
:
1747 type
= "Time stamped log message (INFO level)";
1750 case VDAAE_HDR_TYPE_TLG_WARN
:
1751 type
= "Time stamped log message (WARN level)";
1754 case VDAAE_HDR_TYPE_TLG_CRIT
:
1755 type
= "Time stamped log message (CRIT level)";
1758 case VDAAE_HDR_TYPE_PWRMGT
:
1759 type
= "Power management";
1762 case VDAAE_HDR_TYPE_MUTE
:
1763 type
= "Mute button pressed";
1766 case VDAAE_HDR_TYPE_DEV
:
1767 type
= "Device attribute change";
1775 esas2r_log(ESAS2R_LOG_WARN
,
1776 "An async event of type \"%s\" was received from the firmware. The event contents are:",
1778 esas2r_log_hexdump(ESAS2R_LOG_WARN
, &ae
->vda_ae
,
1779 ae
->vda_ae
.hdr
.bylength
);
1784 esas2r_firmware_event_work(struct work_struct
*work
)
1786 struct esas2r_fw_event_work
*fw_event
=
1787 container_of(work
, struct esas2r_fw_event_work
, work
.work
);
1789 struct esas2r_adapter
*a
= fw_event
->a
;
1791 u16 target_id
= *(u16
*)&fw_event
->data
[0];
1793 if (a
->fw_events_off
)
1796 switch (fw_event
->type
) {
1798 break; /* do nothing */
1800 case fw_event_lun_change
:
1801 esas2r_remove_device(a
, target_id
);
1802 esas2r_add_device(a
, target_id
);
1805 case fw_event_present
:
1806 esas2r_add_device(a
, target_id
);
1809 case fw_event_not_present
:
1810 esas2r_remove_device(a
, target_id
);
1813 case fw_event_vda_ae
:
1814 esas2r_send_ae_event(fw_event
);
1819 esas2r_free_fw_event(fw_event
);
1822 void esas2r_queue_fw_event(struct esas2r_adapter
*a
,
1823 enum fw_event_type type
,
1827 struct esas2r_fw_event_work
*fw_event
;
1828 unsigned long flags
;
1830 fw_event
= kzalloc(sizeof(struct esas2r_fw_event_work
), GFP_ATOMIC
);
1832 esas2r_log(ESAS2R_LOG_WARN
,
1833 "esas2r_queue_fw_event failed to alloc");
1837 if (type
== fw_event_vda_ae
) {
1838 struct esas2r_vda_ae
*ae
=
1839 (struct esas2r_vda_ae
*)fw_event
->data
;
1841 ae
->signature
= ESAS2R_VDA_EVENT_SIG
;
1842 ae
->bus_number
= a
->pcid
->bus
->number
;
1843 ae
->devfn
= a
->pcid
->devfn
;
1844 memcpy(&ae
->vda_ae
, data
, sizeof(ae
->vda_ae
));
1846 memcpy(fw_event
->data
, data
, data_sz
);
1849 fw_event
->type
= type
;
1852 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1853 list_add_tail(&fw_event
->list
, &a
->fw_event_list
);
1854 INIT_DELAYED_WORK(&fw_event
->work
, esas2r_firmware_event_work
);
1855 queue_delayed_work_on(
1856 smp_processor_id(), a
->fw_event_q
, &fw_event
->work
,
1857 msecs_to_jiffies(1));
1858 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1861 void esas2r_target_state_changed(struct esas2r_adapter
*a
, u16 targ_id
,
1864 if (state
== TS_LUN_CHANGE
)
1865 esas2r_queue_fw_event(a
, fw_event_lun_change
, &targ_id
,
1867 else if (state
== TS_PRESENT
)
1868 esas2r_queue_fw_event(a
, fw_event_present
, &targ_id
,
1870 else if (state
== TS_NOT_PRESENT
)
1871 esas2r_queue_fw_event(a
, fw_event_not_present
, &targ_id
,
1875 /* Translate status to a Linux SCSI mid-layer error code */
1876 int esas2r_req_status_to_error(u8 req_stat
)
1883 * NOTE: SCSI mid-layer wants a good status for a SCSI error, because
1884 * it will check the scsi_stat value in the completion anyway.
1891 return DID_NO_CONNECT
;
1900 return DID_BUS_BUSY
;
1903 /* everything else is just an error. */
1908 module_init(esas2r_init
);
1909 module_exit(esas2r_exit
);