45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
55 #include <linux/poll.h>
83 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
100 if (sas_device->
handle != handle)
139 "scsi_io, cmd(0x%02x), cdb_len(%d)",
160 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
171 desc =
"port_enable";
174 desc =
"event_notification";
177 desc =
"fw_download";
183 desc =
"raid_action";
191 "raid_pass, cmd(0x%02x), cdb_len(%d)",
198 desc =
"sas_iounit_cntl";
204 desc =
"diag_buffer_post";
207 desc =
"diag_release";
210 desc =
"smp_passthrough";
218 ioc->
name, calling_function_name, desc, smid);
225 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
238 sas_device = _ctl_sas_device_find_by_handle(ioc,
242 "phy(%d)\n", ioc->
name, (
unsigned long long)
245 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
252 "\tscsi_state(0x%02x), scsi_status"
253 "(0x%02x)\n", ioc->
name,
306 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
307 _ctl_display_some_debug(ioc, smid,
"ctl_done", mpi_reply);
330 if (event >= 128 || !event || !ioc->
event_log)
333 desired_event = (1 << (
event % 32));
354 u32 sz, event_data_sz;
362 if (_ctl_check_event_type(ioc, event)) {
427 if (ioc->
id != ioc_number)
452 switch (reset_phase) {
455 "MPT2_IOC_PRE_RESET\n", ioc->
name, __func__));
463 _ctl_send_release(ioc, i, &issue_reset);
468 "MPT2_IOC_AFTER_RESET\n", ioc->
name, __func__));
477 "MPT2_IOC_DONE_RESET\n", ioc->
name, __func__));
502 _ctl_fasync(
int fd,
struct file *filep,
int mode)
531 poll_wait(filep, &ctl_poll_wait, wait);
580 if (lun != scmd->
device->lun)
582 priv_data = scmd->
device->hostdata;
594 "handle(0x%04x), lun(%d), no active mid!!\n", ioc->
name,
612 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->
name,
633 unsigned long timeout, timeleft;
639 size_t data_out_sz = 0;
642 size_t data_in_sz = 0;
645 u16 wait_state_count;
651 ioc->
name, __func__);
656 wait_state_count = 0;
659 if (wait_state_count++ == 10) {
661 "%s: failed due to ioc not operational\n",
662 ioc->
name, __func__);
669 "operational state(count=%d)\n", ioc->
name,
670 __func__, wait_state_count);
672 if (wait_state_count)
674 ioc->
name, __func__);
679 "mpi_request\n", ioc->
name, __func__);
703 ioc->
name, __func__);
712 ioc->
name, __func__);
731 ioc->
facts.MaxDevHandle) {
774 if (!data_out_sz && !data_in_sz) {
776 }
else if (data_out_sz && data_in_sz) {
782 data_out_sz, data_out_dma);
793 data_in_sz, data_in_dma);
794 }
else if (data_out_sz) {
800 data_out_sz, data_out_dma);
801 }
else if (data_in_sz) {
807 data_in_sz, data_in_dma);
811 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
812 _ctl_display_some_debug(ioc, smid,
"ctl_request",
NULL);
815 init_completion(&ioc->
ctl_cmds.done);
839 "handle(0x%04x), task_type(0x%02x)\n", ioc->
name,
846 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
867 data = (
u8 *)&smp_request->
SGL;
871 __FILE__, __LINE__, __func__);
879 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
928 goto issue_host_reset;
934 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
941 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
942 "TerminationCount(0x%08x)\n", ioc->
name,
993 "= (0x%04x)\n", ioc->
name,
1034 __FILE__, __LINE__, __func__);
1041 memset(&karg, 0 ,
sizeof(karg));
1047 karg.port_number = ioc->
pfacts[0].PortNumber;
1048 karg.hw_rev = ioc->
pdev->revision;
1049 karg.pci_id = ioc->
pdev->device;
1050 karg.subsystem_device = ioc->
pdev->subsystem_device;
1051 karg.subsystem_vendor = ioc->
pdev->subsystem_vendor;
1052 karg.pci_information.u.bits.bus = ioc->
pdev->bus->number;
1053 karg.pci_information.u.bits.device =
PCI_SLOT(ioc->
pdev->devfn);
1054 karg.pci_information.u.bits.function =
PCI_FUNC(ioc->
pdev->devfn);
1056 karg.firmware_version = ioc->
facts.FWVersion.Word;
1058 strcat(karg.driver_version,
"-");
1064 __FILE__, __LINE__, __func__);
1082 __FILE__, __LINE__, __func__);
1095 __FILE__, __LINE__, __func__);
1113 __FILE__, __LINE__, __func__);
1133 __FILE__, __LINE__, __func__);
1148 u32 number_bytes, max_events,
max;
1153 __FILE__, __LINE__, __func__);
1160 number_bytes = karg.
hdr.max_data_size -
1174 __FILE__, __LINE__, __func__);
1196 __FILE__, __LINE__, __func__);
1209 ioc->
name, ((!retval) ?
"SUCCESS" :
"FAILED"));
1223 unsigned long flags;
1231 if (btdh->
bus == 0xFFFFFFFF && btdh->
id == 0xFFFFFFFF &&
1234 btdh->
id = sas_device->
id;
1237 }
else if (btdh->
bus == sas_device->
channel && btdh->
id ==
1238 sas_device->
id && btdh->
handle == 0xFFFF) {
1259 unsigned long flags;
1267 if (btdh->
bus == 0xFFFFFFFF && btdh->
id == 0xFFFFFFFF &&
1270 btdh->
id = raid_device->
id;
1273 }
else if (btdh->
bus == raid_device->
channel && btdh->
id ==
1274 raid_device->
id && btdh->
handle == 0xFFFF) {
1298 __FILE__, __LINE__, __func__);
1305 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1307 _ctl_btdh_search_raid_device(ioc, &karg);
1311 __FILE__, __LINE__, __func__);
1329 switch (buffer_type) {
1331 if (ioc->
facts.IOCCapabilities &
1336 if (ioc->
facts.IOCCapabilities &
1341 if (ioc->
facts.IOCCapabilities &
1360 void *request_data =
NULL;
1362 u32 request_data_sz = 0;
1366 unsigned long timeleft;
1376 ioc->
name, __func__);
1382 if (!_ctl_diag_capability(ioc, buffer_type)) {
1384 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1391 "buffer for buffer_type(0x%02x)\n", ioc->
name, __func__,
1398 "is not 4 byte aligned\n", ioc->
name, __func__);
1405 ioc->
name, __func__);
1429 request_data, request_data_dma);
1430 request_data =
NULL;
1434 if (request_data ==
NULL) {
1438 ioc->
pdev, request_data_sz, &request_data_dma);
1439 if (request_data ==
NULL) {
1441 " for diag buffers, requested size(%d)\n",
1442 ioc->
name, __func__, request_data_sz);
1456 mpi_request->
VF_ID = 0;
1457 mpi_request->
VP_ID = 0;
1460 "dma(0x%llx), sz(%d)\n", ioc->
name, __func__, request_data,
1461 (
unsigned long long)request_data_dma,
1468 init_completion(&ioc->
ctl_cmds.done);
1480 goto issue_host_reset;
1486 ioc->
name, __func__);
1498 ioc->
name, __func__));
1501 "log_info(0x%08x)\n", ioc->
name, __func__,
1513 if (rc && request_data)
1515 request_data, request_data_dma);
1536 if (bits_to_register & 1) {
1543 _ctl_diag_register_2(ioc, &diag_register);
1546 if (bits_to_register & 2) {
1553 _ctl_diag_register_2(ioc, &diag_register);
1556 if (bits_to_register & 4) {
1563 _ctl_diag_register_2(ioc, &diag_register);
1583 __FILE__, __LINE__, __func__);
1587 rc = _ctl_diag_register_2(ioc, &karg);
1605 u32 request_data_sz;
1610 __FILE__, __LINE__, __func__);
1617 buffer_type = karg.unique_id & 0x000000ff;
1618 if (!_ctl_diag_capability(ioc, buffer_type)) {
1620 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1625 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1627 "registered\n", ioc->
name, __func__, buffer_type);
1633 "released\n", ioc->
name, __func__, buffer_type);
1637 if (karg.unique_id != ioc->
unique_id[buffer_type]) {
1639 "registered\n", ioc->
name, __func__, karg.unique_id);
1644 if (!request_data) {
1646 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1653 request_data, request_data_dma);
1678 __FILE__, __LINE__, __func__);
1685 karg.application_flags = 0;
1686 buffer_type = karg.buffer_type;
1688 if (!_ctl_diag_capability(ioc, buffer_type)) {
1690 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1695 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1697 "registered\n", ioc->
name, __func__, buffer_type);
1701 if (karg.unique_id & 0xffffff00) {
1702 if (karg.unique_id != ioc->
unique_id[buffer_type]) {
1704 "registered\n", ioc->
name, __func__,
1711 if (!request_data) {
1713 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1726 karg.product_specific[i] =
1730 karg.driver_added_buffer_size = 0;
1731 karg.unique_id = ioc->
unique_id[buffer_type];
1736 "data @ %p\n", ioc->
name, __func__, arg);
1758 unsigned long timeleft;
1769 "skipping due to FAULT state\n", ioc->
name,
1777 ioc->
name, __func__);
1785 ioc->
name, __func__);
1797 mpi_request->
VF_ID = 0;
1798 mpi_request->
VP_ID = 0;
1800 init_completion(&ioc->
ctl_cmds.done);
1819 ioc->
name, __func__);
1831 ioc->
name, __func__));
1834 "log_info(0x%08x)\n", ioc->
name, __func__,
1863 __FILE__, __LINE__, __func__);
1870 buffer_type = karg.unique_id & 0x000000ff;
1871 if (!_ctl_diag_capability(ioc, buffer_type)) {
1873 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1878 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1880 "registered\n", ioc->
name, __func__, buffer_type);
1884 if (karg.unique_id != ioc->
unique_id[buffer_type]) {
1886 "registered\n", ioc->
name, __func__, karg.unique_id);
1891 MPT2_DIAG_BUFFER_IS_RELEASED) {
1893 "is already released\n", ioc->
name, __func__,
1900 if (!request_data) {
1902 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1912 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET;
1914 "was released due to host reset\n", ioc->
name, __func__,
1919 rc = _ctl_send_release(ioc, buffer_type, &issue_reset);
1938 void *request_data, *diag_data;
1943 unsigned long timeleft, request_size, copy_size;
1950 __FILE__, __LINE__, __func__);
1957 buffer_type = karg.unique_id & 0x000000ff;
1958 if (!_ctl_diag_capability(ioc, buffer_type)) {
1960 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1964 if (karg.unique_id != ioc->
unique_id[buffer_type]) {
1966 "registered\n", ioc->
name, __func__, karg.unique_id);
1971 if (!request_data) {
1973 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type);
1979 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
1981 "or bytes_to_read are not 4 byte aligned\n", ioc->
name,
1986 if (karg.starting_offset > request_size)
1989 diag_data = (
void *)(request_data + karg.starting_offset);
1991 "offset(%d), sz(%d)\n", ioc->
name, __func__,
1992 diag_data, karg.starting_offset, karg.bytes_to_read));
1995 if ((diag_data + karg.bytes_to_read < diag_data) ||
1996 (diag_data + karg.bytes_to_read > request_data + request_size))
1997 copy_size = request_size - karg.starting_offset;
1999 copy_size = karg.bytes_to_read;
2002 diag_data, copy_size)) {
2004 "mpt_diag_read_buffer_t data @ %p\n", ioc->
name,
2005 __func__, diag_data);
2013 "buffer_type(0x%02x)\n", ioc->
name, __func__, buffer_type));
2015 MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
2017 "buffer_type(0x%02x) is still registered\n", ioc->
name,
2018 __func__, buffer_type));
2026 ioc->
name, __func__);
2034 ioc->
name, __func__);
2054 mpi_request->
VF_ID = 0;
2055 mpi_request->
VP_ID = 0;
2057 init_completion(&ioc->
ctl_cmds.done);
2069 goto issue_host_reset;
2075 ioc->
name, __func__);
2087 ioc->
name, __func__));
2090 "log_info(0x%08x)\n", ioc->
name, __func__,
2107 #ifdef CONFIG_COMPAT
2120 struct mpt2_ioctl_command32 karg32;
2121 struct mpt2_ioctl_command32
__user *uarg;
2124 if (
_IOC_SIZE(cmd) !=
sizeof(
struct mpt2_ioctl_command32))
2127 uarg = (
struct mpt2_ioctl_command32
__user *) arg;
2129 if (
copy_from_user(&karg32, (
char __user *)arg,
sizeof(karg32))) {
2131 __FILE__, __LINE__, __func__);
2136 karg.
hdr.ioc_number = karg32.hdr.ioc_number;
2137 karg.
hdr.port_number = karg32.hdr.port_number;
2138 karg.
hdr.max_data_size = karg32.hdr.max_data_size;
2139 karg.
timeout = karg32.timeout;
2149 return _ctl_do_mpt_command(ioc, karg, &uarg->
mf);
2161 _ctl_ioctl_main(
struct file *
file,
unsigned int cmd,
void __user *arg,
2173 __FILE__, __LINE__, __func__);
2177 if (_ctl_verify_adapter(
ioctl_header.ioc_number, &ioc) == -1 || !ioc)
2194 ret = _ctl_getiocinfo(ioc, arg);
2196 #ifdef CONFIG_COMPAT
2203 #ifdef CONFIG_COMPAT
2205 ret = _ctl_compat_mpt_command(ioc, cmd, arg);
2211 __FILE__, __LINE__, __func__);
2218 ret = _ctl_do_mpt_command(ioc, karg, &uarg->
mf);
2224 ret = _ctl_eventquery(ioc, arg);
2228 ret = _ctl_eventenable(ioc, arg);
2231 ret = _ctl_eventreport(ioc, arg);
2235 ret = _ctl_do_reset(ioc, arg);
2239 ret = _ctl_btdh_mapping(ioc, arg);
2243 ret = _ctl_diag_register(ioc, arg);
2247 ret = _ctl_diag_unregister(ioc, arg);
2251 ret = _ctl_diag_query(ioc, arg);
2255 ret = _ctl_diag_release(ioc, arg);
2259 ret = _ctl_diag_read_buffer(ioc, arg);
2264 "unsupported ioctl opcode(0x%08x)\n", ioc->
name, cmd));
2279 _ctl_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
2283 ret = _ctl_ioctl_main(file, cmd, (
void __user *)arg, 0);
2286 #ifdef CONFIG_COMPAT
2296 _ctl_ioctl_compat(
struct file *file,
unsigned cmd,
unsigned long arg)
2300 ret = _ctl_ioctl_main(file, cmd, (
void __user *)arg, 1);
2322 (ioc->
facts.FWVersion.Word & 0xFF000000) >> 24,
2323 (ioc->
facts.FWVersion.Word & 0x00FF0000) >> 16,
2324 (ioc->
facts.FWVersion.Word & 0x0000FF00) >> 8,
2325 ioc->
facts.FWVersion.Word & 0x000000FF);
2346 (version & 0xFF000000) >> 24,
2347 (version & 0x00FF0000) >> 16,
2348 (version & 0x0000FF00) >> 8,
2349 version & 0x000000FF);
2368 ioc->
facts.MsgVersion, ioc->
facts.HeaderVersion >> 8);
2389 _ctl_version_product_show,
NULL);
2399 _ctl_version_nvdata_persistent_show(
struct device *cdev,
2409 _ctl_version_nvdata_persistent_show,
NULL);
2419 _ctl_version_nvdata_default_show(
struct device *cdev,
2429 _ctl_version_nvdata_default_show,
NULL);
2466 _ctl_board_assembly_show,
NULL);
2485 _ctl_board_tracer_show,
NULL);
2507 _ctl_io_delay_show,
NULL);
2529 _ctl_device_delay_show,
NULL);
2550 _ctl_fw_queue_depth_show,
NULL);
2569 (
unsigned long long)ioc->
sas_hba.sas_address);
2572 _ctl_host_sas_address_show,
NULL);
2592 const char *buf,
size_t count)
2598 if (
sscanf(buf,
"%x", &val) != 1)
2607 _ctl_logging_level_show, _ctl_logging_level_store);
2619 _ctl_fwfault_debug_show(
struct device *cdev,
2628 _ctl_fwfault_debug_store(
struct device *cdev,
2635 if (
sscanf(buf,
"%d", &val) != 1)
2644 _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
2666 _ctl_ioc_reset_count_show,
NULL);
2678 _ctl_ioc_reply_queue_count_show(
struct device *cdev,
2685 if ((ioc->
facts.IOCCapabilities &
2689 reply_queue_count = 1;
2693 _ctl_ioc_reply_queue_count_show,
NULL);
2712 u16 backup_rail_monitor_status = 0;
2719 "warpdrive\n", ioc->
name, __func__);
2728 "for iounit_pg3: (%d) bytes\n", ioc->
name, __func__, sz);
2735 "%s: failed reading iounit_pg3\n", ioc->
name,
2743 "ioc_status(0x%04x)\n", ioc->
name, __func__, ioc_status);
2749 "25 entries, detected (%d) entries\n", ioc->
name, __func__,
2781 _ctl_host_trace_buffer_size_show(
struct device *cdev,
2791 "registered\n", ioc->
name, __func__);
2796 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
2798 "registered\n", ioc->
name, __func__);
2813 _ctl_host_trace_buffer_size_show,
NULL);
2837 "registered\n", ioc->
name, __func__);
2842 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
2844 "registered\n", ioc->
name, __func__);
2854 memcpy(buf, request_data, size);
2860 const char *buf,
size_t count)
2866 if (
sscanf(buf,
"%d", &val) != 1)
2873 _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store);
2887 _ctl_host_trace_buffer_enable_show(
struct device *cdev,
2895 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0))
2898 MPT2_DIAG_BUFFER_IS_RELEASED))
2905 _ctl_host_trace_buffer_enable_store(
struct device *cdev,
2914 if (
sscanf(buf,
"%9s", str) != 1)
2917 if (!
strcmp(str,
"post")) {
2921 MPT2_DIAG_BUFFER_IS_REGISTERED) &&
2923 MPT2_DIAG_BUFFER_IS_RELEASED) == 0))
2932 _ctl_diag_register_2(ioc, &diag_register);
2933 }
else if (!
strcmp(str,
"release")) {
2938 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0)
2941 MPT2_DIAG_BUFFER_IS_RELEASED))
2952 _ctl_host_trace_buffer_enable_show, _ctl_host_trace_buffer_enable_store);
2955 &dev_attr_version_fw,
2956 &dev_attr_version_bios,
2957 &dev_attr_version_mpi,
2958 &dev_attr_version_product,
2959 &dev_attr_version_nvdata_persistent,
2960 &dev_attr_version_nvdata_default,
2961 &dev_attr_board_name,
2962 &dev_attr_board_assembly,
2963 &dev_attr_board_tracer,
2965 &dev_attr_device_delay,
2966 &dev_attr_logging_level,
2967 &dev_attr_fwfault_debug,
2968 &dev_attr_fw_queue_depth,
2969 &dev_attr_host_sas_address,
2970 &dev_attr_ioc_reset_count,
2971 &dev_attr_host_trace_buffer_size,
2972 &dev_attr_host_trace_buffer,
2973 &dev_attr_host_trace_buffer_enable,
2974 &dev_attr_reply_queue_count,
2975 &dev_attr_BRM_status,
2996 (
unsigned long long)sas_device_priv_data->
sas_target->sas_address);
3022 &dev_attr_sas_address,
3023 &dev_attr_sas_device_handle,
3029 .unlocked_ioctl = _ctl_ioctl,
3030 .release = _ctl_release,
3032 .fasync = _ctl_fasync,
3033 #ifdef CONFIG_COMPAT
3034 .compat_ioctl = _ctl_ioctl_compat,