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 * Return: 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 * Return: 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 mpt3sas_base_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
465 _transport_delete_port(struct MPT3SAS_ADAPTER *ioc,
466 struct _sas_port *mpt3sas_port)
468 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
469 enum sas_device_type device_type =
470 mpt3sas_port->remote_identify.device_type;
472 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
473 "remove: sas_addr(0x%016llx)\n",
474 (unsigned long long) sas_address);
476 ioc->logging_level |= MPT_DEBUG_TRANSPORT;
477 if (device_type == SAS_END_DEVICE)
478 mpt3sas_device_remove_by_sas_address(ioc, sas_address);
479 else if (device_type == SAS_EDGE_EXPANDER_DEVICE ||
480 device_type == SAS_FANOUT_EXPANDER_DEVICE)
481 mpt3sas_expander_remove(ioc, sas_address);
482 ioc->logging_level &= ~MPT_DEBUG_TRANSPORT;
486 * _transport_delete_phy - helper function to removing single phy from port
487 * @ioc: per adapter object
488 * @mpt3sas_port: mpt3sas per port object
489 * @mpt3sas_phy: mpt3sas per phy object
492 _transport_delete_phy(struct MPT3SAS_ADAPTER *ioc,
493 struct _sas_port *mpt3sas_port, struct _sas_phy *mpt3sas_phy)
495 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
497 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
498 "remove: sas_addr(0x%016llx), phy(%d)\n",
499 (unsigned long long) sas_address, mpt3sas_phy->phy_id);
501 list_del(&mpt3sas_phy->port_siblings);
502 mpt3sas_port->num_phys--;
503 sas_port_delete_phy(mpt3sas_port->port, mpt3sas_phy->phy);
504 mpt3sas_phy->phy_belongs_to_port = 0;
508 * _transport_add_phy - helper function to adding single phy to port
509 * @ioc: per adapter object
510 * @mpt3sas_port: mpt3sas per port object
511 * @mpt3sas_phy: mpt3sas per phy object
514 _transport_add_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_port *mpt3sas_port,
515 struct _sas_phy *mpt3sas_phy)
517 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
519 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
520 "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
521 sas_address, mpt3sas_phy->phy_id);
523 list_add_tail(&mpt3sas_phy->port_siblings, &mpt3sas_port->phy_list);
524 mpt3sas_port->num_phys++;
525 sas_port_add_phy(mpt3sas_port->port, mpt3sas_phy->phy);
526 mpt3sas_phy->phy_belongs_to_port = 1;
530 * _transport_add_phy_to_an_existing_port - adding new phy to existing port
531 * @ioc: per adapter object
532 * @sas_node: sas node object (either expander or sas host)
533 * @mpt3sas_phy: mpt3sas per phy object
534 * @sas_address: sas address of device/expander were phy needs to be added to
537 _transport_add_phy_to_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
538 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy,
541 struct _sas_port *mpt3sas_port;
542 struct _sas_phy *phy_srch;
544 if (mpt3sas_phy->phy_belongs_to_port == 1)
547 list_for_each_entry(mpt3sas_port, &sas_node->sas_port_list,
549 if (mpt3sas_port->remote_identify.sas_address !=
552 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
554 if (phy_srch == mpt3sas_phy)
557 _transport_add_phy(ioc, mpt3sas_port, mpt3sas_phy);
564 * _transport_del_phy_from_an_existing_port - delete phy from existing port
565 * @ioc: per adapter object
566 * @sas_node: sas node object (either expander or sas host)
567 * @mpt3sas_phy: mpt3sas per phy object
570 _transport_del_phy_from_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
571 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy)
573 struct _sas_port *mpt3sas_port, *next;
574 struct _sas_phy *phy_srch;
576 if (mpt3sas_phy->phy_belongs_to_port == 0)
579 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
581 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
583 if (phy_srch != mpt3sas_phy)
586 if (mpt3sas_port->num_phys == 1)
587 _transport_delete_port(ioc, mpt3sas_port);
589 _transport_delete_phy(ioc, mpt3sas_port,
597 * _transport_sanity_check - sanity check when adding a new port
598 * @ioc: per adapter object
599 * @sas_node: sas node object (either expander or sas host)
600 * @sas_address: sas address of device being added
602 * See the explanation above from _transport_delete_duplicate_port
605 _transport_sanity_check(struct MPT3SAS_ADAPTER *ioc, struct _sas_node *sas_node,
610 for (i = 0; i < sas_node->num_phys; i++) {
611 if (sas_node->phy[i].remote_identify.sas_address != sas_address)
613 if (sas_node->phy[i].phy_belongs_to_port == 1)
614 _transport_del_phy_from_an_existing_port(ioc, sas_node,
620 * mpt3sas_transport_port_add - insert port to the list
621 * @ioc: per adapter object
622 * @handle: handle of attached device
623 * @sas_address: sas address of parent expander or sas host
624 * Context: This function will acquire ioc->sas_node_lock.
626 * Adding new port object to the sas_node->sas_port_list.
628 * Return: mpt3sas_port.
631 mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
634 struct _sas_phy *mpt3sas_phy, *next;
635 struct _sas_port *mpt3sas_port;
637 struct _sas_node *sas_node;
638 struct sas_rphy *rphy;
639 struct _sas_device *sas_device = NULL;
641 struct sas_port *port;
643 mpt3sas_port = kzalloc(sizeof(struct _sas_port),
646 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
647 ioc->name, __FILE__, __LINE__, __func__);
651 INIT_LIST_HEAD(&mpt3sas_port->port_list);
652 INIT_LIST_HEAD(&mpt3sas_port->phy_list);
653 spin_lock_irqsave(&ioc->sas_node_lock, flags);
654 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
655 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
659 "%s: Could not find parent sas_address(0x%016llx)!\n",
660 ioc->name, __func__, (unsigned long long)sas_address);
664 if ((_transport_set_identify(ioc, handle,
665 &mpt3sas_port->remote_identify))) {
666 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
667 ioc->name, __FILE__, __LINE__, __func__);
671 if (mpt3sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
672 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
673 ioc->name, __FILE__, __LINE__, __func__);
677 _transport_sanity_check(ioc, sas_node,
678 mpt3sas_port->remote_identify.sas_address);
680 for (i = 0; i < sas_node->num_phys; i++) {
681 if (sas_node->phy[i].remote_identify.sas_address !=
682 mpt3sas_port->remote_identify.sas_address)
684 list_add_tail(&sas_node->phy[i].port_siblings,
685 &mpt3sas_port->phy_list);
686 mpt3sas_port->num_phys++;
689 if (!mpt3sas_port->num_phys) {
690 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
691 ioc->name, __FILE__, __LINE__, __func__);
695 if (!sas_node->parent_dev) {
696 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
697 ioc->name, __FILE__, __LINE__, __func__);
700 port = sas_port_alloc_num(sas_node->parent_dev);
701 if ((sas_port_add(port))) {
702 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
703 ioc->name, __FILE__, __LINE__, __func__);
707 list_for_each_entry(mpt3sas_phy, &mpt3sas_port->phy_list,
709 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
710 dev_printk(KERN_INFO, &port->dev,
711 "add: handle(0x%04x), sas_addr(0x%016llx), phy(%d)\n",
712 handle, (unsigned long long)
713 mpt3sas_port->remote_identify.sas_address,
714 mpt3sas_phy->phy_id);
715 sas_port_add_phy(port, mpt3sas_phy->phy);
716 mpt3sas_phy->phy_belongs_to_port = 1;
719 mpt3sas_port->port = port;
720 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE)
721 rphy = sas_end_device_alloc(port);
723 rphy = sas_expander_alloc(port,
724 mpt3sas_port->remote_identify.device_type);
726 rphy->identify = mpt3sas_port->remote_identify;
728 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
729 sas_device = mpt3sas_get_sdev_by_addr(ioc,
730 mpt3sas_port->remote_identify.sas_address);
732 dfailprintk(ioc, printk(MPT3SAS_FMT
733 "failure at %s:%d/%s()!\n",
734 ioc->name, __FILE__, __LINE__, __func__));
737 sas_device->pend_sas_rphy_add = 1;
740 if ((sas_rphy_add(rphy))) {
741 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
742 ioc->name, __FILE__, __LINE__, __func__);
745 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
746 sas_device->pend_sas_rphy_add = 0;
747 sas_device_put(sas_device);
750 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
751 dev_printk(KERN_INFO, &rphy->dev,
752 "add: handle(0x%04x), sas_addr(0x%016llx)\n",
753 handle, (unsigned long long)
754 mpt3sas_port->remote_identify.sas_address);
755 mpt3sas_port->rphy = rphy;
756 spin_lock_irqsave(&ioc->sas_node_lock, flags);
757 list_add_tail(&mpt3sas_port->port_list, &sas_node->sas_port_list);
758 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
760 /* fill in report manufacture */
761 if (mpt3sas_port->remote_identify.device_type ==
762 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
763 mpt3sas_port->remote_identify.device_type ==
764 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
765 _transport_expander_report_manufacture(ioc,
766 mpt3sas_port->remote_identify.sas_address,
767 rphy_to_expander_device(rphy));
771 list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
773 list_del(&mpt3sas_phy->port_siblings);
779 * mpt3sas_transport_port_remove - remove port from the list
780 * @ioc: per adapter object
781 * @sas_address: sas address of attached device
782 * @sas_address_parent: sas address of parent expander or sas host
783 * Context: This function will acquire ioc->sas_node_lock.
785 * Removing object and freeing associated memory from the
786 * ioc->sas_port_list.
789 mpt3sas_transport_port_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
790 u64 sas_address_parent)
794 struct _sas_port *mpt3sas_port, *next;
795 struct _sas_node *sas_node;
797 struct _sas_phy *mpt3sas_phy, *next_phy;
799 spin_lock_irqsave(&ioc->sas_node_lock, flags);
800 sas_node = _transport_sas_node_find_by_sas_address(ioc,
803 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
806 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
808 if (mpt3sas_port->remote_identify.sas_address != sas_address)
811 list_del(&mpt3sas_port->port_list);
816 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
820 for (i = 0; i < sas_node->num_phys; i++) {
821 if (sas_node->phy[i].remote_identify.sas_address == sas_address)
822 memset(&sas_node->phy[i].remote_identify, 0 ,
823 sizeof(struct sas_identify));
826 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
828 list_for_each_entry_safe(mpt3sas_phy, next_phy,
829 &mpt3sas_port->phy_list, port_siblings) {
830 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
831 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
832 "remove: sas_addr(0x%016llx), phy(%d)\n",
834 mpt3sas_port->remote_identify.sas_address,
835 mpt3sas_phy->phy_id);
836 mpt3sas_phy->phy_belongs_to_port = 0;
837 sas_port_delete_phy(mpt3sas_port->port, mpt3sas_phy->phy);
838 list_del(&mpt3sas_phy->port_siblings);
840 sas_port_delete(mpt3sas_port->port);
845 * mpt3sas_transport_add_host_phy - report sas_host phy to transport
846 * @ioc: per adapter object
847 * @mpt3sas_phy: mpt3sas per phy object
848 * @phy_pg0: sas phy page 0
849 * @parent_dev: parent device class object
851 * Return: 0 for success, non-zero for failure.
854 mpt3sas_transport_add_host_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
855 *mpt3sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev)
858 int phy_index = mpt3sas_phy->phy_id;
861 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
862 phy = sas_phy_alloc(parent_dev, phy_index);
864 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
865 ioc->name, __FILE__, __LINE__, __func__);
868 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
869 &mpt3sas_phy->identify))) {
870 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
871 ioc->name, __FILE__, __LINE__, __func__);
875 phy->identify = mpt3sas_phy->identify;
876 mpt3sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle);
877 if (mpt3sas_phy->attached_handle)
878 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
879 &mpt3sas_phy->remote_identify);
880 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
881 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
882 phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
883 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
884 phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
885 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
886 phy_pg0.HwLinkRate >> 4);
887 phy->minimum_linkrate = _transport_convert_phy_link_rate(
888 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
889 phy->maximum_linkrate = _transport_convert_phy_link_rate(
890 phy_pg0.ProgrammedLinkRate >> 4);
892 if ((sas_phy_add(phy))) {
893 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
894 ioc->name, __FILE__, __LINE__, __func__);
898 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
899 dev_printk(KERN_INFO, &phy->dev,
900 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
901 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
902 mpt3sas_phy->handle, (unsigned long long)
903 mpt3sas_phy->identify.sas_address,
904 mpt3sas_phy->attached_handle,
906 mpt3sas_phy->remote_identify.sas_address);
907 mpt3sas_phy->phy = phy;
913 * mpt3sas_transport_add_expander_phy - report expander phy to transport
914 * @ioc: per adapter object
915 * @mpt3sas_phy: mpt3sas per phy object
916 * @expander_pg1: expander page 1
917 * @parent_dev: parent device class object
919 * Return: 0 for success, non-zero for failure.
922 mpt3sas_transport_add_expander_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
923 *mpt3sas_phy, Mpi2ExpanderPage1_t expander_pg1,
924 struct device *parent_dev)
927 int phy_index = mpt3sas_phy->phy_id;
929 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
930 phy = sas_phy_alloc(parent_dev, phy_index);
932 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
933 ioc->name, __FILE__, __LINE__, __func__);
936 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
937 &mpt3sas_phy->identify))) {
938 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
939 ioc->name, __FILE__, __LINE__, __func__);
943 phy->identify = mpt3sas_phy->identify;
944 mpt3sas_phy->attached_handle =
945 le16_to_cpu(expander_pg1.AttachedDevHandle);
946 if (mpt3sas_phy->attached_handle)
947 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
948 &mpt3sas_phy->remote_identify);
949 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
950 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
951 expander_pg1.NegotiatedLinkRate &
952 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
953 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
954 expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
955 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
956 expander_pg1.HwLinkRate >> 4);
957 phy->minimum_linkrate = _transport_convert_phy_link_rate(
958 expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
959 phy->maximum_linkrate = _transport_convert_phy_link_rate(
960 expander_pg1.ProgrammedLinkRate >> 4);
962 if ((sas_phy_add(phy))) {
963 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
964 ioc->name, __FILE__, __LINE__, __func__);
968 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
969 dev_printk(KERN_INFO, &phy->dev,
970 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
971 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
972 mpt3sas_phy->handle, (unsigned long long)
973 mpt3sas_phy->identify.sas_address,
974 mpt3sas_phy->attached_handle,
976 mpt3sas_phy->remote_identify.sas_address);
977 mpt3sas_phy->phy = phy;
982 * mpt3sas_transport_update_links - refreshing phy link changes
983 * @ioc: per adapter object
984 * @sas_address: sas address of parent expander or sas host
985 * @handle: attached device handle
986 * @phy_number: phy number
987 * @link_rate: new link rate
990 mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
991 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate)
994 struct _sas_node *sas_node;
995 struct _sas_phy *mpt3sas_phy;
997 if (ioc->shost_recovery || ioc->pci_error_recovery)
1000 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1001 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
1003 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1007 mpt3sas_phy = &sas_node->phy[phy_number];
1008 mpt3sas_phy->attached_handle = handle;
1009 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1010 if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
1011 _transport_set_identify(ioc, handle,
1012 &mpt3sas_phy->remote_identify);
1013 _transport_add_phy_to_an_existing_port(ioc, sas_node,
1014 mpt3sas_phy, mpt3sas_phy->remote_identify.sas_address);
1016 memset(&mpt3sas_phy->remote_identify, 0 , sizeof(struct
1019 if (mpt3sas_phy->phy)
1020 mpt3sas_phy->phy->negotiated_linkrate =
1021 _transport_convert_phy_link_rate(link_rate);
1023 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
1024 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
1025 "refresh: parent sas_addr(0x%016llx),\n"
1026 "\tlink_rate(0x%02x), phy(%d)\n"
1027 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1028 (unsigned long long)sas_address,
1029 link_rate, phy_number, handle, (unsigned long long)
1030 mpt3sas_phy->remote_identify.sas_address);
1033 static inline void *
1034 phy_to_ioc(struct sas_phy *phy)
1036 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
1037 return shost_priv(shost);
1040 static inline void *
1041 rphy_to_ioc(struct sas_rphy *rphy)
1043 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
1044 return shost_priv(shost);
1047 /* report phy error log structure */
1048 struct phy_error_log_request {
1049 u8 smp_frame_type; /* 0x40 */
1050 u8 function; /* 0x11 */
1051 u8 allocated_response_length;
1052 u8 request_length; /* 02 */
1058 /* report phy error log reply structure */
1059 struct phy_error_log_reply {
1060 u8 smp_frame_type; /* 0x41 */
1061 u8 function; /* 0x11 */
1064 __be16 expander_change_count;
1068 __be32 invalid_dword;
1069 __be32 running_disparity_error;
1070 __be32 loss_of_dword_sync;
1071 __be32 phy_reset_problem;
1075 * _transport_get_expander_phy_error_log - return expander counters
1076 * @ioc: per adapter object
1077 * @phy: The sas phy object
1079 * Return: 0 for success, non-zero for failure.
1083 _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER *ioc,
1084 struct sas_phy *phy)
1086 Mpi2SmpPassthroughRequest_t *mpi_request;
1087 Mpi2SmpPassthroughReply_t *mpi_reply;
1088 struct phy_error_log_request *phy_error_log_request;
1089 struct phy_error_log_reply *phy_error_log_reply;
1095 void *data_out = NULL;
1096 dma_addr_t data_out_dma;
1098 u16 wait_state_count;
1100 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1101 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1102 __func__, ioc->name);
1106 mutex_lock(&ioc->transport_cmds.mutex);
1108 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1109 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1110 ioc->name, __func__);
1114 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1116 wait_state_count = 0;
1117 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1118 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1119 if (wait_state_count++ == 10) {
1121 "%s: failed due to ioc not operational\n",
1122 ioc->name, __func__);
1127 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1129 "%s: waiting for operational state(count=%d)\n",
1130 ioc->name, __func__, wait_state_count);
1132 if (wait_state_count)
1133 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1134 ioc->name, __func__);
1136 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1138 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1139 ioc->name, __func__);
1144 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1145 ioc->transport_cmds.smid = smid;
1147 sz = sizeof(struct phy_error_log_request) +
1148 sizeof(struct phy_error_log_reply);
1149 data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1151 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1152 __LINE__, __func__);
1154 mpt3sas_base_free_smid(ioc, smid);
1159 memset(data_out, 0, sz);
1160 phy_error_log_request = data_out;
1161 phy_error_log_request->smp_frame_type = 0x40;
1162 phy_error_log_request->function = 0x11;
1163 phy_error_log_request->request_length = 2;
1164 phy_error_log_request->allocated_response_length = 0;
1165 phy_error_log_request->phy_identifier = phy->number;
1167 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1168 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1169 mpi_request->PhysicalPort = 0xFF;
1170 mpi_request->VF_ID = 0; /* TODO */
1171 mpi_request->VP_ID = 0;
1172 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1173 mpi_request->RequestDataLength =
1174 cpu_to_le16(sizeof(struct phy_error_log_request));
1175 psge = &mpi_request->SGL;
1177 ioc->build_sg(ioc, psge, data_out_dma,
1178 sizeof(struct phy_error_log_request),
1179 data_out_dma + sizeof(struct phy_error_log_request),
1180 sizeof(struct phy_error_log_reply));
1182 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1183 "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1184 ioc->name, (unsigned long long)phy->identify.sas_address,
1186 init_completion(&ioc->transport_cmds.done);
1187 mpt3sas_base_put_smid_default(ioc, smid);
1188 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1190 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1191 pr_err(MPT3SAS_FMT "%s: timeout\n",
1192 ioc->name, __func__);
1193 _debug_dump_mf(mpi_request,
1194 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1195 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1197 goto issue_host_reset;
1200 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1201 "phy_error_log - complete\n", ioc->name));
1203 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1205 mpi_reply = ioc->transport_cmds.reply;
1207 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1208 "phy_error_log - reply data transfer size(%d)\n",
1209 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1211 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1212 sizeof(struct phy_error_log_reply))
1215 phy_error_log_reply = data_out +
1216 sizeof(struct phy_error_log_request);
1218 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1219 "phy_error_log - function_result(%d)\n",
1220 ioc->name, phy_error_log_reply->function_result));
1222 phy->invalid_dword_count =
1223 be32_to_cpu(phy_error_log_reply->invalid_dword);
1224 phy->running_disparity_error_count =
1225 be32_to_cpu(phy_error_log_reply->running_disparity_error);
1226 phy->loss_of_dword_sync_count =
1227 be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
1228 phy->phy_reset_problem_count =
1229 be32_to_cpu(phy_error_log_reply->phy_reset_problem);
1232 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1233 "phy_error_log - no reply\n", ioc->name));
1237 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1239 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1241 pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1243 mutex_unlock(&ioc->transport_cmds.mutex);
1248 * _transport_get_linkerrors - return phy counters for both hba and expanders
1249 * @phy: The sas phy object
1251 * Return: 0 for success, non-zero for failure.
1255 _transport_get_linkerrors(struct sas_phy *phy)
1257 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1258 unsigned long flags;
1259 Mpi2ConfigReply_t mpi_reply;
1260 Mpi2SasPhyPage1_t phy_pg1;
1262 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1263 if (_transport_sas_node_find_by_sas_address(ioc,
1264 phy->identify.sas_address) == NULL) {
1265 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1268 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1270 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1271 return _transport_get_expander_phy_error_log(ioc, phy);
1273 /* get hba phy error logs */
1274 if ((mpt3sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
1276 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1277 ioc->name, __FILE__, __LINE__, __func__);
1281 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1283 "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1284 ioc->name, phy->number,
1285 le16_to_cpu(mpi_reply.IOCStatus),
1286 le32_to_cpu(mpi_reply.IOCLogInfo));
1288 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
1289 phy->running_disparity_error_count =
1290 le32_to_cpu(phy_pg1.RunningDisparityErrorCount);
1291 phy->loss_of_dword_sync_count =
1292 le32_to_cpu(phy_pg1.LossDwordSynchCount);
1293 phy->phy_reset_problem_count =
1294 le32_to_cpu(phy_pg1.PhyResetProblemCount);
1299 * _transport_get_enclosure_identifier -
1300 * @rphy: The sas phy object
1303 * Obtain the enclosure logical id for an expander.
1304 * Return: 0 for success, non-zero for failure.
1307 _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1309 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1310 struct _sas_device *sas_device;
1311 unsigned long flags;
1314 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1315 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1316 rphy->identify.sas_address);
1318 *identifier = sas_device->enclosure_logical_id;
1320 sas_device_put(sas_device);
1326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1331 * _transport_get_bay_identifier -
1332 * @rphy: The sas phy object
1334 * Return: the slot id for a device that resides inside an enclosure.
1337 _transport_get_bay_identifier(struct sas_rphy *rphy)
1339 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1340 struct _sas_device *sas_device;
1341 unsigned long flags;
1344 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1345 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1346 rphy->identify.sas_address);
1348 rc = sas_device->slot;
1349 sas_device_put(sas_device);
1353 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1357 /* phy control request structure */
1358 struct phy_control_request {
1359 u8 smp_frame_type; /* 0x40 */
1360 u8 function; /* 0x91 */
1361 u8 allocated_response_length;
1362 u8 request_length; /* 0x09 */
1363 u16 expander_change_count;
1368 u64 attached_device_name;
1369 u8 programmed_min_physical_link_rate;
1370 u8 programmed_max_physical_link_rate;
1374 /* phy control reply structure */
1375 struct phy_control_reply {
1376 u8 smp_frame_type; /* 0x41 */
1377 u8 function; /* 0x11 */
1382 #define SMP_PHY_CONTROL_LINK_RESET (0x01)
1383 #define SMP_PHY_CONTROL_HARD_RESET (0x02)
1384 #define SMP_PHY_CONTROL_DISABLE (0x03)
1387 * _transport_expander_phy_control - expander phy control
1388 * @ioc: per adapter object
1389 * @phy: The sas phy object
1392 * Return: 0 for success, non-zero for failure.
1396 _transport_expander_phy_control(struct MPT3SAS_ADAPTER *ioc,
1397 struct sas_phy *phy, u8 phy_operation)
1399 Mpi2SmpPassthroughRequest_t *mpi_request;
1400 Mpi2SmpPassthroughReply_t *mpi_reply;
1401 struct phy_control_request *phy_control_request;
1402 struct phy_control_reply *phy_control_reply;
1408 void *data_out = NULL;
1409 dma_addr_t data_out_dma;
1411 u16 wait_state_count;
1413 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1414 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1415 __func__, ioc->name);
1419 mutex_lock(&ioc->transport_cmds.mutex);
1421 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1422 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1423 ioc->name, __func__);
1427 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1429 wait_state_count = 0;
1430 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1431 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1432 if (wait_state_count++ == 10) {
1434 "%s: failed due to ioc not operational\n",
1435 ioc->name, __func__);
1440 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1442 "%s: waiting for operational state(count=%d)\n",
1443 ioc->name, __func__, wait_state_count);
1445 if (wait_state_count)
1446 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1447 ioc->name, __func__);
1449 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1451 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1452 ioc->name, __func__);
1457 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1458 ioc->transport_cmds.smid = smid;
1460 sz = sizeof(struct phy_control_request) +
1461 sizeof(struct phy_control_reply);
1462 data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1464 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1465 __LINE__, __func__);
1467 mpt3sas_base_free_smid(ioc, smid);
1472 memset(data_out, 0, sz);
1473 phy_control_request = data_out;
1474 phy_control_request->smp_frame_type = 0x40;
1475 phy_control_request->function = 0x91;
1476 phy_control_request->request_length = 9;
1477 phy_control_request->allocated_response_length = 0;
1478 phy_control_request->phy_identifier = phy->number;
1479 phy_control_request->phy_operation = phy_operation;
1480 phy_control_request->programmed_min_physical_link_rate =
1481 phy->minimum_linkrate << 4;
1482 phy_control_request->programmed_max_physical_link_rate =
1483 phy->maximum_linkrate << 4;
1485 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1486 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1487 mpi_request->PhysicalPort = 0xFF;
1488 mpi_request->VF_ID = 0; /* TODO */
1489 mpi_request->VP_ID = 0;
1490 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1491 mpi_request->RequestDataLength =
1492 cpu_to_le16(sizeof(struct phy_error_log_request));
1493 psge = &mpi_request->SGL;
1495 ioc->build_sg(ioc, psge, data_out_dma,
1496 sizeof(struct phy_control_request),
1497 data_out_dma + sizeof(struct phy_control_request),
1498 sizeof(struct phy_control_reply));
1500 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1501 "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1502 ioc->name, (unsigned long long)phy->identify.sas_address,
1503 phy->number, phy_operation));
1504 init_completion(&ioc->transport_cmds.done);
1505 mpt3sas_base_put_smid_default(ioc, smid);
1506 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1508 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1509 pr_err(MPT3SAS_FMT "%s: timeout\n",
1510 ioc->name, __func__);
1511 _debug_dump_mf(mpi_request,
1512 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1513 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1515 goto issue_host_reset;
1518 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1519 "phy_control - complete\n", ioc->name));
1521 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1523 mpi_reply = ioc->transport_cmds.reply;
1525 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1526 "phy_control - reply data transfer size(%d)\n",
1527 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1529 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1530 sizeof(struct phy_control_reply))
1533 phy_control_reply = data_out +
1534 sizeof(struct phy_control_request);
1536 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1537 "phy_control - function_result(%d)\n",
1538 ioc->name, phy_control_reply->function_result));
1542 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1543 "phy_control - no reply\n", ioc->name));
1547 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1549 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1551 pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1553 mutex_unlock(&ioc->transport_cmds.mutex);
1558 * _transport_phy_reset -
1559 * @phy: The sas phy object
1562 * Return: 0 for success, non-zero for failure.
1565 _transport_phy_reset(struct sas_phy *phy, int hard_reset)
1567 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1568 Mpi2SasIoUnitControlReply_t mpi_reply;
1569 Mpi2SasIoUnitControlRequest_t mpi_request;
1570 unsigned long flags;
1572 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1573 if (_transport_sas_node_find_by_sas_address(ioc,
1574 phy->identify.sas_address) == NULL) {
1575 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1578 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1580 /* handle expander phys */
1581 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1582 return _transport_expander_phy_control(ioc, phy,
1583 (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET :
1584 SMP_PHY_CONTROL_LINK_RESET);
1586 /* handle hba phys */
1587 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
1588 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
1589 mpi_request.Operation = hard_reset ?
1590 MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET;
1591 mpi_request.PhyNum = phy->number;
1593 if ((mpt3sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
1594 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1595 ioc->name, __FILE__, __LINE__, __func__);
1599 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1601 "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1602 ioc->name, phy->number, le16_to_cpu(mpi_reply.IOCStatus),
1603 le32_to_cpu(mpi_reply.IOCLogInfo));
1609 * _transport_phy_enable - enable/disable phys
1610 * @phy: The sas phy object
1611 * @enable: enable phy when true
1613 * Only support sas_host direct attached phys.
1614 * Return: 0 for success, non-zero for failure.
1617 _transport_phy_enable(struct sas_phy *phy, int enable)
1619 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1620 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1621 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
1622 Mpi2ConfigReply_t mpi_reply;
1626 unsigned long flags;
1627 int i, discovery_active;
1629 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1630 if (_transport_sas_node_find_by_sas_address(ioc,
1631 phy->identify.sas_address) == NULL) {
1632 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1635 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1637 /* handle expander phys */
1638 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1639 return _transport_expander_phy_control(ioc, phy,
1640 (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET :
1641 SMP_PHY_CONTROL_DISABLE);
1643 /* handle hba phys */
1645 /* read sas_iounit page 0 */
1646 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
1647 sizeof(Mpi2SasIOUnit0PhyData_t));
1648 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
1649 if (!sas_iounit_pg0) {
1650 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1651 ioc->name, __FILE__, __LINE__, __func__);
1655 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
1656 sas_iounit_pg0, sz))) {
1657 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1658 ioc->name, __FILE__, __LINE__, __func__);
1662 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1663 MPI2_IOCSTATUS_MASK;
1664 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1665 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1666 ioc->name, __FILE__, __LINE__, __func__);
1671 /* unable to enable/disable phys when when discovery is active */
1672 for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) {
1673 if (sas_iounit_pg0->PhyData[i].PortFlags &
1674 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
1675 pr_err(MPT3SAS_FMT "discovery is active on " \
1676 "port = %d, phy = %d: unable to enable/disable "
1677 "phys, try again later!\n", ioc->name,
1678 sas_iounit_pg0->PhyData[i].Port, i);
1679 discovery_active = 1;
1683 if (discovery_active) {
1688 /* read sas_iounit page 1 */
1689 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1690 sizeof(Mpi2SasIOUnit1PhyData_t));
1691 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1692 if (!sas_iounit_pg1) {
1693 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1694 ioc->name, __FILE__, __LINE__, __func__);
1698 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1699 sas_iounit_pg1, sz))) {
1700 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1701 ioc->name, __FILE__, __LINE__, __func__);
1705 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1706 MPI2_IOCSTATUS_MASK;
1707 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1708 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1709 ioc->name, __FILE__, __LINE__, __func__);
1714 /* copy Port/PortFlags/PhyFlags from page 0 */
1715 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
1716 sas_iounit_pg1->PhyData[i].Port =
1717 sas_iounit_pg0->PhyData[i].Port;
1718 sas_iounit_pg1->PhyData[i].PortFlags =
1719 (sas_iounit_pg0->PhyData[i].PortFlags &
1720 MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG);
1721 sas_iounit_pg1->PhyData[i].PhyFlags =
1722 (sas_iounit_pg0->PhyData[i].PhyFlags &
1723 (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED +
1724 MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED));
1728 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1729 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1731 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1732 |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1734 mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
1738 _transport_phy_reset(phy, 0);
1741 kfree(sas_iounit_pg1);
1742 kfree(sas_iounit_pg0);
1747 * _transport_phy_speed - set phy min/max link rates
1748 * @phy: The sas phy object
1749 * @rates: rates defined in sas_phy_linkrates
1751 * Only support sas_host direct attached phys.
1753 * Return: 0 for success, non-zero for failure.
1756 _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
1758 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1759 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1760 Mpi2SasPhyPage0_t phy_pg0;
1761 Mpi2ConfigReply_t mpi_reply;
1766 unsigned long flags;
1768 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1769 if (_transport_sas_node_find_by_sas_address(ioc,
1770 phy->identify.sas_address) == NULL) {
1771 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1774 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1776 if (!rates->minimum_linkrate)
1777 rates->minimum_linkrate = phy->minimum_linkrate;
1778 else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
1779 rates->minimum_linkrate = phy->minimum_linkrate_hw;
1781 if (!rates->maximum_linkrate)
1782 rates->maximum_linkrate = phy->maximum_linkrate;
1783 else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
1784 rates->maximum_linkrate = phy->maximum_linkrate_hw;
1786 /* handle expander phys */
1787 if (phy->identify.sas_address != ioc->sas_hba.sas_address) {
1788 phy->minimum_linkrate = rates->minimum_linkrate;
1789 phy->maximum_linkrate = rates->maximum_linkrate;
1790 return _transport_expander_phy_control(ioc, phy,
1791 SMP_PHY_CONTROL_LINK_RESET);
1794 /* handle hba phys */
1796 /* sas_iounit page 1 */
1797 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1798 sizeof(Mpi2SasIOUnit1PhyData_t));
1799 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1800 if (!sas_iounit_pg1) {
1801 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1802 ioc->name, __FILE__, __LINE__, __func__);
1806 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1807 sas_iounit_pg1, sz))) {
1808 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1809 ioc->name, __FILE__, __LINE__, __func__);
1813 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1814 MPI2_IOCSTATUS_MASK;
1815 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1816 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1817 ioc->name, __FILE__, __LINE__, __func__);
1822 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
1823 if (phy->number != i) {
1824 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1825 (ioc->sas_hba.phy[i].phy->minimum_linkrate +
1826 (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
1828 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1829 (rates->minimum_linkrate +
1830 (rates->maximum_linkrate << 4));
1834 if (mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
1836 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1837 ioc->name, __FILE__, __LINE__, __func__);
1843 _transport_phy_reset(phy, 0);
1845 /* read phy page 0, then update the rates in the sas transport phy */
1846 if (!mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
1848 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1849 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
1850 phy->maximum_linkrate = _transport_convert_phy_link_rate(
1851 phy_pg0.ProgrammedLinkRate >> 4);
1852 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
1853 phy_pg0.NegotiatedLinkRate &
1854 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
1858 kfree(sas_iounit_pg1);
1863 _transport_map_smp_buffer(struct device *dev, struct bsg_buffer *buf,
1864 dma_addr_t *dma_addr, size_t *dma_len, void **p)
1866 /* Check if the request is split across multiple segments */
1867 if (buf->sg_cnt > 1) {
1868 *p = dma_alloc_coherent(dev, buf->payload_len, dma_addr,
1872 *dma_len = buf->payload_len;
1874 if (!dma_map_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL))
1876 *dma_addr = sg_dma_address(buf->sg_list);
1877 *dma_len = sg_dma_len(buf->sg_list);
1885 _transport_unmap_smp_buffer(struct device *dev, struct bsg_buffer *buf,
1886 dma_addr_t dma_addr, void *p)
1889 dma_free_coherent(dev, buf->payload_len, p, dma_addr);
1891 dma_unmap_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL);
1895 * _transport_smp_handler - transport portal for smp passthru
1897 * @shost: shost object
1898 * @rphy: sas transport rphy object
1900 * This used primarily for smp_utils.
1902 * smp_rep_general /sys/class/bsg/expander-5:0
1905 _transport_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
1906 struct sas_rphy *rphy)
1908 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1909 Mpi2SmpPassthroughRequest_t *mpi_request;
1910 Mpi2SmpPassthroughReply_t *mpi_reply;
1915 dma_addr_t dma_addr_in;
1916 dma_addr_t dma_addr_out;
1917 void *addr_in = NULL;
1918 void *addr_out = NULL;
1921 u16 wait_state_count;
1922 unsigned int reslen = 0;
1924 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1925 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1926 __func__, ioc->name);
1931 rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex);
1935 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1936 pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n", ioc->name,
1941 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1943 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->request_payload,
1944 &dma_addr_out, &dma_len_out, &addr_out);
1948 sg_copy_to_buffer(job->request_payload.sg_list,
1949 job->request_payload.sg_cnt, addr_out,
1950 job->request_payload.payload_len);
1953 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
1954 &dma_addr_in, &dma_len_in, &addr_in);
1958 wait_state_count = 0;
1959 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1960 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1961 if (wait_state_count++ == 10) {
1963 "%s: failed due to ioc not operational\n",
1964 ioc->name, __func__);
1969 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1971 "%s: waiting for operational state(count=%d)\n",
1972 ioc->name, __func__, wait_state_count);
1974 if (wait_state_count)
1975 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1976 ioc->name, __func__);
1978 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1980 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1981 ioc->name, __func__);
1987 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1988 ioc->transport_cmds.smid = smid;
1990 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1991 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1992 mpi_request->PhysicalPort = 0xFF;
1993 mpi_request->SASAddress = (rphy) ?
1994 cpu_to_le64(rphy->identify.sas_address) :
1995 cpu_to_le64(ioc->sas_hba.sas_address);
1996 mpi_request->RequestDataLength = cpu_to_le16(dma_len_out - 4);
1997 psge = &mpi_request->SGL;
1999 ioc->build_sg(ioc, psge, dma_addr_out, dma_len_out - 4, dma_addr_in,
2002 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2003 "%s - sending smp request\n", ioc->name, __func__));
2005 init_completion(&ioc->transport_cmds.done);
2006 mpt3sas_base_put_smid_default(ioc, smid);
2007 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
2009 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
2010 pr_err(MPT3SAS_FMT "%s : timeout\n",
2011 __func__, ioc->name);
2012 _debug_dump_mf(mpi_request,
2013 sizeof(Mpi2SmpPassthroughRequest_t)/4);
2014 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET)) {
2015 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2021 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2022 "%s - complete\n", ioc->name, __func__));
2024 if (!(ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID)) {
2025 dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2026 "%s - no reply\n", ioc->name, __func__));
2031 mpi_reply = ioc->transport_cmds.reply;
2033 dtransportprintk(ioc,
2034 pr_info(MPT3SAS_FMT "%s - reply data transfer size(%d)\n",
2035 ioc->name, __func__,
2036 le16_to_cpu(mpi_reply->ResponseDataLength)));
2038 memcpy(job->reply, mpi_reply, sizeof(*mpi_reply));
2039 job->reply_len = sizeof(*mpi_reply);
2040 reslen = le16_to_cpu(mpi_reply->ResponseDataLength);
2043 sg_copy_to_buffer(job->reply_payload.sg_list,
2044 job->reply_payload.sg_cnt, addr_in,
2045 job->reply_payload.payload_len);
2050 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
2051 dma_addr_in, addr_in);
2053 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->request_payload,
2054 dma_addr_out, addr_out);
2056 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
2057 mutex_unlock(&ioc->transport_cmds.mutex);
2059 bsg_job_done(job, rc, reslen);
2062 struct sas_function_template mpt3sas_transport_functions = {
2063 .get_linkerrors = _transport_get_linkerrors,
2064 .get_enclosure_identifier = _transport_get_enclosure_identifier,
2065 .get_bay_identifier = _transport_get_bay_identifier,
2066 .phy_reset = _transport_phy_reset,
2067 .phy_enable = _transport_phy_enable,
2068 .set_phy_speed = _transport_phy_speed,
2069 .smp_handler = _transport_smp_handler,
2072 struct scsi_transport_template *mpt3sas_transport_template;