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
= kzalloc(sizeof(struct atto_ioctl
),
199 if (a
->local_atto_ioctl
== NULL
) {
200 esas2r_log(ESAS2R_LOG_WARN
,
201 "write_hw kzalloc failed for %d 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
,
238 .release
= esas2r_release
,
240 .ioctl
= esas2r_ioctl
,
241 .queuecommand
= esas2r_queuecommand
,
242 .eh_abort_handler
= esas2r_eh_abort
,
243 .eh_device_reset_handler
= esas2r_device_reset
,
244 .eh_bus_reset_handler
= esas2r_bus_reset
,
245 .eh_host_reset_handler
= esas2r_host_reset
,
246 .eh_target_reset_handler
= esas2r_target_reset
,
249 .sg_tablesize
= SCSI_MAX_SG_SEGMENTS
,
251 ESAS2R_DEFAULT_CMD_PER_LUN
,
253 .unchecked_isa_dma
= 0,
254 .use_clustering
= ENABLE_CLUSTERING
,
256 .proc_name
= ESAS2R_DRVR_NAME
,
257 .slave_configure
= esas2r_slave_configure
,
258 .slave_alloc
= esas2r_slave_alloc
,
259 .slave_destroy
= esas2r_slave_destroy
,
260 .change_queue_depth
= esas2r_change_queue_depth
,
261 .change_queue_type
= esas2r_change_queue_type
,
262 .max_sectors
= 0xFFFF,
265 int sgl_page_size
= 512;
266 module_param(sgl_page_size
, int, 0);
267 MODULE_PARM_DESC(sgl_page_size
,
268 "Scatter/gather list (SGL) page size in number of S/G "
269 "entries. If your application is doing a lot of very large "
270 "transfers, you may want to increase the SGL page size. "
273 int num_sg_lists
= 1024;
274 module_param(num_sg_lists
, int, 0);
275 MODULE_PARM_DESC(num_sg_lists
,
276 "Number of scatter/gather lists. Default 1024.");
278 int sg_tablesize
= SCSI_MAX_SG_SEGMENTS
;
279 module_param(sg_tablesize
, int, 0);
280 MODULE_PARM_DESC(sg_tablesize
,
281 "Maximum number of entries in a scatter/gather table.");
283 int num_requests
= 256;
284 module_param(num_requests
, int, 0);
285 MODULE_PARM_DESC(num_requests
,
286 "Number of requests. Default 256.");
288 int num_ae_requests
= 4;
289 module_param(num_ae_requests
, int, 0);
290 MODULE_PARM_DESC(num_ae_requests
,
291 "Number of VDA asynchromous event requests. Default 4.");
293 int cmd_per_lun
= ESAS2R_DEFAULT_CMD_PER_LUN
;
294 module_param(cmd_per_lun
, int, 0);
295 MODULE_PARM_DESC(cmd_per_lun
,
296 "Maximum number of commands per LUN. Default "
297 DEFINED_NUM_TO_STR(ESAS2R_DEFAULT_CMD_PER_LUN
) ".");
300 module_param(can_queue
, int, 0);
301 MODULE_PARM_DESC(can_queue
,
302 "Maximum number of commands per adapter. Default 128.");
304 int esas2r_max_sectors
= 0xFFFF;
305 module_param(esas2r_max_sectors
, int, 0);
306 MODULE_PARM_DESC(esas2r_max_sectors
,
307 "Maximum number of disk sectors in a single data transfer. "
308 "Default 65535 (largest possible setting).");
310 int interrupt_mode
= 1;
311 module_param(interrupt_mode
, int, 0);
312 MODULE_PARM_DESC(interrupt_mode
,
313 "Defines the interrupt mode to use. 0 for legacy"
314 ", 1 for MSI. Default is MSI (1).");
316 static struct pci_device_id
317 esas2r_pci_table
[] = {
318 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x0049,
321 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004A,
324 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004B,
327 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004C,
330 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004D,
333 { ATTO_VENDOR_ID
, 0x0049, ATTO_VENDOR_ID
, 0x004E,
341 MODULE_DEVICE_TABLE(pci
, esas2r_pci_table
);
344 esas2r_probe(struct pci_dev
*pcid
, const struct pci_device_id
*id
);
347 esas2r_remove(struct pci_dev
*pcid
);
349 static struct pci_driver
350 esas2r_pci_driver
= {
351 .name
= ESAS2R_DRVR_NAME
,
352 .id_table
= esas2r_pci_table
,
353 .probe
= esas2r_probe
,
354 .remove
= esas2r_remove
,
355 .suspend
= esas2r_suspend
,
356 .resume
= esas2r_resume
,
359 static int esas2r_probe(struct pci_dev
*pcid
,
360 const struct pci_device_id
*id
)
362 struct Scsi_Host
*host
= NULL
;
363 struct esas2r_adapter
*a
;
366 size_t host_alloc_size
= sizeof(struct esas2r_adapter
)
368 1) * sizeof(struct esas2r_request
);
370 esas2r_log_dev(ESAS2R_LOG_DEBG
, &(pcid
->dev
),
371 "esas2r_probe() 0x%02x 0x%02x 0x%02x 0x%02x",
374 pcid
->subsystem_vendor
,
375 pcid
->subsystem_device
);
377 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
378 "before pci_enable_device() "
380 pcid
->enable_cnt
.counter
);
382 err
= pci_enable_device(pcid
);
384 esas2r_log_dev(ESAS2R_LOG_CRIT
, &(pcid
->dev
),
385 "pci_enable_device() FAIL (%d)",
390 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
391 "pci_enable_device() OK");
392 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pcid
->dev
),
393 "after pci_device_enable() enable_cnt: %d",
394 pcid
->enable_cnt
.counter
);
396 host
= scsi_host_alloc(&driver_template
, host_alloc_size
);
398 esas2r_log(ESAS2R_LOG_CRIT
, "scsi_host_alloc() FAIL");
402 memset(host
->hostdata
, 0, host_alloc_size
);
404 a
= (struct esas2r_adapter
*)host
->hostdata
;
406 esas2r_log(ESAS2R_LOG_INFO
, "scsi_host_alloc() OK host: %p", host
);
408 /* override max LUN and max target id */
410 host
->max_id
= ESAS2R_MAX_ID
+ 1;
413 /* we can handle 16-byte CDbs */
415 host
->max_cmd_len
= 16;
417 host
->can_queue
= can_queue
;
418 host
->cmd_per_lun
= cmd_per_lun
;
419 host
->this_id
= host
->max_id
+ 1;
420 host
->max_channel
= 0;
421 host
->unique_id
= found_adapters
;
422 host
->sg_tablesize
= sg_tablesize
;
423 host
->max_sectors
= esas2r_max_sectors
;
425 /* set to bus master for BIOses that don't do it for us */
427 esas2r_log(ESAS2R_LOG_INFO
, "pci_set_master() called");
429 pci_set_master(pcid
);
431 if (!esas2r_init_adapter(host
, pcid
, found_adapters
)) {
432 esas2r_log(ESAS2R_LOG_CRIT
,
433 "unable to initialize device at PCI bus %x:%x",
437 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
438 "scsi_host_put() called");
446 esas2r_log(ESAS2R_LOG_INFO
, "pci_set_drvdata(%p, %p) called", pcid
,
449 pci_set_drvdata(pcid
, host
);
451 esas2r_log(ESAS2R_LOG_INFO
, "scsi_add_host() called");
453 err
= scsi_add_host(host
, &pcid
->dev
);
456 esas2r_log(ESAS2R_LOG_CRIT
, "scsi_add_host returned %d", err
);
457 esas2r_log_dev(ESAS2R_LOG_CRIT
, &(host
->shost_gendev
),
458 "scsi_add_host() FAIL");
460 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
461 "scsi_host_put() called");
465 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
466 "pci_set_drvdata(%p, NULL) called",
469 pci_set_drvdata(pcid
, NULL
);
475 esas2r_fw_event_on(a
);
477 esas2r_log_dev(ESAS2R_LOG_INFO
, &(host
->shost_gendev
),
478 "scsi_scan_host() called");
480 scsi_scan_host(host
);
482 /* Add sysfs binary files */
483 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_fw
))
484 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
485 "Failed to create sysfs binary file: fw");
487 a
->sysfs_fw_created
= 1;
489 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_fs
))
490 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
491 "Failed to create sysfs binary file: fs");
493 a
->sysfs_fs_created
= 1;
495 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_vda
))
496 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
497 "Failed to create sysfs binary file: vda");
499 a
->sysfs_vda_created
= 1;
501 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_hw
))
502 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
503 "Failed to create sysfs binary file: hw");
505 a
->sysfs_hw_created
= 1;
507 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &bin_attr_live_nvram
))
508 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
509 "Failed to create sysfs binary file: live_nvram");
511 a
->sysfs_live_nvram_created
= 1;
513 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
,
514 &bin_attr_default_nvram
))
515 esas2r_log_dev(ESAS2R_LOG_WARN
, &(host
->shost_gendev
),
516 "Failed to create sysfs binary file: default_nvram");
518 a
->sysfs_default_nvram_created
= 1;
525 static void esas2r_remove(struct pci_dev
*pdev
)
527 struct Scsi_Host
*host
;
531 esas2r_log(ESAS2R_LOG_WARN
, "esas2r_remove pdev==NULL");
535 host
= pci_get_drvdata(pdev
);
539 * this can happen if pci_set_drvdata was already called
540 * to clear the host pointer. if this is the case, we
541 * are okay; this channel has already been cleaned up.
547 esas2r_log_dev(ESAS2R_LOG_INFO
, &(pdev
->dev
),
548 "esas2r_remove(%p) called; "
552 index
= esas2r_cleanup(host
);
555 esas2r_log_dev(ESAS2R_LOG_WARN
, &(pdev
->dev
),
556 "unknown host in %s",
561 /* if this was the last adapter, clean up the rest of the driver */
563 if (found_adapters
== 0)
564 esas2r_cleanup(NULL
);
567 static int __init
esas2r_init(void)
571 esas2r_log(ESAS2R_LOG_INFO
, "%s called", __func__
);
573 /* verify valid parameters */
576 esas2r_log(ESAS2R_LOG_WARN
,
577 "warning: can_queue must be at least 1, value "
580 } else if (can_queue
> 2048) {
581 esas2r_log(ESAS2R_LOG_WARN
,
582 "warning: can_queue must be no larger than 2048, "
587 if (cmd_per_lun
< 1) {
588 esas2r_log(ESAS2R_LOG_WARN
,
589 "warning: cmd_per_lun must be at least 1, value "
592 } else if (cmd_per_lun
> 2048) {
593 esas2r_log(ESAS2R_LOG_WARN
,
594 "warning: cmd_per_lun must be no larger than "
595 "2048, value forced.");
599 if (sg_tablesize
< 32) {
600 esas2r_log(ESAS2R_LOG_WARN
,
601 "warning: sg_tablesize must be at least 32, "
606 if (esas2r_max_sectors
< 1) {
607 esas2r_log(ESAS2R_LOG_WARN
,
608 "warning: esas2r_max_sectors must be at least "
610 esas2r_max_sectors
= 1;
611 } else if (esas2r_max_sectors
> 0xffff) {
612 esas2r_log(ESAS2R_LOG_WARN
,
613 "warning: esas2r_max_sectors must be no larger "
614 "than 0xffff, value forced.");
615 esas2r_max_sectors
= 0xffff;
618 sgl_page_size
&= ~(ESAS2R_SGL_ALIGN
- 1);
620 if (sgl_page_size
< SGL_PG_SZ_MIN
)
621 sgl_page_size
= SGL_PG_SZ_MIN
;
622 else if (sgl_page_size
> SGL_PG_SZ_MAX
)
623 sgl_page_size
= SGL_PG_SZ_MAX
;
625 if (num_sg_lists
< NUM_SGL_MIN
)
626 num_sg_lists
= NUM_SGL_MIN
;
627 else if (num_sg_lists
> NUM_SGL_MAX
)
628 num_sg_lists
= NUM_SGL_MAX
;
630 if (num_requests
< NUM_REQ_MIN
)
631 num_requests
= NUM_REQ_MIN
;
632 else if (num_requests
> NUM_REQ_MAX
)
633 num_requests
= NUM_REQ_MAX
;
635 if (num_ae_requests
< NUM_AE_MIN
)
636 num_ae_requests
= NUM_AE_MIN
;
637 else if (num_ae_requests
> NUM_AE_MAX
)
638 num_ae_requests
= NUM_AE_MAX
;
640 /* set up other globals */
642 for (i
= 0; i
< MAX_ADAPTERS
; i
++)
643 esas2r_adapters
[i
] = NULL
;
647 driver_template
.module
= THIS_MODULE
;
649 if (pci_register_driver(&esas2r_pci_driver
) != 0)
650 esas2r_log(ESAS2R_LOG_CRIT
, "pci_register_driver FAILED");
652 esas2r_log(ESAS2R_LOG_INFO
, "pci_register_driver() OK");
654 if (!found_adapters
) {
655 pci_unregister_driver(&esas2r_pci_driver
);
656 esas2r_cleanup(NULL
);
658 esas2r_log(ESAS2R_LOG_CRIT
,
659 "driver will not be loaded because no ATTO "
660 "%s devices were found",
664 esas2r_log(ESAS2R_LOG_INFO
, "found %d adapters",
671 /* Handle ioctl calls to "/proc/scsi/esas2r/ATTOnode" */
672 static const struct file_operations esas2r_proc_fops
= {
673 .compat_ioctl
= esas2r_proc_ioctl
,
674 .unlocked_ioctl
= esas2r_proc_ioctl
,
677 static struct Scsi_Host
*esas2r_proc_host
;
678 static int esas2r_proc_major
;
680 long esas2r_proc_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
682 return esas2r_ioctl_handler(esas2r_proc_host
->hostdata
,
683 (int)cmd
, (void __user
*)arg
);
686 static void __exit
esas2r_exit(void)
688 esas2r_log(ESAS2R_LOG_INFO
, "%s called", __func__
);
690 if (esas2r_proc_major
> 0) {
691 esas2r_log(ESAS2R_LOG_INFO
, "unregister proc");
693 remove_proc_entry(ATTONODE_NAME
,
694 esas2r_proc_host
->hostt
->proc_dir
);
695 unregister_chrdev(esas2r_proc_major
, ESAS2R_DRVR_NAME
);
697 esas2r_proc_major
= 0;
700 esas2r_log(ESAS2R_LOG_INFO
, "pci_unregister_driver() called");
702 pci_unregister_driver(&esas2r_pci_driver
);
705 int esas2r_show_info(struct seq_file
*m
, struct Scsi_Host
*sh
)
707 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)sh
->hostdata
;
709 struct esas2r_target
*t
;
712 esas2r_log(ESAS2R_LOG_DEBG
, "esas2r_show_info (%p,%d)", m
, sh
->host_no
);
714 seq_printf(m
, ESAS2R_LONGNAME
"\n"
715 "Driver version: "ESAS2R_VERSION_STR
"\n"
716 "Flash version: %s\n"
717 "Firmware version: %s\n"
718 "Copyright "ESAS2R_COPYRIGHT_YEARS
"\n"
719 "http://www.attotech.com\n"
722 a
->fw_rev
[0] ? a
->fw_rev
: "(none)");
725 seq_printf(m
, "Adapter information:\n"
726 "--------------------\n"
728 "SAS address: %02X%02X%02X%02X:%02X%02X%02X%02X\n",
729 esas2r_get_model_name(a
),
730 a
->nvram
->sas_addr
[0],
731 a
->nvram
->sas_addr
[1],
732 a
->nvram
->sas_addr
[2],
733 a
->nvram
->sas_addr
[3],
734 a
->nvram
->sas_addr
[4],
735 a
->nvram
->sas_addr
[5],
736 a
->nvram
->sas_addr
[6],
737 a
->nvram
->sas_addr
[7]);
740 "Discovered devices:\n"
743 "---------------\n");
745 for (t
= a
->targetdb
; t
< a
->targetdb_end
; t
++)
746 if (t
->buffered_target_state
== TS_PRESENT
) {
747 seq_printf(m
, " %3d %3d\n",
749 (u16
)(uintptr_t)(t
- a
->targetdb
));
753 seq_puts(m
, "none\n");
760 int esas2r_release(struct Scsi_Host
*sh
)
762 esas2r_log_dev(ESAS2R_LOG_INFO
, &(sh
->shost_gendev
),
763 "esas2r_release() called");
767 free_irq(sh
->irq
, NULL
);
772 const char *esas2r_info(struct Scsi_Host
*sh
)
774 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)sh
->hostdata
;
775 static char esas2r_info_str
[512];
777 esas2r_log_dev(ESAS2R_LOG_INFO
, &(sh
->shost_gendev
),
778 "esas2r_info() called");
781 * if we haven't done so already, register as a char driver
782 * and stick a node under "/proc/scsi/esas2r/ATTOnode"
785 if (esas2r_proc_major
<= 0) {
786 esas2r_proc_host
= sh
;
788 esas2r_proc_major
= register_chrdev(0, ESAS2R_DRVR_NAME
,
791 esas2r_log_dev(ESAS2R_LOG_DEBG
, &(sh
->shost_gendev
),
792 "register_chrdev (major %d)",
795 if (esas2r_proc_major
> 0) {
796 struct proc_dir_entry
*pde
;
798 pde
= proc_create(ATTONODE_NAME
, 0,
803 esas2r_log_dev(ESAS2R_LOG_WARN
,
805 "failed to create_proc_entry");
806 esas2r_proc_major
= -1;
811 sprintf(esas2r_info_str
,
812 ESAS2R_LONGNAME
" (bus 0x%02X, device 0x%02X, IRQ 0x%02X)"
813 " driver version: "ESAS2R_VERSION_STR
" firmware version: "
815 a
->pcid
->bus
->number
, a
->pcid
->devfn
, a
->pcid
->irq
,
816 a
->fw_rev
[0] ? a
->fw_rev
: "(none)");
818 return esas2r_info_str
;
821 /* Callback for building a request scatter/gather list */
822 static u32
get_physaddr_from_sgc(struct esas2r_sg_context
*sgc
, u64
*addr
)
826 if (likely(sgc
->cur_offset
== sgc
->exp_offset
)) {
828 * the normal case: caller used all bytes from previous call, so
829 * expected offset is the same as the current offset.
832 if (sgc
->sgel_count
< sgc
->num_sgel
) {
833 /* retrieve next segment, except for first time */
834 if (sgc
->exp_offset
> (u8
*)0) {
835 /* advance current segment */
836 sgc
->cur_sgel
= sg_next(sgc
->cur_sgel
);
841 len
= sg_dma_len(sgc
->cur_sgel
);
842 (*addr
) = sg_dma_address(sgc
->cur_sgel
);
844 /* save the total # bytes returned to caller so far */
845 sgc
->exp_offset
+= len
;
850 } else if (sgc
->cur_offset
< sgc
->exp_offset
) {
852 * caller did not use all bytes from previous call. need to
853 * compute the address based on current segment.
856 len
= sg_dma_len(sgc
->cur_sgel
);
857 (*addr
) = sg_dma_address(sgc
->cur_sgel
);
859 sgc
->exp_offset
-= len
;
861 /* calculate PA based on prev segment address and offsets */
863 (sgc
->cur_offset
- sgc
->exp_offset
);
865 sgc
->exp_offset
+= len
;
867 /* re-calculate length based on offset */
869 sgc
->exp_offset
- sgc
->cur_offset
);
870 } else { /* if ( sgc->cur_offset > sgc->exp_offset ) */
872 * we don't expect the caller to skip ahead.
873 * cur_offset will never exceed the len we return
881 int esas2r_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
883 struct esas2r_adapter
*a
=
884 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
885 struct esas2r_request
*rq
;
886 struct esas2r_sg_context sgc
;
889 /* Assume success, if it fails we will fix the result later. */
890 cmd
->result
= DID_OK
<< 16;
892 if (unlikely(test_bit(AF_DEGRADED_MODE
, &a
->flags
))) {
893 cmd
->result
= DID_NO_CONNECT
<< 16;
898 rq
= esas2r_alloc_request(a
);
899 if (unlikely(rq
== NULL
)) {
900 esas2r_debug("esas2r_alloc_request failed");
901 return SCSI_MLQUEUE_HOST_BUSY
;
905 bufflen
= scsi_bufflen(cmd
);
907 if (likely(bufflen
!= 0)) {
908 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
909 rq
->vrq
->scsi
.flags
|= cpu_to_le32(FCP_CMND_WRD
);
910 else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
911 rq
->vrq
->scsi
.flags
|= cpu_to_le32(FCP_CMND_RDD
);
914 memcpy(rq
->vrq
->scsi
.cdb
, cmd
->cmnd
, cmd
->cmd_len
);
915 rq
->vrq
->scsi
.length
= cpu_to_le32(bufflen
);
916 rq
->target_id
= cmd
->device
->id
;
917 rq
->vrq
->scsi
.flags
|= cpu_to_le32(cmd
->device
->lun
);
918 rq
->sense_buf
= cmd
->sense_buffer
;
919 rq
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
921 esas2r_sgc_init(&sgc
, a
, rq
, NULL
);
923 sgc
.length
= bufflen
;
924 sgc
.cur_offset
= NULL
;
926 sgc
.cur_sgel
= scsi_sglist(cmd
);
927 sgc
.exp_offset
= NULL
;
928 sgc
.num_sgel
= scsi_dma_map(cmd
);
931 if (unlikely(sgc
.num_sgel
< 0)) {
932 esas2r_free_request(a
, rq
);
933 return SCSI_MLQUEUE_HOST_BUSY
;
936 sgc
.get_phys_addr
= (PGETPHYSADDR
)get_physaddr_from_sgc
;
938 if (unlikely(!esas2r_build_sg_list(a
, rq
, &sgc
))) {
940 esas2r_free_request(a
, rq
);
941 return SCSI_MLQUEUE_HOST_BUSY
;
944 esas2r_debug("start request %p to %d:%d\n", rq
, (int)cmd
->device
->id
,
945 (int)cmd
->device
->lun
);
947 esas2r_start_request(a
, rq
);
952 static void complete_task_management_request(struct esas2r_adapter
*a
,
953 struct esas2r_request
*rq
)
955 (*rq
->task_management_status_ptr
) = rq
->req_stat
;
956 esas2r_free_request(a
, rq
);
960 * Searches the specified queue for the specified queue for the command
964 * @param [in] abort_request
967 * @return 0 on failure, 1 if command was not found, 2 if command was found
969 static int esas2r_check_active_queue(struct esas2r_adapter
*a
,
970 struct esas2r_request
**abort_request
,
971 struct scsi_cmnd
*cmd
,
972 struct list_head
*queue
)
975 struct esas2r_request
*ar
= *abort_request
;
976 struct esas2r_request
*rq
;
977 struct list_head
*element
, *next
;
979 list_for_each_safe(element
, next
, queue
) {
981 rq
= list_entry(element
, struct esas2r_request
, req_list
);
983 if (rq
->cmd
== cmd
) {
985 /* Found the request. See what to do with it. */
986 if (queue
== &a
->active_list
) {
988 * We are searching the active queue, which
989 * means that we need to send an abort request
992 ar
= esas2r_alloc_request(a
);
994 esas2r_log_dev(ESAS2R_LOG_WARN
,
995 &(a
->host
->shost_gendev
),
996 "unable to allocate an abort request for cmd %p",
998 return 0; /* Failure */
1002 * Task management request must be formatted
1006 ar
->vrq
->scsi
.length
= 0;
1007 ar
->target_id
= rq
->target_id
;
1008 ar
->vrq
->scsi
.flags
|= cpu_to_le32(
1009 (u8
)le32_to_cpu(rq
->vrq
->scsi
.flags
));
1011 memset(ar
->vrq
->scsi
.cdb
, 0,
1012 sizeof(ar
->vrq
->scsi
.cdb
));
1014 ar
->vrq
->scsi
.flags
|= cpu_to_le32(
1016 ar
->vrq
->scsi
.u
.abort_handle
=
1017 rq
->vrq
->scsi
.handle
;
1020 * The request is pending but not active on
1021 * the firmware. Just free it now and we'll
1022 * report the successful abort below.
1024 list_del_init(&rq
->req_list
);
1025 esas2r_free_request(a
, rq
);
1035 return 1; /* Not found */
1037 return 2; /* found */
1042 int esas2r_eh_abort(struct scsi_cmnd
*cmd
)
1044 struct esas2r_adapter
*a
=
1045 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
1046 struct esas2r_request
*abort_request
= NULL
;
1047 unsigned long flags
;
1048 struct list_head
*queue
;
1051 esas2r_log(ESAS2R_LOG_INFO
, "eh_abort (%p)", cmd
);
1053 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
)) {
1054 cmd
->result
= DID_ABORT
<< 16;
1056 scsi_set_resid(cmd
, 0);
1058 cmd
->scsi_done(cmd
);
1063 spin_lock_irqsave(&a
->queue_lock
, flags
);
1066 * Run through the defer and active queues looking for the request
1070 queue
= &a
->defer_list
;
1074 result
= esas2r_check_active_queue(a
, &abort_request
, cmd
, queue
);
1077 spin_unlock_irqrestore(&a
->queue_lock
, flags
);
1079 } else if (result
== 2 && (queue
== &a
->defer_list
)) {
1080 queue
= &a
->active_list
;
1081 goto check_active_queue
;
1084 spin_unlock_irqrestore(&a
->queue_lock
, flags
);
1086 if (abort_request
) {
1087 u8 task_management_status
= RS_PENDING
;
1090 * the request is already active, so we need to tell
1091 * the firmware to abort it and wait for the response.
1094 abort_request
->comp_cb
= complete_task_management_request
;
1095 abort_request
->task_management_status_ptr
=
1096 &task_management_status
;
1098 esas2r_start_request(a
, abort_request
);
1100 if (atomic_read(&a
->disable_cnt
) == 0)
1101 esas2r_do_deferred_processes(a
);
1103 while (task_management_status
== RS_PENDING
)
1107 * Once we get here, the original request will have been
1108 * completed by the firmware and the abort request will have
1109 * been cleaned up. we're done!
1116 * If we get here, either we found the inactive request and
1117 * freed it, or we didn't find it at all. Either way, success!
1120 cmd
->result
= DID_ABORT
<< 16;
1122 scsi_set_resid(cmd
, 0);
1124 cmd
->scsi_done(cmd
);
1129 static int esas2r_host_bus_reset(struct scsi_cmnd
*cmd
, bool host_reset
)
1131 struct esas2r_adapter
*a
=
1132 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
1134 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1138 esas2r_reset_adapter(a
);
1140 esas2r_reset_bus(a
);
1142 /* above call sets the AF_OS_RESET flag. wait for it to clear. */
1144 while (test_bit(AF_OS_RESET
, &a
->flags
)) {
1147 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1151 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1157 int esas2r_host_reset(struct scsi_cmnd
*cmd
)
1159 esas2r_log(ESAS2R_LOG_INFO
, "host_reset (%p)", cmd
);
1161 return esas2r_host_bus_reset(cmd
, true);
1164 int esas2r_bus_reset(struct scsi_cmnd
*cmd
)
1166 esas2r_log(ESAS2R_LOG_INFO
, "bus_reset (%p)", cmd
);
1168 return esas2r_host_bus_reset(cmd
, false);
1171 static int esas2r_dev_targ_reset(struct scsi_cmnd
*cmd
, bool target_reset
)
1173 struct esas2r_adapter
*a
=
1174 (struct esas2r_adapter
*)cmd
->device
->host
->hostdata
;
1175 struct esas2r_request
*rq
;
1176 u8 task_management_status
= RS_PENDING
;
1179 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1183 rq
= esas2r_alloc_request(a
);
1186 esas2r_log(ESAS2R_LOG_CRIT
,
1187 "unable to allocate a request for a "
1188 "target reset (%d)!",
1191 esas2r_log(ESAS2R_LOG_CRIT
,
1192 "unable to allocate a request for a "
1193 "device reset (%d:%d)!",
1202 rq
->target_id
= cmd
->device
->id
;
1203 rq
->vrq
->scsi
.flags
|= cpu_to_le32(cmd
->device
->lun
);
1204 rq
->req_stat
= RS_PENDING
;
1206 rq
->comp_cb
= complete_task_management_request
;
1207 rq
->task_management_status_ptr
= &task_management_status
;
1210 esas2r_debug("issuing target reset (%p) to id %d", rq
,
1212 completed
= esas2r_send_task_mgmt(a
, rq
, 0x20);
1214 esas2r_debug("issuing device reset (%p) to id %d lun %d", rq
,
1215 cmd
->device
->id
, cmd
->device
->lun
);
1216 completed
= esas2r_send_task_mgmt(a
, rq
, 0x10);
1220 /* Task management cmd completed right away, need to free it. */
1222 esas2r_free_request(a
, rq
);
1225 * Wait for firmware to complete the request. Completion
1226 * callback will free it.
1228 while (task_management_status
== RS_PENDING
)
1232 if (test_bit(AF_DEGRADED_MODE
, &a
->flags
))
1235 if (task_management_status
== RS_BUSY
) {
1237 * Busy, probably because we are flashing. Wait a bit and
1247 int esas2r_device_reset(struct scsi_cmnd
*cmd
)
1249 esas2r_log(ESAS2R_LOG_INFO
, "device_reset (%p)", cmd
);
1251 return esas2r_dev_targ_reset(cmd
, false);
1255 int esas2r_target_reset(struct scsi_cmnd
*cmd
)
1257 esas2r_log(ESAS2R_LOG_INFO
, "target_reset (%p)", cmd
);
1259 return esas2r_dev_targ_reset(cmd
, true);
1262 int esas2r_change_queue_depth(struct scsi_device
*dev
, int depth
, int reason
)
1264 esas2r_log(ESAS2R_LOG_INFO
, "change_queue_depth %p, %d", dev
, depth
);
1266 scsi_adjust_queue_depth(dev
, scsi_get_tag_type(dev
), depth
);
1268 return dev
->queue_depth
;
1271 int esas2r_change_queue_type(struct scsi_device
*dev
, int type
)
1273 esas2r_log(ESAS2R_LOG_INFO
, "change_queue_type %p, %d", dev
, type
);
1275 if (dev
->tagged_supported
) {
1276 scsi_set_tag_type(dev
, type
);
1279 scsi_activate_tcq(dev
, dev
->queue_depth
);
1281 scsi_deactivate_tcq(dev
, dev
->queue_depth
);
1289 int esas2r_slave_alloc(struct scsi_device
*dev
)
1294 int esas2r_slave_configure(struct scsi_device
*dev
)
1296 esas2r_log_dev(ESAS2R_LOG_INFO
, &(dev
->sdev_gendev
),
1297 "esas2r_slave_configure()");
1299 if (dev
->tagged_supported
) {
1300 scsi_set_tag_type(dev
, MSG_SIMPLE_TAG
);
1301 scsi_activate_tcq(dev
, cmd_per_lun
);
1303 scsi_set_tag_type(dev
, 0);
1304 scsi_deactivate_tcq(dev
, cmd_per_lun
);
1310 void esas2r_slave_destroy(struct scsi_device
*dev
)
1312 esas2r_log_dev(ESAS2R_LOG_INFO
, &(dev
->sdev_gendev
),
1313 "esas2r_slave_destroy()");
1316 void esas2r_log_request_failure(struct esas2r_adapter
*a
,
1317 struct esas2r_request
*rq
)
1319 u8 reqstatus
= rq
->req_stat
;
1321 if (reqstatus
== RS_SUCCESS
)
1324 if (rq
->vrq
->scsi
.function
== VDA_FUNC_SCSI
) {
1325 if (reqstatus
== RS_SCSI_ERROR
) {
1326 if (rq
->func_rsp
.scsi_rsp
.sense_len
>= 13) {
1327 esas2r_log(ESAS2R_LOG_WARN
,
1328 "request failure - SCSI error %x ASC:%x ASCQ:%x CDB:%x",
1329 rq
->sense_buf
[2], rq
->sense_buf
[12],
1331 rq
->vrq
->scsi
.cdb
[0]);
1333 esas2r_log(ESAS2R_LOG_WARN
,
1334 "request failure - SCSI error CDB:%x\n",
1335 rq
->vrq
->scsi
.cdb
[0]);
1337 } else if ((rq
->vrq
->scsi
.cdb
[0] != INQUIRY
1338 && rq
->vrq
->scsi
.cdb
[0] != REPORT_LUNS
)
1339 || (reqstatus
!= RS_SEL
1340 && reqstatus
!= RS_SEL2
)) {
1341 if ((reqstatus
== RS_UNDERRUN
) &&
1342 (rq
->vrq
->scsi
.cdb
[0] == INQUIRY
)) {
1343 /* Don't log inquiry underruns */
1345 esas2r_log(ESAS2R_LOG_WARN
,
1346 "request failure - cdb:%x reqstatus:%d target:%d",
1347 rq
->vrq
->scsi
.cdb
[0], reqstatus
,
1354 void esas2r_wait_request(struct esas2r_adapter
*a
, struct esas2r_request
*rq
)
1359 starttime
= jiffies_to_msecs(jiffies
);
1360 timeout
= rq
->timeout
? rq
->timeout
: 5000;
1363 esas2r_polled_interrupt(a
);
1365 if (rq
->req_stat
!= RS_STARTED
)
1368 schedule_timeout_interruptible(msecs_to_jiffies(100));
1370 if ((jiffies_to_msecs(jiffies
) - starttime
) > timeout
) {
1371 esas2r_hdebug("request TMO");
1374 rq
->req_stat
= RS_TIMEOUT
;
1376 esas2r_local_reset_adapter(a
);
1382 u32
esas2r_map_data_window(struct esas2r_adapter
*a
, u32 addr_lo
)
1384 u32 offset
= addr_lo
& (MW_DATA_WINDOW_SIZE
- 1);
1385 u32 base
= addr_lo
& -(signed int)MW_DATA_WINDOW_SIZE
;
1387 if (a
->window_base
!= base
) {
1388 esas2r_write_register_dword(a
, MVR_PCI_WIN1_REMAP
,
1389 base
| MVRPW1R_ENABLE
);
1390 esas2r_flush_register_dword(a
, MVR_PCI_WIN1_REMAP
);
1391 a
->window_base
= base
;
1397 /* Read a block of data from chip memory */
1398 bool esas2r_read_mem_block(struct esas2r_adapter
*a
,
1410 iatvr
= (from
& -(signed int)MW_DATA_WINDOW_SIZE
);
1412 esas2r_map_data_window(a
, iatvr
);
1414 offset
= from
& (MW_DATA_WINDOW_SIZE
- 1);
1417 if (len
> MW_DATA_WINDOW_SIZE
- offset
)
1418 len
= MW_DATA_WINDOW_SIZE
- offset
;
1424 *end
++ = esas2r_read_data_byte(a
, offset
);
1432 void esas2r_nuxi_mgt_data(u8 function
, void *data
)
1434 struct atto_vda_grp_info
*g
;
1435 struct atto_vda_devinfo
*d
;
1436 struct atto_vdapart_info
*p
;
1437 struct atto_vda_dh_info
*h
;
1438 struct atto_vda_metrics_info
*m
;
1439 struct atto_vda_schedule_info
*s
;
1440 struct atto_vda_buzzer_info
*b
;
1444 case VDAMGT_BUZZER_INFO
:
1445 case VDAMGT_BUZZER_SET
:
1447 b
= (struct atto_vda_buzzer_info
*)data
;
1449 b
->duration
= le32_to_cpu(b
->duration
);
1452 case VDAMGT_SCHEDULE_INFO
:
1453 case VDAMGT_SCHEDULE_EVENT
:
1455 s
= (struct atto_vda_schedule_info
*)data
;
1457 s
->id
= le32_to_cpu(s
->id
);
1461 case VDAMGT_DEV_INFO
:
1462 case VDAMGT_DEV_CLEAN
:
1463 case VDAMGT_DEV_PT_INFO
:
1464 case VDAMGT_DEV_FEATURES
:
1465 case VDAMGT_DEV_PT_FEATURES
:
1466 case VDAMGT_DEV_OPERATION
:
1468 d
= (struct atto_vda_devinfo
*)data
;
1470 d
->capacity
= le64_to_cpu(d
->capacity
);
1471 d
->block_size
= le32_to_cpu(d
->block_size
);
1472 d
->ses_dev_index
= le16_to_cpu(d
->ses_dev_index
);
1473 d
->target_id
= le16_to_cpu(d
->target_id
);
1474 d
->lun
= le16_to_cpu(d
->lun
);
1475 d
->features
= le16_to_cpu(d
->features
);
1478 case VDAMGT_GRP_INFO
:
1479 case VDAMGT_GRP_CREATE
:
1480 case VDAMGT_GRP_DELETE
:
1481 case VDAMGT_ADD_STORAGE
:
1482 case VDAMGT_MEMBER_ADD
:
1483 case VDAMGT_GRP_COMMIT
:
1484 case VDAMGT_GRP_REBUILD
:
1485 case VDAMGT_GRP_COMMIT_INIT
:
1486 case VDAMGT_QUICK_RAID
:
1487 case VDAMGT_GRP_FEATURES
:
1488 case VDAMGT_GRP_COMMIT_INIT_AUTOMAP
:
1489 case VDAMGT_QUICK_RAID_INIT_AUTOMAP
:
1490 case VDAMGT_SPARE_LIST
:
1491 case VDAMGT_SPARE_ADD
:
1492 case VDAMGT_SPARE_REMOVE
:
1493 case VDAMGT_LOCAL_SPARE_ADD
:
1494 case VDAMGT_GRP_OPERATION
:
1496 g
= (struct atto_vda_grp_info
*)data
;
1498 g
->capacity
= le64_to_cpu(g
->capacity
);
1499 g
->block_size
= le32_to_cpu(g
->block_size
);
1500 g
->interleave
= le32_to_cpu(g
->interleave
);
1501 g
->features
= le16_to_cpu(g
->features
);
1503 for (i
= 0; i
< 32; i
++)
1504 g
->members
[i
] = le16_to_cpu(g
->members
[i
]);
1508 case VDAMGT_PART_INFO
:
1509 case VDAMGT_PART_MAP
:
1510 case VDAMGT_PART_UNMAP
:
1511 case VDAMGT_PART_AUTOMAP
:
1512 case VDAMGT_PART_SPLIT
:
1513 case VDAMGT_PART_MERGE
:
1515 p
= (struct atto_vdapart_info
*)data
;
1517 p
->part_size
= le64_to_cpu(p
->part_size
);
1518 p
->start_lba
= le32_to_cpu(p
->start_lba
);
1519 p
->block_size
= le32_to_cpu(p
->block_size
);
1520 p
->target_id
= le16_to_cpu(p
->target_id
);
1523 case VDAMGT_DEV_HEALTH_REQ
:
1525 h
= (struct atto_vda_dh_info
*)data
;
1527 h
->med_defect_cnt
= le32_to_cpu(h
->med_defect_cnt
);
1528 h
->info_exc_cnt
= le32_to_cpu(h
->info_exc_cnt
);
1531 case VDAMGT_DEV_METRICS
:
1533 m
= (struct atto_vda_metrics_info
*)data
;
1535 for (i
= 0; i
< 32; i
++)
1536 m
->dev_indexes
[i
] = le16_to_cpu(m
->dev_indexes
[i
]);
1545 void esas2r_nuxi_cfg_data(u8 function
, void *data
)
1547 struct atto_vda_cfg_init
*ci
;
1551 case VDA_CFG_GET_INIT
:
1552 case VDA_CFG_GET_INIT2
:
1554 ci
= (struct atto_vda_cfg_init
*)data
;
1556 ci
->date_time
.year
= le16_to_cpu(ci
->date_time
.year
);
1557 ci
->sgl_page_size
= le32_to_cpu(ci
->sgl_page_size
);
1558 ci
->vda_version
= le32_to_cpu(ci
->vda_version
);
1559 ci
->epoch_time
= le32_to_cpu(ci
->epoch_time
);
1560 ci
->ioctl_tunnel
= le32_to_cpu(ci
->ioctl_tunnel
);
1561 ci
->num_targets_backend
= le32_to_cpu(ci
->num_targets_backend
);
1569 void esas2r_nuxi_ae_data(union atto_vda_ae
*ae
)
1571 struct atto_vda_ae_raid
*r
= &ae
->raid
;
1572 struct atto_vda_ae_lu
*l
= &ae
->lu
;
1574 switch (ae
->hdr
.bytype
) {
1575 case VDAAE_HDR_TYPE_RAID
:
1577 r
->dwflags
= le32_to_cpu(r
->dwflags
);
1580 case VDAAE_HDR_TYPE_LU
:
1582 l
->dwevent
= le32_to_cpu(l
->dwevent
);
1583 l
->wphys_target_id
= le16_to_cpu(l
->wphys_target_id
);
1584 l
->id
.tgtlun
.wtarget_id
= le16_to_cpu(l
->id
.tgtlun
.wtarget_id
);
1586 if (l
->hdr
.bylength
>= offsetof(struct atto_vda_ae_lu
, id
)
1587 + sizeof(struct atto_vda_ae_lu_tgt_lun_raid
)) {
1588 l
->id
.tgtlun_raid
.dwinterleave
1589 = le32_to_cpu(l
->id
.tgtlun_raid
.dwinterleave
);
1590 l
->id
.tgtlun_raid
.dwblock_size
1591 = le32_to_cpu(l
->id
.tgtlun_raid
.dwblock_size
);
1596 case VDAAE_HDR_TYPE_DISK
:
1602 void esas2r_free_request(struct esas2r_adapter
*a
, struct esas2r_request
*rq
)
1604 unsigned long flags
;
1606 esas2r_rq_destroy_request(rq
, a
);
1607 spin_lock_irqsave(&a
->request_lock
, flags
);
1608 list_add(&rq
->comp_list
, &a
->avail_request
);
1609 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1612 struct esas2r_request
*esas2r_alloc_request(struct esas2r_adapter
*a
)
1614 struct esas2r_request
*rq
;
1615 unsigned long flags
;
1617 spin_lock_irqsave(&a
->request_lock
, flags
);
1619 if (unlikely(list_empty(&a
->avail_request
))) {
1620 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1624 rq
= list_first_entry(&a
->avail_request
, struct esas2r_request
,
1626 list_del(&rq
->comp_list
);
1627 spin_unlock_irqrestore(&a
->request_lock
, flags
);
1628 esas2r_rq_init_request(rq
, a
);
1634 void esas2r_complete_request_cb(struct esas2r_adapter
*a
,
1635 struct esas2r_request
*rq
)
1637 esas2r_debug("completing request %p\n", rq
);
1639 scsi_dma_unmap(rq
->cmd
);
1641 if (unlikely(rq
->req_stat
!= RS_SUCCESS
)) {
1642 esas2r_debug("[%x STATUS %x:%x (%x)]", rq
->target_id
,
1644 rq
->func_rsp
.scsi_rsp
.scsi_stat
,
1648 ((esas2r_req_status_to_error(rq
->req_stat
) << 16)
1649 | (rq
->func_rsp
.scsi_rsp
.scsi_stat
& STATUS_MASK
));
1651 if (rq
->req_stat
== RS_UNDERRUN
)
1652 scsi_set_resid(rq
->cmd
,
1653 le32_to_cpu(rq
->func_rsp
.scsi_rsp
.
1656 scsi_set_resid(rq
->cmd
, 0);
1659 rq
->cmd
->scsi_done(rq
->cmd
);
1661 esas2r_free_request(a
, rq
);
1664 /* Run tasklet to handle stuff outside of interrupt context. */
1665 void esas2r_adapter_tasklet(unsigned long context
)
1667 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)context
;
1669 if (unlikely(test_bit(AF2_TIMER_TICK
, &a
->flags2
))) {
1670 clear_bit(AF2_TIMER_TICK
, &a
->flags2
);
1671 esas2r_timer_tick(a
);
1674 if (likely(test_bit(AF2_INT_PENDING
, &a
->flags2
))) {
1675 clear_bit(AF2_INT_PENDING
, &a
->flags2
);
1676 esas2r_adapter_interrupt(a
);
1679 if (esas2r_is_tasklet_pending(a
))
1680 esas2r_do_tasklet_tasks(a
);
1682 if (esas2r_is_tasklet_pending(a
)
1683 || (test_bit(AF2_INT_PENDING
, &a
->flags2
))
1684 || (test_bit(AF2_TIMER_TICK
, &a
->flags2
))) {
1685 clear_bit(AF_TASKLET_SCHEDULED
, &a
->flags
);
1686 esas2r_schedule_tasklet(a
);
1688 clear_bit(AF_TASKLET_SCHEDULED
, &a
->flags
);
1692 static void esas2r_timer_callback(unsigned long context
);
1694 void esas2r_kickoff_timer(struct esas2r_adapter
*a
)
1696 init_timer(&a
->timer
);
1698 a
->timer
.function
= esas2r_timer_callback
;
1699 a
->timer
.data
= (unsigned long)a
;
1700 a
->timer
.expires
= jiffies
+
1701 msecs_to_jiffies(100);
1703 add_timer(&a
->timer
);
1706 static void esas2r_timer_callback(unsigned long context
)
1708 struct esas2r_adapter
*a
= (struct esas2r_adapter
*)context
;
1710 set_bit(AF2_TIMER_TICK
, &a
->flags2
);
1712 esas2r_schedule_tasklet(a
);
1714 esas2r_kickoff_timer(a
);
1718 * Firmware events need to be handled outside of interrupt context
1719 * so we schedule a delayed_work to handle them.
1723 esas2r_free_fw_event(struct esas2r_fw_event_work
*fw_event
)
1725 unsigned long flags
;
1726 struct esas2r_adapter
*a
= fw_event
->a
;
1728 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1729 list_del(&fw_event
->list
);
1731 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1735 esas2r_fw_event_off(struct esas2r_adapter
*a
)
1737 unsigned long flags
;
1739 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1740 a
->fw_events_off
= 1;
1741 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1745 esas2r_fw_event_on(struct esas2r_adapter
*a
)
1747 unsigned long flags
;
1749 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1750 a
->fw_events_off
= 0;
1751 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1754 static void esas2r_add_device(struct esas2r_adapter
*a
, u16 target_id
)
1757 struct scsi_device
*scsi_dev
;
1759 scsi_dev
= scsi_device_lookup(a
->host
, 0, target_id
, 0);
1766 "scsi device already exists at id %d", target_id
);
1768 scsi_device_put(scsi_dev
);
1774 "scsi_add_device() called for 0:%d:0",
1777 ret
= scsi_add_device(a
->host
, 0, target_id
, 0);
1783 "scsi_add_device failed with %d for id %d",
1789 static void esas2r_remove_device(struct esas2r_adapter
*a
, u16 target_id
)
1791 struct scsi_device
*scsi_dev
;
1793 scsi_dev
= scsi_device_lookup(a
->host
, 0, target_id
, 0);
1796 scsi_device_set_state(scsi_dev
, SDEV_OFFLINE
);
1802 "scsi_remove_device() called for 0:%d:0",
1805 scsi_remove_device(scsi_dev
);
1811 "scsi_device_put() called");
1813 scsi_device_put(scsi_dev
);
1817 &(a
->host
->shost_gendev
),
1818 "no target found at id %d",
1824 * Sends a firmware asynchronous event to anyone who happens to be
1825 * listening on the defined ATTO VDA event ports.
1827 static void esas2r_send_ae_event(struct esas2r_fw_event_work
*fw_event
)
1829 struct esas2r_vda_ae
*ae
= (struct esas2r_vda_ae
*)fw_event
->data
;
1832 switch (ae
->vda_ae
.hdr
.bytype
) {
1833 case VDAAE_HDR_TYPE_RAID
:
1834 type
= "RAID group state change";
1837 case VDAAE_HDR_TYPE_LU
:
1838 type
= "Mapped destination LU change";
1841 case VDAAE_HDR_TYPE_DISK
:
1842 type
= "Physical disk inventory change";
1845 case VDAAE_HDR_TYPE_RESET
:
1846 type
= "Firmware reset";
1849 case VDAAE_HDR_TYPE_LOG_INFO
:
1850 type
= "Event Log message (INFO level)";
1853 case VDAAE_HDR_TYPE_LOG_WARN
:
1854 type
= "Event Log message (WARN level)";
1857 case VDAAE_HDR_TYPE_LOG_CRIT
:
1858 type
= "Event Log message (CRIT level)";
1861 case VDAAE_HDR_TYPE_LOG_FAIL
:
1862 type
= "Event Log message (FAIL level)";
1865 case VDAAE_HDR_TYPE_NVC
:
1866 type
= "NVCache change";
1869 case VDAAE_HDR_TYPE_TLG_INFO
:
1870 type
= "Time stamped log message (INFO level)";
1873 case VDAAE_HDR_TYPE_TLG_WARN
:
1874 type
= "Time stamped log message (WARN level)";
1877 case VDAAE_HDR_TYPE_TLG_CRIT
:
1878 type
= "Time stamped log message (CRIT level)";
1881 case VDAAE_HDR_TYPE_PWRMGT
:
1882 type
= "Power management";
1885 case VDAAE_HDR_TYPE_MUTE
:
1886 type
= "Mute button pressed";
1889 case VDAAE_HDR_TYPE_DEV
:
1890 type
= "Device attribute change";
1898 esas2r_log(ESAS2R_LOG_WARN
,
1899 "An async event of type \"%s\" was received from the firmware. The event contents are:",
1901 esas2r_log_hexdump(ESAS2R_LOG_WARN
, &ae
->vda_ae
,
1902 ae
->vda_ae
.hdr
.bylength
);
1907 esas2r_firmware_event_work(struct work_struct
*work
)
1909 struct esas2r_fw_event_work
*fw_event
=
1910 container_of(work
, struct esas2r_fw_event_work
, work
.work
);
1912 struct esas2r_adapter
*a
= fw_event
->a
;
1914 u16 target_id
= *(u16
*)&fw_event
->data
[0];
1916 if (a
->fw_events_off
)
1919 switch (fw_event
->type
) {
1921 break; /* do nothing */
1923 case fw_event_lun_change
:
1924 esas2r_remove_device(a
, target_id
);
1925 esas2r_add_device(a
, target_id
);
1928 case fw_event_present
:
1929 esas2r_add_device(a
, target_id
);
1932 case fw_event_not_present
:
1933 esas2r_remove_device(a
, target_id
);
1936 case fw_event_vda_ae
:
1937 esas2r_send_ae_event(fw_event
);
1942 esas2r_free_fw_event(fw_event
);
1945 void esas2r_queue_fw_event(struct esas2r_adapter
*a
,
1946 enum fw_event_type type
,
1950 struct esas2r_fw_event_work
*fw_event
;
1951 unsigned long flags
;
1953 fw_event
= kzalloc(sizeof(struct esas2r_fw_event_work
), GFP_ATOMIC
);
1955 esas2r_log(ESAS2R_LOG_WARN
,
1956 "esas2r_queue_fw_event failed to alloc");
1960 if (type
== fw_event_vda_ae
) {
1961 struct esas2r_vda_ae
*ae
=
1962 (struct esas2r_vda_ae
*)fw_event
->data
;
1964 ae
->signature
= ESAS2R_VDA_EVENT_SIG
;
1965 ae
->bus_number
= a
->pcid
->bus
->number
;
1966 ae
->devfn
= a
->pcid
->devfn
;
1967 memcpy(&ae
->vda_ae
, data
, sizeof(ae
->vda_ae
));
1969 memcpy(fw_event
->data
, data
, data_sz
);
1972 fw_event
->type
= type
;
1975 spin_lock_irqsave(&a
->fw_event_lock
, flags
);
1976 list_add_tail(&fw_event
->list
, &a
->fw_event_list
);
1977 INIT_DELAYED_WORK(&fw_event
->work
, esas2r_firmware_event_work
);
1978 queue_delayed_work_on(
1979 smp_processor_id(), a
->fw_event_q
, &fw_event
->work
,
1980 msecs_to_jiffies(1));
1981 spin_unlock_irqrestore(&a
->fw_event_lock
, flags
);
1984 void esas2r_target_state_changed(struct esas2r_adapter
*a
, u16 targ_id
,
1987 if (state
== TS_LUN_CHANGE
)
1988 esas2r_queue_fw_event(a
, fw_event_lun_change
, &targ_id
,
1990 else if (state
== TS_PRESENT
)
1991 esas2r_queue_fw_event(a
, fw_event_present
, &targ_id
,
1993 else if (state
== TS_NOT_PRESENT
)
1994 esas2r_queue_fw_event(a
, fw_event_not_present
, &targ_id
,
1998 /* Translate status to a Linux SCSI mid-layer error code */
1999 int esas2r_req_status_to_error(u8 req_stat
)
2006 * NOTE: SCSI mid-layer wants a good status for a SCSI error, because
2007 * it will check the scsi_stat value in the completion anyway.
2014 return DID_NO_CONNECT
;
2023 return DID_BUS_BUSY
;
2026 /* everything else is just an error. */
2031 module_init(esas2r_init
);
2032 module_exit(esas2r_exit
);