James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Serial Attached SCSI (SAS) Phy class |
| 3 | * |
| 4 | * Copyright (C) 2005 Adaptec, Inc. All rights reserved. |
| 5 | * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com> |
| 6 | * |
| 7 | * This file is licensed under GPLv2. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of the |
| 12 | * License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "sas_internal.h" |
| 26 | #include <scsi/scsi_host.h> |
| 27 | #include <scsi/scsi_transport.h> |
| 28 | #include <scsi/scsi_transport_sas.h> |
| 29 | #include "../scsi_sas_internal.h" |
| 30 | |
| 31 | /* ---------- Phy events ---------- */ |
| 32 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 33 | static void sas_phye_loss_of_signal(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 34 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 35 | struct asd_sas_event *ev = |
| 36 | container_of(work, struct asd_sas_event, work); |
| 37 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 38 | |
Dan Williams | b15ebe0 | 2011-11-17 17:59:49 -0800 | [diff] [blame] | 39 | clear_bit(PHYE_LOSS_OF_SIGNAL, &phy->phy_events_pending); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 40 | phy->error = 0; |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 41 | sas_deform_port(phy, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 42 | } |
| 43 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 44 | static void sas_phye_oob_done(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 45 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 46 | struct asd_sas_event *ev = |
| 47 | container_of(work, struct asd_sas_event, work); |
| 48 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 49 | |
Dan Williams | b15ebe0 | 2011-11-17 17:59:49 -0800 | [diff] [blame] | 50 | clear_bit(PHYE_OOB_DONE, &phy->phy_events_pending); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 51 | phy->error = 0; |
| 52 | } |
| 53 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 54 | static void sas_phye_oob_error(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 55 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 56 | struct asd_sas_event *ev = |
| 57 | container_of(work, struct asd_sas_event, work); |
| 58 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 59 | struct sas_ha_struct *sas_ha = phy->ha; |
| 60 | struct asd_sas_port *port = phy->port; |
| 61 | struct sas_internal *i = |
| 62 | to_sas_internal(sas_ha->core.shost->transportt); |
| 63 | |
Dan Williams | b15ebe0 | 2011-11-17 17:59:49 -0800 | [diff] [blame] | 64 | clear_bit(PHYE_OOB_ERROR, &phy->phy_events_pending); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 65 | |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 66 | sas_deform_port(phy, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 67 | |
| 68 | if (!port && phy->enabled && i->dft->lldd_control_phy) { |
| 69 | phy->error++; |
| 70 | switch (phy->error) { |
| 71 | case 1: |
| 72 | case 2: |
James Bottomley | a01e70e | 2006-09-06 19:28:07 -0500 | [diff] [blame] | 73 | i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET, |
| 74 | NULL); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 75 | break; |
| 76 | case 3: |
| 77 | default: |
| 78 | phy->error = 0; |
| 79 | phy->enabled = 0; |
James Bottomley | a01e70e | 2006-09-06 19:28:07 -0500 | [diff] [blame] | 80 | i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 86 | static void sas_phye_spinup_hold(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 87 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 88 | struct asd_sas_event *ev = |
| 89 | container_of(work, struct asd_sas_event, work); |
| 90 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 91 | struct sas_ha_struct *sas_ha = phy->ha; |
| 92 | struct sas_internal *i = |
| 93 | to_sas_internal(sas_ha->core.shost->transportt); |
| 94 | |
Dan Williams | b15ebe0 | 2011-11-17 17:59:49 -0800 | [diff] [blame] | 95 | clear_bit(PHYE_SPINUP_HOLD, &phy->phy_events_pending); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 96 | |
| 97 | phy->error = 0; |
James Bottomley | a01e70e | 2006-09-06 19:28:07 -0500 | [diff] [blame] | 98 | i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* ---------- Phy class registration ---------- */ |
| 102 | |
| 103 | int sas_register_phys(struct sas_ha_struct *sas_ha) |
| 104 | { |
| 105 | int i; |
| 106 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 107 | static const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 108 | [PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal, |
| 109 | [PHYE_OOB_DONE] = sas_phye_oob_done, |
| 110 | [PHYE_OOB_ERROR] = sas_phye_oob_error, |
| 111 | [PHYE_SPINUP_HOLD] = sas_phye_spinup_hold, |
| 112 | }; |
| 113 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 114 | static const work_func_t sas_port_event_fns[PORT_NUM_EVENTS] = { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 115 | [PORTE_BYTES_DMAED] = sas_porte_bytes_dmaed, |
| 116 | [PORTE_BROADCAST_RCVD] = sas_porte_broadcast_rcvd, |
| 117 | [PORTE_LINK_RESET_ERR] = sas_porte_link_reset_err, |
| 118 | [PORTE_TIMER_EVENT] = sas_porte_timer_event, |
| 119 | [PORTE_HARD_RESET] = sas_porte_hard_reset, |
| 120 | }; |
| 121 | |
| 122 | /* Now register the phys. */ |
| 123 | for (i = 0; i < sas_ha->num_phys; i++) { |
| 124 | int k; |
| 125 | struct asd_sas_phy *phy = sas_ha->sas_phy[i]; |
| 126 | |
| 127 | phy->error = 0; |
| 128 | INIT_LIST_HEAD(&phy->port_phy_el); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 129 | for (k = 0; k < PORT_NUM_EVENTS; k++) { |
| 130 | INIT_WORK(&phy->port_events[k].work, |
| 131 | sas_port_event_fns[k]); |
| 132 | phy->port_events[k].phy = phy; |
| 133 | } |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 134 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 135 | for (k = 0; k < PHY_NUM_EVENTS; k++) { |
| 136 | INIT_WORK(&phy->phy_events[k].work, |
| 137 | sas_phy_event_fns[k]); |
| 138 | phy->phy_events[k].phy = phy; |
| 139 | } |
| 140 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 141 | phy->port = NULL; |
| 142 | phy->ha = sas_ha; |
| 143 | spin_lock_init(&phy->frame_rcvd_lock); |
| 144 | spin_lock_init(&phy->sas_prim_lock); |
| 145 | phy->frame_rcvd_size = 0; |
| 146 | |
| 147 | phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, |
| 148 | i); |
| 149 | if (!phy->phy) |
| 150 | return -ENOMEM; |
| 151 | |
| 152 | phy->phy->identify.initiator_port_protocols = |
| 153 | phy->iproto; |
| 154 | phy->phy->identify.target_port_protocols = phy->tproto; |
| 155 | phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr); |
| 156 | phy->phy->identify.phy_identifier = i; |
James Bottomley | a01e70e | 2006-09-06 19:28:07 -0500 | [diff] [blame] | 157 | phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; |
| 158 | phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; |
| 159 | phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN; |
| 160 | phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 161 | phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; |
| 162 | |
| 163 | sas_phy_add(phy->phy); |
| 164 | } |
| 165 | |
| 166 | return 0; |
| 167 | } |