2 * SAS Transport Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_transport.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
54 #include <scsi/scsi.h>
55 #include <scsi/scsi_cmnd.h>
56 #include <scsi/scsi_device.h>
57 #include <scsi/scsi_host.h>
58 #include <scsi/scsi_transport_sas.h>
59 #include <scsi/scsi_dbg.h>
61 #include "mpt3sas_base.h"
64 * _transport_sas_node_find_by_sas_address - sas node search
65 * @ioc: per adapter object
66 * @sas_address: sas address of expander or sas host
67 * Context: Calling function should acquire ioc->sas_node_lock.
69 * Search for either hba phys or expander device based on handle, then returns
70 * the sas_node object.
72 static struct _sas_node *
73 _transport_sas_node_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
76 if (ioc->sas_hba.sas_address == sas_address)
79 return mpt3sas_scsih_expander_find_by_sas_address(ioc,
84 * _transport_convert_phy_link_rate -
85 * @link_rate: link rate returned from mpt firmware
87 * Convert link_rate from mpi fusion into sas_transport form.
89 static enum sas_linkrate
90 _transport_convert_phy_link_rate(u8 link_rate)
95 case MPI2_SAS_NEG_LINK_RATE_1_5:
96 rc = SAS_LINK_RATE_1_5_GBPS;
98 case MPI2_SAS_NEG_LINK_RATE_3_0:
99 rc = SAS_LINK_RATE_3_0_GBPS;
101 case MPI2_SAS_NEG_LINK_RATE_6_0:
102 rc = SAS_LINK_RATE_6_0_GBPS;
104 case MPI25_SAS_NEG_LINK_RATE_12_0:
105 rc = SAS_LINK_RATE_12_0_GBPS;
107 case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED:
108 rc = SAS_PHY_DISABLED;
110 case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED:
111 rc = SAS_LINK_RATE_FAILED;
113 case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR:
114 rc = SAS_SATA_PORT_SELECTOR;
116 case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS:
117 rc = SAS_PHY_RESET_IN_PROGRESS;
121 case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE:
122 case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE:
123 rc = SAS_LINK_RATE_UNKNOWN;
130 * _transport_set_identify - set identify for phys and end devices
131 * @ioc: per adapter object
132 * @handle: device handle
133 * @identify: sas identify info
135 * Populates sas identify info.
137 * Returns 0 for success, non-zero for failure.
140 _transport_set_identify(struct MPT3SAS_ADAPTER *ioc, u16 handle,
141 struct sas_identify *identify)
143 Mpi2SasDevicePage0_t sas_device_pg0;
144 Mpi2ConfigReply_t mpi_reply;
148 if (ioc->shost_recovery || ioc->pci_error_recovery) {
149 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
150 __func__, ioc->name);
154 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
155 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
156 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
157 ioc->name, __FILE__, __LINE__, __func__);
161 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
163 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
165 "handle(0x%04x), ioc_status(0x%04x)\nfailure at %s:%d/%s()!\n",
166 ioc->name, handle, ioc_status,
167 __FILE__, __LINE__, __func__);
171 memset(identify, 0, sizeof(struct sas_identify));
172 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
175 identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
177 /* phy number of the parent device this device is linked to */
178 identify->phy_identifier = sas_device_pg0.PhyNum;
181 switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
182 case MPI2_SAS_DEVICE_INFO_NO_DEVICE:
183 identify->device_type = SAS_PHY_UNUSED;
185 case MPI2_SAS_DEVICE_INFO_END_DEVICE:
186 identify->device_type = SAS_END_DEVICE;
188 case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER:
189 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
191 case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER:
192 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
196 /* initiator_port_protocols */
197 if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR)
198 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
199 if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR)
200 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
201 if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR)
202 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
203 if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST)
204 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
206 /* target_port_protocols */
207 if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET)
208 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
209 if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
210 identify->target_port_protocols |= SAS_PROTOCOL_STP;
211 if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET)
212 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
213 if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
214 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
220 * mpt3sas_transport_done - internal transport layer callback handler.
221 * @ioc: per adapter object
222 * @smid: system request message index
223 * @msix_index: MSIX table index supplied by the OS
224 * @reply: reply message frame(lower 32bit addr)
226 * Callback handler when sending internal generated transport cmds.
227 * The callback index passed is `ioc->transport_cb_idx`
229 * Return 1 meaning mf should be freed from _base_interrupt
230 * 0 means the mf is freed from this function.
233 mpt3sas_transport_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
236 MPI2DefaultReply_t *mpi_reply;
238 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
239 if (ioc->transport_cmds.status == MPT3_CMD_NOT_USED)
241 if (ioc->transport_cmds.smid != smid)
243 ioc->transport_cmds.status |= MPT3_CMD_COMPLETE;
245 memcpy(ioc->transport_cmds.reply, mpi_reply,
246 mpi_reply->MsgLength*4);
247 ioc->transport_cmds.status |= MPT3_CMD_REPLY_VALID;
249 ioc->transport_cmds.status &= ~MPT3_CMD_PENDING;
250 complete(&ioc->transport_cmds.done);
254 /* report manufacture request structure */
255 struct rep_manu_request {
262 /* report manufacture reply structure */
263 struct rep_manu_reply {
264 u8 smp_frame_type; /* 0x41 */
265 u8 function; /* 0x01 */
268 u16 expander_change_count;
272 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
273 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
274 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
275 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
277 u8 component_revision_id;
279 u8 vendor_specific[8];
283 * transport_expander_report_manufacture - obtain SMP report_manufacture
284 * @ioc: per adapter object
285 * @sas_address: expander sas address
286 * @edev: the sas_expander_device object
288 * Fills in the sas_expander_device object when SMP port is created.
290 * Returns 0 for success, non-zero for failure.
293 _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc,
294 u64 sas_address, struct sas_expander_device *edev)
296 Mpi2SmpPassthroughRequest_t *mpi_request;
297 Mpi2SmpPassthroughReply_t *mpi_reply;
298 struct rep_manu_reply *manufacture_reply;
299 struct rep_manu_request *manufacture_request;
305 void *data_out = NULL;
306 dma_addr_t data_out_dma;
307 dma_addr_t data_in_dma;
310 u16 wait_state_count;
312 if (ioc->shost_recovery || ioc->pci_error_recovery) {
313 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
314 __func__, ioc->name);
318 mutex_lock(&ioc->transport_cmds.mutex);
320 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
321 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
322 ioc->name, __func__);
326 ioc->transport_cmds.status = MPT3_CMD_PENDING;
328 wait_state_count = 0;
329 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
330 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
331 if (wait_state_count++ == 10) {
333 "%s: failed due to ioc not operational\n",
334 ioc->name, __func__);
339 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
341 "%s: waiting for operational state(count=%d)\n",
342 ioc->name, __func__, wait_state_count);
344 if (wait_state_count)
345 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
346 ioc->name, __func__);
348 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
350 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
351 ioc->name, __func__);
357 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
358 ioc->transport_cmds.smid = smid;
360 data_out_sz = sizeof(struct rep_manu_request);
361 data_in_sz = sizeof(struct rep_manu_reply);
362 data_out = pci_alloc_consistent(ioc->pdev, data_out_sz + data_in_sz,
366 pr_err("failure at %s:%d/%s()!\n", __FILE__,
369 mpt3sas_base_free_smid(ioc, smid);
373 data_in_dma = data_out_dma + sizeof(struct rep_manu_request);
375 manufacture_request = data_out;
376 manufacture_request->smp_frame_type = 0x40;
377 manufacture_request->function = 1;
378 manufacture_request->reserved = 0;
379 manufacture_request->request_length = 0;
381 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
382 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
383 mpi_request->PhysicalPort = 0xFF;
384 mpi_request->SASAddress = cpu_to_le64(sas_address);
385 mpi_request->RequestDataLength = cpu_to_le16(data_out_sz);
386 psge = &mpi_request->SGL;
388 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
391 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
392 "report_manufacture - send to sas_addr(0x%016llx)\n",
393 ioc->name, (unsigned long long)sas_address));
394 init_completion(&ioc->transport_cmds.done);
395 ioc->put_smid_default(ioc, smid);
396 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
398 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
399 pr_err(MPT3SAS_FMT "%s: timeout\n",
400 ioc->name, __func__);
401 _debug_dump_mf(mpi_request,
402 sizeof(Mpi2SmpPassthroughRequest_t)/4);
403 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
405 goto issue_host_reset;
408 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
409 "report_manufacture - complete\n", ioc->name));
411 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
414 mpi_reply = ioc->transport_cmds.reply;
416 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
417 "report_manufacture - reply data transfer size(%d)\n",
418 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
420 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
421 sizeof(struct rep_manu_reply))
424 manufacture_reply = data_out + sizeof(struct rep_manu_request);
425 strncpy(edev->vendor_id, manufacture_reply->vendor_id,
426 SAS_EXPANDER_VENDOR_ID_LEN);
427 strncpy(edev->product_id, manufacture_reply->product_id,
428 SAS_EXPANDER_PRODUCT_ID_LEN);
429 strncpy(edev->product_rev, manufacture_reply->product_rev,
430 SAS_EXPANDER_PRODUCT_REV_LEN);
431 edev->level = manufacture_reply->sas_format & 1;
433 strncpy(edev->component_vendor_id,
434 manufacture_reply->component_vendor_id,
435 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
436 tmp = (u8 *)&manufacture_reply->component_id;
437 edev->component_id = tmp[0] << 8 | tmp[1];
438 edev->component_revision_id =
439 manufacture_reply->component_revision_id;
442 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
443 "report_manufacture - no reply\n", ioc->name));
447 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
449 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
451 pci_free_consistent(ioc->pdev, data_out_sz + data_in_sz,
452 data_out, data_out_dma);
454 mutex_unlock(&ioc->transport_cmds.mutex);
460 * _transport_delete_port - helper function to removing a port
461 * @ioc: per adapter object
462 * @mpt3sas_port: mpt3sas per port object
467 _transport_delete_port(struct MPT3SAS_ADAPTER *ioc,
468 struct _sas_port *mpt3sas_port)
470 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
471 enum sas_device_type device_type =
472 mpt3sas_port->remote_identify.device_type;
474 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
475 "remove: sas_addr(0x%016llx)\n",
476 (unsigned long long) sas_address);
478 ioc->logging_level |= MPT_DEBUG_TRANSPORT;
479 if (device_type == SAS_END_DEVICE)
480 mpt3sas_device_remove_by_sas_address(ioc, sas_address);
481 else if (device_type == SAS_EDGE_EXPANDER_DEVICE ||
482 device_type == SAS_FANOUT_EXPANDER_DEVICE)
483 mpt3sas_expander_remove(ioc, sas_address);
484 ioc->logging_level &= ~MPT_DEBUG_TRANSPORT;
488 * _transport_delete_phy - helper function to removing single phy from port
489 * @ioc: per adapter object
490 * @mpt3sas_port: mpt3sas per port object
491 * @mpt3sas_phy: mpt3sas per phy object
496 _transport_delete_phy(struct MPT3SAS_ADAPTER *ioc,
497 struct _sas_port *mpt3sas_port, struct _sas_phy *mpt3sas_phy)
499 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
501 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
502 "remove: sas_addr(0x%016llx), phy(%d)\n",
503 (unsigned long long) sas_address, mpt3sas_phy->phy_id);
505 list_del(&mpt3sas_phy->port_siblings);
506 mpt3sas_port->num_phys--;
507 sas_port_delete_phy(mpt3sas_port->port, mpt3sas_phy->phy);
508 mpt3sas_phy->phy_belongs_to_port = 0;
512 * _transport_add_phy - helper function to adding single phy to port
513 * @ioc: per adapter object
514 * @mpt3sas_port: mpt3sas per port object
515 * @mpt3sas_phy: mpt3sas per phy object
520 _transport_add_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_port *mpt3sas_port,
521 struct _sas_phy *mpt3sas_phy)
523 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
525 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
526 "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
527 sas_address, mpt3sas_phy->phy_id);
529 list_add_tail(&mpt3sas_phy->port_siblings, &mpt3sas_port->phy_list);
530 mpt3sas_port->num_phys++;
531 sas_port_add_phy(mpt3sas_port->port, mpt3sas_phy->phy);
532 mpt3sas_phy->phy_belongs_to_port = 1;
536 * _transport_add_phy_to_an_existing_port - adding new phy to existing port
537 * @ioc: per adapter object
538 * @sas_node: sas node object (either expander or sas host)
539 * @mpt3sas_phy: mpt3sas per phy object
540 * @sas_address: sas address of device/expander were phy needs to be added to
545 _transport_add_phy_to_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
546 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy,
549 struct _sas_port *mpt3sas_port;
550 struct _sas_phy *phy_srch;
552 if (mpt3sas_phy->phy_belongs_to_port == 1)
555 list_for_each_entry(mpt3sas_port, &sas_node->sas_port_list,
557 if (mpt3sas_port->remote_identify.sas_address !=
560 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
562 if (phy_srch == mpt3sas_phy)
565 _transport_add_phy(ioc, mpt3sas_port, mpt3sas_phy);
572 * _transport_del_phy_from_an_existing_port - delete phy from existing port
573 * @ioc: per adapter object
574 * @sas_node: sas node object (either expander or sas host)
575 * @mpt3sas_phy: mpt3sas per phy object
580 _transport_del_phy_from_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
581 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy)
583 struct _sas_port *mpt3sas_port, *next;
584 struct _sas_phy *phy_srch;
586 if (mpt3sas_phy->phy_belongs_to_port == 0)
589 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
591 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
593 if (phy_srch != mpt3sas_phy)
596 if (mpt3sas_port->num_phys == 1)
597 _transport_delete_port(ioc, mpt3sas_port);
599 _transport_delete_phy(ioc, mpt3sas_port,
607 * _transport_sanity_check - sanity check when adding a new port
608 * @ioc: per adapter object
609 * @sas_node: sas node object (either expander or sas host)
610 * @sas_address: sas address of device being added
612 * See the explanation above from _transport_delete_duplicate_port
615 _transport_sanity_check(struct MPT3SAS_ADAPTER *ioc, struct _sas_node *sas_node,
620 for (i = 0; i < sas_node->num_phys; i++) {
621 if (sas_node->phy[i].remote_identify.sas_address != sas_address)
623 if (sas_node->phy[i].phy_belongs_to_port == 1)
624 _transport_del_phy_from_an_existing_port(ioc, sas_node,
630 * mpt3sas_transport_port_add - insert port to the list
631 * @ioc: per adapter object
632 * @handle: handle of attached device
633 * @sas_address: sas address of parent expander or sas host
634 * Context: This function will acquire ioc->sas_node_lock.
636 * Adding new port object to the sas_node->sas_port_list.
638 * Returns mpt3sas_port.
641 mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
644 struct _sas_phy *mpt3sas_phy, *next;
645 struct _sas_port *mpt3sas_port;
647 struct _sas_node *sas_node;
648 struct sas_rphy *rphy;
649 struct _sas_device *sas_device = NULL;
651 struct sas_port *port;
653 mpt3sas_port = kzalloc(sizeof(struct _sas_port),
656 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
657 ioc->name, __FILE__, __LINE__, __func__);
661 INIT_LIST_HEAD(&mpt3sas_port->port_list);
662 INIT_LIST_HEAD(&mpt3sas_port->phy_list);
663 spin_lock_irqsave(&ioc->sas_node_lock, flags);
664 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
665 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
669 "%s: Could not find parent sas_address(0x%016llx)!\n",
670 ioc->name, __func__, (unsigned long long)sas_address);
674 if ((_transport_set_identify(ioc, handle,
675 &mpt3sas_port->remote_identify))) {
676 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
677 ioc->name, __FILE__, __LINE__, __func__);
681 if (mpt3sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
682 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
683 ioc->name, __FILE__, __LINE__, __func__);
687 _transport_sanity_check(ioc, sas_node,
688 mpt3sas_port->remote_identify.sas_address);
690 for (i = 0; i < sas_node->num_phys; i++) {
691 if (sas_node->phy[i].remote_identify.sas_address !=
692 mpt3sas_port->remote_identify.sas_address)
694 list_add_tail(&sas_node->phy[i].port_siblings,
695 &mpt3sas_port->phy_list);
696 mpt3sas_port->num_phys++;
699 if (!mpt3sas_port->num_phys) {
700 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
701 ioc->name, __FILE__, __LINE__, __func__);
705 if (!sas_node->parent_dev) {
706 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
707 ioc->name, __FILE__, __LINE__, __func__);
710 port = sas_port_alloc_num(sas_node->parent_dev);
711 if ((sas_port_add(port))) {
712 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
713 ioc->name, __FILE__, __LINE__, __func__);
717 list_for_each_entry(mpt3sas_phy, &mpt3sas_port->phy_list,
719 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
720 dev_printk(KERN_INFO, &port->dev,
721 "add: handle(0x%04x), sas_addr(0x%016llx), phy(%d)\n",
722 handle, (unsigned long long)
723 mpt3sas_port->remote_identify.sas_address,
724 mpt3sas_phy->phy_id);
725 sas_port_add_phy(port, mpt3sas_phy->phy);
726 mpt3sas_phy->phy_belongs_to_port = 1;
729 mpt3sas_port->port = port;
730 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE)
731 rphy = sas_end_device_alloc(port);
733 rphy = sas_expander_alloc(port,
734 mpt3sas_port->remote_identify.device_type);
736 rphy->identify = mpt3sas_port->remote_identify;
738 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
739 sas_device = mpt3sas_get_sdev_by_addr(ioc,
740 mpt3sas_port->remote_identify.sas_address);
742 dfailprintk(ioc, printk(MPT3SAS_FMT
743 "failure at %s:%d/%s()!\n",
744 ioc->name, __FILE__, __LINE__, __func__));
747 sas_device->pend_sas_rphy_add = 1;
750 if ((sas_rphy_add(rphy))) {
751 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
752 ioc->name, __FILE__, __LINE__, __func__);
755 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
756 sas_device->pend_sas_rphy_add = 0;
757 sas_device_put(sas_device);
760 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
761 dev_printk(KERN_INFO, &rphy->dev,
762 "add: handle(0x%04x), sas_addr(0x%016llx)\n",
763 handle, (unsigned long long)
764 mpt3sas_port->remote_identify.sas_address);
765 mpt3sas_port->rphy = rphy;
766 spin_lock_irqsave(&ioc->sas_node_lock, flags);
767 list_add_tail(&mpt3sas_port->port_list, &sas_node->sas_port_list);
768 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
770 /* fill in report manufacture */
771 if (mpt3sas_port->remote_identify.device_type ==
772 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
773 mpt3sas_port->remote_identify.device_type ==
774 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
775 _transport_expander_report_manufacture(ioc,
776 mpt3sas_port->remote_identify.sas_address,
777 rphy_to_expander_device(rphy));
781 list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
783 list_del(&mpt3sas_phy->port_siblings);
789 * mpt3sas_transport_port_remove - remove port from the list
790 * @ioc: per adapter object
791 * @sas_address: sas address of attached device
792 * @sas_address_parent: sas address of parent expander or sas host
793 * Context: This function will acquire ioc->sas_node_lock.
795 * Removing object and freeing associated memory from the
796 * ioc->sas_port_list.
801 mpt3sas_transport_port_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
802 u64 sas_address_parent)
806 struct _sas_port *mpt3sas_port, *next;
807 struct _sas_node *sas_node;
809 struct _sas_phy *mpt3sas_phy, *next_phy;
811 spin_lock_irqsave(&ioc->sas_node_lock, flags);
812 sas_node = _transport_sas_node_find_by_sas_address(ioc,
815 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
818 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
820 if (mpt3sas_port->remote_identify.sas_address != sas_address)
823 list_del(&mpt3sas_port->port_list);
828 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
832 for (i = 0; i < sas_node->num_phys; i++) {
833 if (sas_node->phy[i].remote_identify.sas_address == sas_address)
834 memset(&sas_node->phy[i].remote_identify, 0 ,
835 sizeof(struct sas_identify));
838 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
840 list_for_each_entry_safe(mpt3sas_phy, next_phy,
841 &mpt3sas_port->phy_list, port_siblings) {
842 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
843 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
844 "remove: sas_addr(0x%016llx), phy(%d)\n",
846 mpt3sas_port->remote_identify.sas_address,
847 mpt3sas_phy->phy_id);
848 mpt3sas_phy->phy_belongs_to_port = 0;
849 if (!ioc->remove_host)
850 sas_port_delete_phy(mpt3sas_port->port,
852 list_del(&mpt3sas_phy->port_siblings);
854 if (!ioc->remove_host)
855 sas_port_delete(mpt3sas_port->port);
860 * mpt3sas_transport_add_host_phy - report sas_host phy to transport
861 * @ioc: per adapter object
862 * @mpt3sas_phy: mpt3sas per phy object
863 * @phy_pg0: sas phy page 0
864 * @parent_dev: parent device class object
866 * Returns 0 for success, non-zero for failure.
869 mpt3sas_transport_add_host_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
870 *mpt3sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev)
873 int phy_index = mpt3sas_phy->phy_id;
876 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
877 phy = sas_phy_alloc(parent_dev, phy_index);
879 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
880 ioc->name, __FILE__, __LINE__, __func__);
883 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
884 &mpt3sas_phy->identify))) {
885 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
886 ioc->name, __FILE__, __LINE__, __func__);
890 phy->identify = mpt3sas_phy->identify;
891 mpt3sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle);
892 if (mpt3sas_phy->attached_handle)
893 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
894 &mpt3sas_phy->remote_identify);
895 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
896 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
897 phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
898 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
899 phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
900 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
901 phy_pg0.HwLinkRate >> 4);
902 phy->minimum_linkrate = _transport_convert_phy_link_rate(
903 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
904 phy->maximum_linkrate = _transport_convert_phy_link_rate(
905 phy_pg0.ProgrammedLinkRate >> 4);
907 if ((sas_phy_add(phy))) {
908 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
909 ioc->name, __FILE__, __LINE__, __func__);
913 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
914 dev_printk(KERN_INFO, &phy->dev,
915 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
916 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
917 mpt3sas_phy->handle, (unsigned long long)
918 mpt3sas_phy->identify.sas_address,
919 mpt3sas_phy->attached_handle,
921 mpt3sas_phy->remote_identify.sas_address);
922 mpt3sas_phy->phy = phy;
928 * mpt3sas_transport_add_expander_phy - report expander phy to transport
929 * @ioc: per adapter object
930 * @mpt3sas_phy: mpt3sas per phy object
931 * @expander_pg1: expander page 1
932 * @parent_dev: parent device class object
934 * Returns 0 for success, non-zero for failure.
937 mpt3sas_transport_add_expander_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
938 *mpt3sas_phy, Mpi2ExpanderPage1_t expander_pg1,
939 struct device *parent_dev)
942 int phy_index = mpt3sas_phy->phy_id;
944 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
945 phy = sas_phy_alloc(parent_dev, phy_index);
947 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
948 ioc->name, __FILE__, __LINE__, __func__);
951 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
952 &mpt3sas_phy->identify))) {
953 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
954 ioc->name, __FILE__, __LINE__, __func__);
958 phy->identify = mpt3sas_phy->identify;
959 mpt3sas_phy->attached_handle =
960 le16_to_cpu(expander_pg1.AttachedDevHandle);
961 if (mpt3sas_phy->attached_handle)
962 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
963 &mpt3sas_phy->remote_identify);
964 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
965 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
966 expander_pg1.NegotiatedLinkRate &
967 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
968 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
969 expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
970 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
971 expander_pg1.HwLinkRate >> 4);
972 phy->minimum_linkrate = _transport_convert_phy_link_rate(
973 expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
974 phy->maximum_linkrate = _transport_convert_phy_link_rate(
975 expander_pg1.ProgrammedLinkRate >> 4);
977 if ((sas_phy_add(phy))) {
978 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
979 ioc->name, __FILE__, __LINE__, __func__);
983 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
984 dev_printk(KERN_INFO, &phy->dev,
985 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
986 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
987 mpt3sas_phy->handle, (unsigned long long)
988 mpt3sas_phy->identify.sas_address,
989 mpt3sas_phy->attached_handle,
991 mpt3sas_phy->remote_identify.sas_address);
992 mpt3sas_phy->phy = phy;
997 * mpt3sas_transport_update_links - refreshing phy link changes
998 * @ioc: per adapter object
999 * @sas_address: sas address of parent expander or sas host
1000 * @handle: attached device handle
1001 * @phy_numberv: phy number
1002 * @link_rate: new link rate
1007 mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
1008 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate)
1010 unsigned long flags;
1011 struct _sas_node *sas_node;
1012 struct _sas_phy *mpt3sas_phy;
1014 if (ioc->shost_recovery || ioc->pci_error_recovery)
1017 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1018 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
1020 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1024 mpt3sas_phy = &sas_node->phy[phy_number];
1025 mpt3sas_phy->attached_handle = handle;
1026 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1027 if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
1028 _transport_set_identify(ioc, handle,
1029 &mpt3sas_phy->remote_identify);
1030 _transport_add_phy_to_an_existing_port(ioc, sas_node,
1031 mpt3sas_phy, mpt3sas_phy->remote_identify.sas_address);
1033 memset(&mpt3sas_phy->remote_identify, 0 , sizeof(struct
1036 if (mpt3sas_phy->phy)
1037 mpt3sas_phy->phy->negotiated_linkrate =
1038 _transport_convert_phy_link_rate(link_rate);
1040 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
1041 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
1042 "refresh: parent sas_addr(0x%016llx),\n"
1043 "\tlink_rate(0x%02x), phy(%d)\n"
1044 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1045 (unsigned long long)sas_address,
1046 link_rate, phy_number, handle, (unsigned long long)
1047 mpt3sas_phy->remote_identify.sas_address);
1050 static inline void *
1051 phy_to_ioc(struct sas_phy *phy)
1053 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
1054 return shost_priv(shost);
1057 static inline void *
1058 rphy_to_ioc(struct sas_rphy *rphy)
1060 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
1061 return shost_priv(shost);
1064 /* report phy error log structure */
1065 struct phy_error_log_request {
1066 u8 smp_frame_type; /* 0x40 */
1067 u8 function; /* 0x11 */
1068 u8 allocated_response_length;
1069 u8 request_length; /* 02 */
1075 /* report phy error log reply structure */
1076 struct phy_error_log_reply {
1077 u8 smp_frame_type; /* 0x41 */
1078 u8 function; /* 0x11 */
1081 __be16 expander_change_count;
1085 __be32 invalid_dword;
1086 __be32 running_disparity_error;
1087 __be32 loss_of_dword_sync;
1088 __be32 phy_reset_problem;
1092 * _transport_get_expander_phy_error_log - return expander counters
1093 * @ioc: per adapter object
1094 * @phy: The sas phy object
1096 * Returns 0 for success, non-zero for failure.
1100 _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER *ioc,
1101 struct sas_phy *phy)
1103 Mpi2SmpPassthroughRequest_t *mpi_request;
1104 Mpi2SmpPassthroughReply_t *mpi_reply;
1105 struct phy_error_log_request *phy_error_log_request;
1106 struct phy_error_log_reply *phy_error_log_reply;
1112 void *data_out = NULL;
1113 dma_addr_t data_out_dma;
1115 u16 wait_state_count;
1117 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1118 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1119 __func__, ioc->name);
1123 mutex_lock(&ioc->transport_cmds.mutex);
1125 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1126 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1127 ioc->name, __func__);
1131 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1133 wait_state_count = 0;
1134 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1135 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1136 if (wait_state_count++ == 10) {
1138 "%s: failed due to ioc not operational\n",
1139 ioc->name, __func__);
1144 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1146 "%s: waiting for operational state(count=%d)\n",
1147 ioc->name, __func__, wait_state_count);
1149 if (wait_state_count)
1150 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1151 ioc->name, __func__);
1153 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1155 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1156 ioc->name, __func__);
1161 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1162 ioc->transport_cmds.smid = smid;
1164 sz = sizeof(struct phy_error_log_request) +
1165 sizeof(struct phy_error_log_reply);
1166 data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1168 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1169 __LINE__, __func__);
1171 mpt3sas_base_free_smid(ioc, smid);
1176 memset(data_out, 0, sz);
1177 phy_error_log_request = data_out;
1178 phy_error_log_request->smp_frame_type = 0x40;
1179 phy_error_log_request->function = 0x11;
1180 phy_error_log_request->request_length = 2;
1181 phy_error_log_request->allocated_response_length = 0;
1182 phy_error_log_request->phy_identifier = phy->number;
1184 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1185 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1186 mpi_request->PhysicalPort = 0xFF;
1187 mpi_request->VF_ID = 0; /* TODO */
1188 mpi_request->VP_ID = 0;
1189 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1190 mpi_request->RequestDataLength =
1191 cpu_to_le16(sizeof(struct phy_error_log_request));
1192 psge = &mpi_request->SGL;
1194 ioc->build_sg(ioc, psge, data_out_dma,
1195 sizeof(struct phy_error_log_request),
1196 data_out_dma + sizeof(struct phy_error_log_request),
1197 sizeof(struct phy_error_log_reply));
1199 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1200 "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1201 ioc->name, (unsigned long long)phy->identify.sas_address,
1203 init_completion(&ioc->transport_cmds.done);
1204 ioc->put_smid_default(ioc, smid);
1205 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1207 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1208 pr_err(MPT3SAS_FMT "%s: timeout\n",
1209 ioc->name, __func__);
1210 _debug_dump_mf(mpi_request,
1211 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1212 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1214 goto issue_host_reset;
1217 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1218 "phy_error_log - complete\n", ioc->name));
1220 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1222 mpi_reply = ioc->transport_cmds.reply;
1224 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1225 "phy_error_log - reply data transfer size(%d)\n",
1226 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1228 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1229 sizeof(struct phy_error_log_reply))
1232 phy_error_log_reply = data_out +
1233 sizeof(struct phy_error_log_request);
1235 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1236 "phy_error_log - function_result(%d)\n",
1237 ioc->name, phy_error_log_reply->function_result));
1239 phy->invalid_dword_count =
1240 be32_to_cpu(phy_error_log_reply->invalid_dword);
1241 phy->running_disparity_error_count =
1242 be32_to_cpu(phy_error_log_reply->running_disparity_error);
1243 phy->loss_of_dword_sync_count =
1244 be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
1245 phy->phy_reset_problem_count =
1246 be32_to_cpu(phy_error_log_reply->phy_reset_problem);
1249 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1250 "phy_error_log - no reply\n", ioc->name));
1254 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1256 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1258 pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1260 mutex_unlock(&ioc->transport_cmds.mutex);
1265 * _transport_get_linkerrors - return phy counters for both hba and expanders
1266 * @phy: The sas phy object
1268 * Returns 0 for success, non-zero for failure.
1272 _transport_get_linkerrors(struct sas_phy *phy)
1274 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1275 unsigned long flags;
1276 Mpi2ConfigReply_t mpi_reply;
1277 Mpi2SasPhyPage1_t phy_pg1;
1279 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1280 if (_transport_sas_node_find_by_sas_address(ioc,
1281 phy->identify.sas_address) == NULL) {
1282 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1285 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1287 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1288 return _transport_get_expander_phy_error_log(ioc, phy);
1290 /* get hba phy error logs */
1291 if ((mpt3sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
1293 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1294 ioc->name, __FILE__, __LINE__, __func__);
1298 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1300 "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1301 ioc->name, phy->number,
1302 le16_to_cpu(mpi_reply.IOCStatus),
1303 le32_to_cpu(mpi_reply.IOCLogInfo));
1305 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
1306 phy->running_disparity_error_count =
1307 le32_to_cpu(phy_pg1.RunningDisparityErrorCount);
1308 phy->loss_of_dword_sync_count =
1309 le32_to_cpu(phy_pg1.LossDwordSynchCount);
1310 phy->phy_reset_problem_count =
1311 le32_to_cpu(phy_pg1.PhyResetProblemCount);
1316 * _transport_get_enclosure_identifier -
1317 * @phy: The sas phy object
1319 * Obtain the enclosure logical id for an expander.
1320 * Returns 0 for success, non-zero for failure.
1323 _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1325 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1326 struct _sas_device *sas_device;
1327 unsigned long flags;
1330 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1331 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1332 rphy->identify.sas_address);
1334 *identifier = sas_device->enclosure_logical_id;
1336 sas_device_put(sas_device);
1342 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1347 * _transport_get_bay_identifier -
1348 * @phy: The sas phy object
1350 * Returns the slot id for a device that resides inside an enclosure.
1353 _transport_get_bay_identifier(struct sas_rphy *rphy)
1355 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1356 struct _sas_device *sas_device;
1357 unsigned long flags;
1360 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1361 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1362 rphy->identify.sas_address);
1364 rc = sas_device->slot;
1365 sas_device_put(sas_device);
1369 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1373 /* phy control request structure */
1374 struct phy_control_request {
1375 u8 smp_frame_type; /* 0x40 */
1376 u8 function; /* 0x91 */
1377 u8 allocated_response_length;
1378 u8 request_length; /* 0x09 */
1379 u16 expander_change_count;
1384 u64 attached_device_name;
1385 u8 programmed_min_physical_link_rate;
1386 u8 programmed_max_physical_link_rate;
1390 /* phy control reply structure */
1391 struct phy_control_reply {
1392 u8 smp_frame_type; /* 0x41 */
1393 u8 function; /* 0x11 */
1398 #define SMP_PHY_CONTROL_LINK_RESET (0x01)
1399 #define SMP_PHY_CONTROL_HARD_RESET (0x02)
1400 #define SMP_PHY_CONTROL_DISABLE (0x03)
1403 * _transport_expander_phy_control - expander phy control
1404 * @ioc: per adapter object
1405 * @phy: The sas phy object
1407 * Returns 0 for success, non-zero for failure.
1411 _transport_expander_phy_control(struct MPT3SAS_ADAPTER *ioc,
1412 struct sas_phy *phy, u8 phy_operation)
1414 Mpi2SmpPassthroughRequest_t *mpi_request;
1415 Mpi2SmpPassthroughReply_t *mpi_reply;
1416 struct phy_control_request *phy_control_request;
1417 struct phy_control_reply *phy_control_reply;
1423 void *data_out = NULL;
1424 dma_addr_t data_out_dma;
1426 u16 wait_state_count;
1428 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1429 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1430 __func__, ioc->name);
1434 mutex_lock(&ioc->transport_cmds.mutex);
1436 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1437 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1438 ioc->name, __func__);
1442 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1444 wait_state_count = 0;
1445 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1446 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1447 if (wait_state_count++ == 10) {
1449 "%s: failed due to ioc not operational\n",
1450 ioc->name, __func__);
1455 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1457 "%s: waiting for operational state(count=%d)\n",
1458 ioc->name, __func__, wait_state_count);
1460 if (wait_state_count)
1461 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1462 ioc->name, __func__);
1464 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1466 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1467 ioc->name, __func__);
1472 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1473 ioc->transport_cmds.smid = smid;
1475 sz = sizeof(struct phy_control_request) +
1476 sizeof(struct phy_control_reply);
1477 data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1479 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1480 __LINE__, __func__);
1482 mpt3sas_base_free_smid(ioc, smid);
1487 memset(data_out, 0, sz);
1488 phy_control_request = data_out;
1489 phy_control_request->smp_frame_type = 0x40;
1490 phy_control_request->function = 0x91;
1491 phy_control_request->request_length = 9;
1492 phy_control_request->allocated_response_length = 0;
1493 phy_control_request->phy_identifier = phy->number;
1494 phy_control_request->phy_operation = phy_operation;
1495 phy_control_request->programmed_min_physical_link_rate =
1496 phy->minimum_linkrate << 4;
1497 phy_control_request->programmed_max_physical_link_rate =
1498 phy->maximum_linkrate << 4;
1500 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1501 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1502 mpi_request->PhysicalPort = 0xFF;
1503 mpi_request->VF_ID = 0; /* TODO */
1504 mpi_request->VP_ID = 0;
1505 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1506 mpi_request->RequestDataLength =
1507 cpu_to_le16(sizeof(struct phy_error_log_request));
1508 psge = &mpi_request->SGL;
1510 ioc->build_sg(ioc, psge, data_out_dma,
1511 sizeof(struct phy_control_request),
1512 data_out_dma + sizeof(struct phy_control_request),
1513 sizeof(struct phy_control_reply));
1515 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1516 "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1517 ioc->name, (unsigned long long)phy->identify.sas_address,
1518 phy->number, phy_operation));
1519 init_completion(&ioc->transport_cmds.done);
1520 ioc->put_smid_default(ioc, smid);
1521 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1523 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1524 pr_err(MPT3SAS_FMT "%s: timeout\n",
1525 ioc->name, __func__);
1526 _debug_dump_mf(mpi_request,
1527 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1528 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1530 goto issue_host_reset;
1533 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1534 "phy_control - complete\n", ioc->name));
1536 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1538 mpi_reply = ioc->transport_cmds.reply;
1540 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1541 "phy_control - reply data transfer size(%d)\n",
1542 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1544 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1545 sizeof(struct phy_control_reply))
1548 phy_control_reply = data_out +
1549 sizeof(struct phy_control_request);
1551 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1552 "phy_control - function_result(%d)\n",
1553 ioc->name, phy_control_reply->function_result));
1557 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1558 "phy_control - no reply\n", ioc->name));
1562 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1564 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1566 pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1568 mutex_unlock(&ioc->transport_cmds.mutex);
1573 * _transport_phy_reset -
1574 * @phy: The sas phy object
1577 * Returns 0 for success, non-zero for failure.
1580 _transport_phy_reset(struct sas_phy *phy, int hard_reset)
1582 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1583 Mpi2SasIoUnitControlReply_t mpi_reply;
1584 Mpi2SasIoUnitControlRequest_t mpi_request;
1585 unsigned long flags;
1587 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1588 if (_transport_sas_node_find_by_sas_address(ioc,
1589 phy->identify.sas_address) == NULL) {
1590 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1593 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1595 /* handle expander phys */
1596 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1597 return _transport_expander_phy_control(ioc, phy,
1598 (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET :
1599 SMP_PHY_CONTROL_LINK_RESET);
1601 /* handle hba phys */
1602 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
1603 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
1604 mpi_request.Operation = hard_reset ?
1605 MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET;
1606 mpi_request.PhyNum = phy->number;
1608 if ((mpt3sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
1609 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1610 ioc->name, __FILE__, __LINE__, __func__);
1614 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1616 "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1617 ioc->name, phy->number, le16_to_cpu(mpi_reply.IOCStatus),
1618 le32_to_cpu(mpi_reply.IOCLogInfo));
1624 * _transport_phy_enable - enable/disable phys
1625 * @phy: The sas phy object
1626 * @enable: enable phy when true
1628 * Only support sas_host direct attached phys.
1629 * Returns 0 for success, non-zero for failure.
1632 _transport_phy_enable(struct sas_phy *phy, int enable)
1634 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1635 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1636 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
1637 Mpi2ConfigReply_t mpi_reply;
1641 unsigned long flags;
1642 int i, discovery_active;
1644 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1645 if (_transport_sas_node_find_by_sas_address(ioc,
1646 phy->identify.sas_address) == NULL) {
1647 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1650 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1652 /* handle expander phys */
1653 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1654 return _transport_expander_phy_control(ioc, phy,
1655 (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET :
1656 SMP_PHY_CONTROL_DISABLE);
1658 /* handle hba phys */
1660 /* read sas_iounit page 0 */
1661 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
1662 sizeof(Mpi2SasIOUnit0PhyData_t));
1663 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
1664 if (!sas_iounit_pg0) {
1665 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1666 ioc->name, __FILE__, __LINE__, __func__);
1670 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
1671 sas_iounit_pg0, sz))) {
1672 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1673 ioc->name, __FILE__, __LINE__, __func__);
1677 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1678 MPI2_IOCSTATUS_MASK;
1679 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1680 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1681 ioc->name, __FILE__, __LINE__, __func__);
1686 /* unable to enable/disable phys when when discovery is active */
1687 for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) {
1688 if (sas_iounit_pg0->PhyData[i].PortFlags &
1689 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
1690 pr_err(MPT3SAS_FMT "discovery is active on " \
1691 "port = %d, phy = %d: unable to enable/disable "
1692 "phys, try again later!\n", ioc->name,
1693 sas_iounit_pg0->PhyData[i].Port, i);
1694 discovery_active = 1;
1698 if (discovery_active) {
1703 /* read sas_iounit page 1 */
1704 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1705 sizeof(Mpi2SasIOUnit1PhyData_t));
1706 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1707 if (!sas_iounit_pg1) {
1708 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1709 ioc->name, __FILE__, __LINE__, __func__);
1713 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1714 sas_iounit_pg1, sz))) {
1715 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1716 ioc->name, __FILE__, __LINE__, __func__);
1720 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1721 MPI2_IOCSTATUS_MASK;
1722 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1723 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1724 ioc->name, __FILE__, __LINE__, __func__);
1729 /* copy Port/PortFlags/PhyFlags from page 0 */
1730 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
1731 sas_iounit_pg1->PhyData[i].Port =
1732 sas_iounit_pg0->PhyData[i].Port;
1733 sas_iounit_pg1->PhyData[i].PortFlags =
1734 (sas_iounit_pg0->PhyData[i].PortFlags &
1735 MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG);
1736 sas_iounit_pg1->PhyData[i].PhyFlags =
1737 (sas_iounit_pg0->PhyData[i].PhyFlags &
1738 (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED +
1739 MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED));
1743 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1744 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1746 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1747 |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1749 mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
1753 _transport_phy_reset(phy, 0);
1756 kfree(sas_iounit_pg1);
1757 kfree(sas_iounit_pg0);
1762 * _transport_phy_speed - set phy min/max link rates
1763 * @phy: The sas phy object
1764 * @rates: rates defined in sas_phy_linkrates
1766 * Only support sas_host direct attached phys.
1767 * Returns 0 for success, non-zero for failure.
1770 _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
1772 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1773 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1774 Mpi2SasPhyPage0_t phy_pg0;
1775 Mpi2ConfigReply_t mpi_reply;
1780 unsigned long flags;
1782 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1783 if (_transport_sas_node_find_by_sas_address(ioc,
1784 phy->identify.sas_address) == NULL) {
1785 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1788 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1790 if (!rates->minimum_linkrate)
1791 rates->minimum_linkrate = phy->minimum_linkrate;
1792 else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
1793 rates->minimum_linkrate = phy->minimum_linkrate_hw;
1795 if (!rates->maximum_linkrate)
1796 rates->maximum_linkrate = phy->maximum_linkrate;
1797 else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
1798 rates->maximum_linkrate = phy->maximum_linkrate_hw;
1800 /* handle expander phys */
1801 if (phy->identify.sas_address != ioc->sas_hba.sas_address) {
1802 phy->minimum_linkrate = rates->minimum_linkrate;
1803 phy->maximum_linkrate = rates->maximum_linkrate;
1804 return _transport_expander_phy_control(ioc, phy,
1805 SMP_PHY_CONTROL_LINK_RESET);
1808 /* handle hba phys */
1810 /* sas_iounit page 1 */
1811 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1812 sizeof(Mpi2SasIOUnit1PhyData_t));
1813 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1814 if (!sas_iounit_pg1) {
1815 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1816 ioc->name, __FILE__, __LINE__, __func__);
1820 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1821 sas_iounit_pg1, sz))) {
1822 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1823 ioc->name, __FILE__, __LINE__, __func__);
1827 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1828 MPI2_IOCSTATUS_MASK;
1829 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1830 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1831 ioc->name, __FILE__, __LINE__, __func__);
1836 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
1837 if (phy->number != i) {
1838 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1839 (ioc->sas_hba.phy[i].phy->minimum_linkrate +
1840 (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
1842 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1843 (rates->minimum_linkrate +
1844 (rates->maximum_linkrate << 4));
1848 if (mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
1850 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1851 ioc->name, __FILE__, __LINE__, __func__);
1857 _transport_phy_reset(phy, 0);
1859 /* read phy page 0, then update the rates in the sas transport phy */
1860 if (!mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
1862 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1863 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
1864 phy->maximum_linkrate = _transport_convert_phy_link_rate(
1865 phy_pg0.ProgrammedLinkRate >> 4);
1866 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
1867 phy_pg0.NegotiatedLinkRate &
1868 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
1872 kfree(sas_iounit_pg1);
1877 _transport_map_smp_buffer(struct device *dev, struct bsg_buffer *buf,
1878 dma_addr_t *dma_addr, size_t *dma_len, void **p)
1880 /* Check if the request is split across multiple segments */
1881 if (buf->sg_cnt > 1) {
1882 *p = dma_alloc_coherent(dev, buf->payload_len, dma_addr,
1886 *dma_len = buf->payload_len;
1888 if (!dma_map_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL))
1890 *dma_addr = sg_dma_address(buf->sg_list);
1891 *dma_len = sg_dma_len(buf->sg_list);
1899 _transport_unmap_smp_buffer(struct device *dev, struct bsg_buffer *buf,
1900 dma_addr_t dma_addr, void *p)
1903 dma_free_coherent(dev, buf->payload_len, p, dma_addr);
1905 dma_unmap_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL);
1909 * _transport_smp_handler - transport portal for smp passthru
1910 * @shost: shost object
1911 * @rphy: sas transport rphy object
1914 * This used primarily for smp_utils.
1916 * smp_rep_general /sys/class/bsg/expander-5:0
1919 _transport_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
1920 struct sas_rphy *rphy)
1922 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1923 Mpi2SmpPassthroughRequest_t *mpi_request;
1924 Mpi2SmpPassthroughReply_t *mpi_reply;
1929 dma_addr_t dma_addr_in;
1930 dma_addr_t dma_addr_out;
1931 void *addr_in = NULL;
1932 void *addr_out = NULL;
1935 u16 wait_state_count;
1936 unsigned int reslen = 0;
1938 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1939 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1940 __func__, ioc->name);
1945 rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex);
1949 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1950 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n", ioc->name,
1955 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1957 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->request_payload,
1958 &dma_addr_out, &dma_len_out, &addr_out);
1962 sg_copy_to_buffer(job->request_payload.sg_list,
1963 job->request_payload.sg_cnt, addr_out,
1964 job->request_payload.payload_len);
1967 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
1968 &dma_addr_in, &dma_len_in, &addr_in);
1972 wait_state_count = 0;
1973 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1974 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1975 if (wait_state_count++ == 10) {
1977 "%s: failed due to ioc not operational\n",
1978 ioc->name, __func__);
1983 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1985 "%s: waiting for operational state(count=%d)\n",
1986 ioc->name, __func__, wait_state_count);
1988 if (wait_state_count)
1989 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1990 ioc->name, __func__);
1992 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1994 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1995 ioc->name, __func__);
2001 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2002 ioc->transport_cmds.smid = smid;
2004 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
2005 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
2006 mpi_request->PhysicalPort = 0xFF;
2007 mpi_request->SASAddress = (rphy) ?
2008 cpu_to_le64(rphy->identify.sas_address) :
2009 cpu_to_le64(ioc->sas_hba.sas_address);
2010 mpi_request->RequestDataLength = cpu_to_le16(dma_len_out - 4);
2011 psge = &mpi_request->SGL;
2013 ioc->build_sg(ioc, psge, dma_addr_out, dma_len_out - 4, dma_addr_in,
2016 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2017 "%s - sending smp request\n", ioc->name, __func__));
2019 init_completion(&ioc->transport_cmds.done);
2020 ioc->put_smid_default(ioc, smid);
2021 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
2023 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
2024 pr_err(MPT3SAS_FMT "%s : timeout\n",
2025 __func__, ioc->name);
2026 _debug_dump_mf(mpi_request,
2027 sizeof(Mpi2SmpPassthroughRequest_t)/4);
2028 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET)) {
2029 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2035 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2036 "%s - complete\n", ioc->name, __func__));
2038 if (!(ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID)) {
2039 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2040 "%s - no reply\n", ioc->name, __func__));
2045 mpi_reply = ioc->transport_cmds.reply;
2047 dtransportprintk(ioc,
2048 pr_info(MPT3SAS_FMT "%s - reply data transfer size(%d)\n",
2049 ioc->name, __func__,
2050 le16_to_cpu(mpi_reply->ResponseDataLength)));
2052 memcpy(job->reply, mpi_reply, sizeof(*mpi_reply));
2053 job->reply_len = sizeof(*mpi_reply);
2054 reslen = le16_to_cpu(mpi_reply->ResponseDataLength);
2057 sg_copy_to_buffer(job->reply_payload.sg_list,
2058 job->reply_payload.sg_cnt, addr_in,
2059 job->reply_payload.payload_len);
2064 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
2065 dma_addr_in, addr_in);
2067 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->request_payload,
2068 dma_addr_out, addr_out);
2070 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
2071 mutex_unlock(&ioc->transport_cmds.mutex);
2073 bsg_job_done(job, rc, reslen);
2076 struct sas_function_template mpt3sas_transport_functions = {
2077 .get_linkerrors = _transport_get_linkerrors,
2078 .get_enclosure_identifier = _transport_get_enclosure_identifier,
2079 .get_bay_identifier = _transport_get_bay_identifier,
2080 .phy_reset = _transport_phy_reset,
2081 .phy_enable = _transport_phy_enable,
2082 .set_phy_speed = _transport_phy_speed,
2083 .smp_handler = _transport_smp_handler,
2086 struct scsi_transport_template *mpt3sas_transport_template;