44 #include <linux/module.h>
45 #include <linux/kernel.h>
47 #include <linux/errno.h>
48 #include <linux/sched.h>
51 #include <linux/pci.h>
52 #include <linux/slab.h>
54 #include <scsi/scsi.h>
75 if (ioc->
sas_hba.sas_address == sas_address)
145 __func__, ioc->
name);
153 ioc->
name, __FILE__, __LINE__, __func__);
161 "\nfailure at %s:%d/%s()!\n", ioc->
name, handle, ioc_status,
162 __FILE__, __LINE__, __func__);
298 unsigned long timeleft;
305 u16 wait_state_count;
309 __func__, ioc->
name);
317 ioc->
name, __func__);
323 wait_state_count = 0;
326 if (wait_state_count++ == 10) {
328 "%s: failed due to ioc not operational\n",
329 ioc->
name, __func__);
336 "operational state(count=%d)\n", ioc->
name,
337 __func__, wait_state_count);
339 if (wait_state_count)
341 ioc->
name, __func__);
346 ioc->
name, __func__);
366 manufacture_request = data_out;
375 mpi_request->
VF_ID = 0;
376 mpi_request->
VP_ID = 0;
380 psge = &mpi_request->
SGL;
402 "send to sas_addr(0x%016llx)\n", ioc->
name,
403 (
unsigned long long)sas_address));
411 ioc->
name, __func__);
416 goto issue_host_reset;
420 "complete\n", ioc->
name));
428 "report_manufacture - reply data transfer size(%d)\n",
454 "report_manufacture - no reply\n", ioc->
name));
485 "remove: sas_addr(0x%016llx)\n",
486 (
unsigned long long) sas_address);
512 "remove: sas_addr(0x%016llx), phy(%d)\n",
513 (
unsigned long long) sas_address, mpt2sas_phy->
phy_id);
536 "add: sas_addr(0x%016llx), phy(%d)\n", (
unsigned long long)
537 sas_address, mpt2sas_phy->
phy_id);
571 if (phy_srch == mpt2sas_phy)
574 _transport_add_phy(ioc, mpt2sas_port, mpt2sas_phy);
602 if (phy_srch != mpt2sas_phy)
605 _transport_delete_port(ioc, mpt2sas_port);
607 _transport_delete_phy(ioc, mpt2sas_port,
628 for (i = 0; i < sas_node->
num_phys; i++) {
629 if (sas_node->
phy[i].remote_identify.sas_address != sas_address)
631 if (sas_node->
phy[i].phy_belongs_to_port == 1)
632 _transport_del_phy_from_an_existing_port(ioc, sas_node,
660 mpt2sas_port = kzalloc(
sizeof(
struct _sas_port),
664 ioc->
name, __FILE__, __LINE__, __func__);
668 INIT_LIST_HEAD(&mpt2sas_port->
port_list);
669 INIT_LIST_HEAD(&mpt2sas_port->
phy_list);
671 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
676 "parent sas_address(0x%016llx)!\n", ioc->
name,
677 __func__, (
unsigned long long)sas_address);
681 if ((_transport_set_identify(ioc, handle,
684 ioc->
name, __FILE__, __LINE__, __func__);
690 ioc->
name, __FILE__, __LINE__, __func__);
694 _transport_sanity_check(ioc, sas_node,
697 for (i = 0; i < sas_node->
num_phys; i++) {
698 if (sas_node->
phy[i].remote_identify.sas_address !=
708 ioc->
name, __FILE__, __LINE__, __func__);
715 ioc->
name, __FILE__, __LINE__, __func__);
723 ", sas_addr(0x%016llx), phy(%d)\n", handle,
741 ioc->
name, __FILE__, __LINE__, __func__);
744 dev_printk(
KERN_INFO, &rphy->
dev,
"add: handle(0x%04x), "
745 "sas_addr(0x%016llx)\n", handle,
758 _transport_expander_report_manufacture(ioc,
786 u64 sas_address_parent)
793 struct _sas_phy *mpt2sas_phy, *next_phy;
796 sas_node = _transport_sas_node_find_by_sas_address(ioc,
816 for (i = 0; i < sas_node->
num_phys; i++) {
817 if (sas_node->
phy[i].remote_identify.sas_address == sas_address)
818 memset(&sas_node->
phy[i].remote_identify, 0 ,
827 "remove: sas_addr(0x%016llx), phy(%d)\n",
853 int phy_index = mpt2sas_phy->
phy_id;
860 ioc->
name, __FILE__, __LINE__, __func__);
863 if ((_transport_set_identify(ioc, mpt2sas_phy->
handle,
866 ioc->
name, __FILE__, __LINE__, __func__);
888 ioc->
name, __FILE__, __LINE__, __func__);
894 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
895 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
896 mpt2sas_phy->
handle, (
unsigned long long)
920 int phy_index = mpt2sas_phy->
phy_id;
926 ioc->
name, __FILE__, __LINE__, __func__);
929 if ((_transport_set_identify(ioc, mpt2sas_phy->
handle,
932 ioc->
name, __FILE__, __LINE__, __func__);
956 ioc->
name, __FILE__, __LINE__, __func__);
962 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
963 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
964 mpt2sas_phy->
handle, (
unsigned long long)
985 u64 sas_address,
u16 handle,
u8 phy_number,
u8 link_rate)
995 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
1001 mpt2sas_phy = &sas_node->
phy[phy_number];
1005 _transport_set_identify(ioc, handle,
1007 _transport_add_phy_to_an_existing_port(ioc, sas_node,
1013 if (mpt2sas_phy->
phy)
1014 mpt2sas_phy->
phy->negotiated_linkrate =
1015 _transport_convert_phy_link_rate(link_rate);
1019 "refresh: parent sas_addr(0x%016llx),\n"
1020 "\tlink_rate(0x%02x), phy(%d)\n"
1021 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1022 (
unsigned long long)sas_address,
1023 link_rate, phy_number, handle, (
unsigned long long)
1027 static inline void *
1031 return shost_priv(shost);
1034 static inline void *
1038 return shost_priv(shost);
1088 unsigned long timeleft;
1092 void *data_out =
NULL;
1095 u16 wait_state_count;
1099 __func__, ioc->
name);
1107 ioc->
name, __func__);
1113 wait_state_count = 0;
1116 if (wait_state_count++ == 10) {
1118 "%s: failed due to ioc not operational\n",
1119 ioc->
name, __func__);
1126 "operational state(count=%d)\n", ioc->
name,
1127 __func__, wait_state_count);
1129 if (wait_state_count)
1131 ioc->
name, __func__);
1136 ioc->
name, __func__);
1144 sz =
sizeof(
struct phy_error_log_request) +
1149 __LINE__, __func__);
1157 phy_error_log_request = data_out;
1159 phy_error_log_request->
function = 0x11;
1167 mpi_request->
VF_ID = 0;
1168 mpi_request->
VP_ID = 0;
1171 cpu_to_le16(
sizeof(
struct phy_error_log_request));
1172 psge = &mpi_request->
SGL;
1179 sizeof(
struct phy_error_log_request), data_out_dma);
1190 sizeof(
struct phy_error_log_reply), data_out_dma +
1191 sizeof(
struct phy_error_log_request));
1194 "send to sas_addr(0x%016llx), phy(%d)\n", ioc->
name,
1203 ioc->
name, __func__);
1208 goto issue_host_reset;
1212 "complete\n", ioc->
name));
1219 "phy_error_log - reply data transfer size(%d)\n",
1223 sizeof(
struct phy_error_log_reply))
1226 phy_error_log_reply = data_out +
1227 sizeof(
struct phy_error_log_request);
1230 "phy_error_log - function_result(%d)\n",
1244 "phy_error_log - no reply\n", ioc->
name));
1267 _transport_get_linkerrors(
struct sas_phy *phy)
1270 unsigned long flags;
1275 if (_transport_sas_node_find_by_sas_address(ioc,
1283 return _transport_get_expander_phy_error_log(ioc, phy);
1289 ioc->
name, __FILE__, __LINE__, __func__);
1295 "(0x%04x), loginfo(0x%08x)\n", ioc->
name,
1321 unsigned long flags;
1345 _transport_get_bay_identifier(
struct sas_rphy *rphy)
1349 unsigned long flags;
1356 rc = sas_device->
slot;
1388 #define SMP_PHY_CONTROL_LINK_RESET (0x01)
1389 #define SMP_PHY_CONTROL_HARD_RESET (0x02)
1390 #define SMP_PHY_CONTROL_DISABLE (0x03)
1411 unsigned long timeleft;
1415 void *data_out =
NULL;
1418 u16 wait_state_count;
1422 __func__, ioc->
name);
1430 ioc->
name, __func__);
1436 wait_state_count = 0;
1439 if (wait_state_count++ == 10) {
1441 "%s: failed due to ioc not operational\n",
1442 ioc->
name, __func__);
1449 "operational state(count=%d)\n", ioc->
name,
1450 __func__, wait_state_count);
1452 if (wait_state_count)
1454 ioc->
name, __func__);
1459 ioc->
name, __func__);
1467 sz =
sizeof(
struct phy_control_request) +
1468 sizeof(struct phy_control_reply);
1472 __LINE__, __func__);
1480 phy_control_request = data_out;
1482 phy_control_request->
function = 0x91;
1495 mpi_request->
VF_ID = 0;
1496 mpi_request->
VP_ID = 0;
1499 cpu_to_le16(
sizeof(
struct phy_error_log_request));
1500 psge = &mpi_request->
SGL;
1507 sizeof(
struct phy_control_request), data_out_dma);
1518 sizeof(
struct phy_control_reply), data_out_dma +
1519 sizeof(
struct phy_control_request));
1522 "send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n", ioc->
name,
1533 ioc->
name, __func__);
1538 goto issue_host_reset;
1542 "complete\n", ioc->
name));
1549 "phy_control - reply data transfer size(%d)\n",
1553 sizeof(
struct phy_control_reply))
1556 phy_control_reply = data_out +
1557 sizeof(
struct phy_control_request);
1560 "phy_control - function_result(%d)\n",
1561 ioc->
name, phy_control_reply->function_result));
1566 "phy_control - no reply\n", ioc->
name));
1589 _transport_phy_reset(
struct sas_phy *phy,
int hard_reset)
1594 unsigned long flags;
1597 if (_transport_sas_node_find_by_sas_address(ioc,
1606 return _transport_expander_phy_control(ioc, phy,
1619 ioc->
name, __FILE__, __LINE__, __func__);
1625 "(0x%04x), loginfo(0x%08x)\n", ioc->
name,
1650 unsigned long flags;
1651 int i, discovery_active;
1654 if (_transport_sas_node_find_by_sas_address(ioc,
1663 return _transport_expander_phy_control(ioc, phy,
1673 if (!sas_iounit_pg0) {
1675 ioc->
name, __FILE__, __LINE__, __func__);
1680 sas_iounit_pg0, sz))) {
1682 ioc->
name, __FILE__, __LINE__, __func__);
1690 ioc->
name, __FILE__, __LINE__, __func__);
1696 for (i = 0, discovery_active = 0; i < ioc->
sas_hba.num_phys ; i++) {
1700 "port = %d, phy = %d: unable to enable/disable "
1701 "phys, try again later!\n", ioc->
name,
1703 discovery_active = 1;
1707 if (discovery_active) {
1716 if (!sas_iounit_pg1) {
1718 ioc->
name, __FILE__, __LINE__, __func__);
1723 sas_iounit_pg1, sz))) {
1725 ioc->
name, __FILE__, __LINE__, __func__);
1733 ioc->
name, __FILE__, __LINE__, __func__);
1738 for (i = 0; i < ioc->
sas_hba.num_phys ; i++) {
1760 _transport_phy_reset(phy, 0);
1763 kfree(sas_iounit_pg1);
1764 kfree(sas_iounit_pg0);
1787 unsigned long flags;
1790 if (_transport_sas_node_find_by_sas_address(ioc,
1811 return _transport_expander_phy_control(ioc, phy,
1821 if (!sas_iounit_pg1) {
1823 ioc->
name, __FILE__, __LINE__, __func__);
1828 sas_iounit_pg1, sz))) {
1830 ioc->
name, __FILE__, __LINE__, __func__);
1838 ioc->
name, __FILE__, __LINE__, __func__);
1843 for (i = 0; i < ioc->
sas_hba.num_phys; i++) {
1846 (ioc->
sas_hba.phy[
i].phy->minimum_linkrate +
1847 (ioc->
sas_hba.phy[
i].phy->maximum_linkrate << 4));
1858 ioc->
name, __FILE__, __LINE__, __func__);
1864 _transport_phy_reset(phy, 0);
1879 kfree(sas_iounit_pg1);
1904 unsigned long timeleft;
1912 void *pci_addr_in =
NULL;
1913 void *pci_addr_out =
NULL;
1914 u16 wait_state_count;
1916 struct bio_vec *bvec =
NULL;
1920 "missing\n", ioc->
name, __func__);
1925 __func__, ioc->
name);
1942 if (req->bio->bi_vcnt > 1) {
1947 blk_rq_bytes(req), &pci_dma_out);
1948 if (!pci_addr_out) {
1950 ioc->
name, __func__);
1955 bio_for_each_segment(bvec, req->bio, i) {
1956 memcpy(pci_addr_out + offset,
1959 offset += bvec->bv_len;
1962 dma_addr_out = pci_map_single(ioc->
pdev, bio_data(req->bio),
1964 if (!dma_addr_out) {
1966 ioc->
name, __func__);
1974 if (rsp->bio->bi_vcnt > 1) {
1979 ioc->
name, __func__);
1984 dma_addr_in = pci_map_single(ioc->
pdev, bio_data(rsp->bio),
1988 ioc->
name, __func__);
1994 wait_state_count = 0;
1997 if (wait_state_count++ == 10) {
1999 "%s: failed due to ioc not operational\n",
2000 ioc->
name, __func__);
2007 "operational state(count=%d)\n", ioc->
name,
2008 __func__, wait_state_count);
2010 if (wait_state_count)
2012 ioc->
name, __func__);
2017 ioc->
name, __func__);
2029 mpi_request->
VF_ID = 0;
2030 mpi_request->
VP_ID = 0;
2035 psge = &mpi_request->
SGL;
2041 if (req->bio->bi_vcnt > 1) {
2043 (blk_rq_bytes(req) - 4), pci_dma_out);
2046 (blk_rq_bytes(req) - 4), dma_addr_out);
2057 if (rsp->bio->bi_vcnt > 1) {
2059 (blk_rq_bytes(rsp) + 4), pci_dma_in);
2062 (blk_rq_bytes(rsp) + 4), dma_addr_in);
2066 "sending smp request\n", ioc->
name, __func__));
2075 __func__, ioc->
name);
2080 goto issue_host_reset;
2084 "complete\n", ioc->
name, __func__));
2091 "%s - reply data transfer size(%d)\n",
2092 ioc->
name, __func__,
2095 memcpy(req->sense, mpi_reply,
sizeof(*mpi_reply));
2096 req->sense_len =
sizeof(*mpi_reply);
2102 if (rsp->bio->bi_vcnt > 1) {
2106 bio_for_each_segment(bvec, rsp->bio, i) {
2107 if (bytes_to_copy <= bvec->bv_len) {
2109 bvec->bv_offset, pci_addr_in +
2110 offset, bytes_to_copy);
2114 bvec->bv_offset, pci_addr_in +
2115 offset, bvec->bv_len);
2116 bytes_to_copy -= bvec->bv_len;
2118 offset += bvec->bv_len;
2123 "%s - no reply\n", ioc->
name, __func__));
2136 pci_unmap_single(ioc->
pdev, dma_addr_out, blk_rq_bytes(req),
2139 pci_unmap_single(ioc->
pdev, dma_addr_in, blk_rq_bytes(rsp),
2158 .get_linkerrors = _transport_get_linkerrors,
2159 .get_enclosure_identifier = _transport_get_enclosure_identifier,
2160 .get_bay_identifier = _transport_get_bay_identifier,
2161 .phy_reset = _transport_phy_reset,
2162 .phy_enable = _transport_phy_enable,
2163 .set_phy_speed = _transport_phy_speed,
2164 .smp_handler = _transport_smp_handler,