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_get_port_id_by_sas_phy - get zone's port id that Phy belong to
65 * @phy: sas_phy object
70 _transport_get_port_id_by_sas_phy(struct sas_phy *phy)
73 struct hba_port *port = phy->hostdata;
76 port_id = port->port_id;
82 * _transport_sas_node_find_by_sas_address - sas node search
83 * @ioc: per adapter object
84 * @sas_address: sas address of expander or sas host
85 * @port: hba port entry
86 * Context: Calling function should acquire ioc->sas_node_lock.
88 * Search for either hba phys or expander device based on handle, then returns
89 * the sas_node object.
91 static struct _sas_node *
92 _transport_sas_node_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
93 u64 sas_address, struct hba_port *port)
95 if (ioc->sas_hba.sas_address == sas_address)
98 return mpt3sas_scsih_expander_find_by_sas_address(ioc,
103 * _transport_get_port_id_by_rphy - Get Port number from rphy object
104 * @ioc: per adapter object
105 * @rphy: sas_rphy object
107 * Returns Port number.
110 _transport_get_port_id_by_rphy(struct MPT3SAS_ADAPTER *ioc,
111 struct sas_rphy *rphy)
113 struct _sas_node *sas_expander;
114 struct _sas_device *sas_device;
121 if (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
122 rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE) {
123 spin_lock_irqsave(&ioc->sas_node_lock, flags);
124 list_for_each_entry(sas_expander,
125 &ioc->sas_expander_list, list) {
126 if (sas_expander->rphy == rphy) {
127 port_id = sas_expander->port->port_id;
131 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
132 } else if (rphy->identify.device_type == SAS_END_DEVICE) {
133 spin_lock_irqsave(&ioc->sas_device_lock, flags);
134 sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy);
136 port_id = sas_device->port->port_id;
137 sas_device_put(sas_device);
139 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
146 * _transport_convert_phy_link_rate -
147 * @link_rate: link rate returned from mpt firmware
149 * Convert link_rate from mpi fusion into sas_transport form.
151 static enum sas_linkrate
152 _transport_convert_phy_link_rate(u8 link_rate)
154 enum sas_linkrate rc;
157 case MPI2_SAS_NEG_LINK_RATE_1_5:
158 rc = SAS_LINK_RATE_1_5_GBPS;
160 case MPI2_SAS_NEG_LINK_RATE_3_0:
161 rc = SAS_LINK_RATE_3_0_GBPS;
163 case MPI2_SAS_NEG_LINK_RATE_6_0:
164 rc = SAS_LINK_RATE_6_0_GBPS;
166 case MPI25_SAS_NEG_LINK_RATE_12_0:
167 rc = SAS_LINK_RATE_12_0_GBPS;
169 case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED:
170 rc = SAS_PHY_DISABLED;
172 case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED:
173 rc = SAS_LINK_RATE_FAILED;
175 case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR:
176 rc = SAS_SATA_PORT_SELECTOR;
178 case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS:
179 rc = SAS_PHY_RESET_IN_PROGRESS;
183 case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE:
184 case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE:
185 rc = SAS_LINK_RATE_UNKNOWN;
192 * _transport_set_identify - set identify for phys and end devices
193 * @ioc: per adapter object
194 * @handle: device handle
195 * @identify: sas identify info
197 * Populates sas identify info.
199 * Return: 0 for success, non-zero for failure.
202 _transport_set_identify(struct MPT3SAS_ADAPTER *ioc, u16 handle,
203 struct sas_identify *identify)
205 Mpi2SasDevicePage0_t sas_device_pg0;
206 Mpi2ConfigReply_t mpi_reply;
210 if (ioc->shost_recovery || ioc->pci_error_recovery) {
211 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
215 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
216 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
217 ioc_err(ioc, "failure at %s:%d/%s()!\n",
218 __FILE__, __LINE__, __func__);
222 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
224 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
225 ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x) failure at %s:%d/%s()!\n",
226 handle, ioc_status, __FILE__, __LINE__, __func__);
230 memset(identify, 0, sizeof(struct sas_identify));
231 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
234 identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
236 /* phy number of the parent device this device is linked to */
237 identify->phy_identifier = sas_device_pg0.PhyNum;
240 switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
241 case MPI2_SAS_DEVICE_INFO_NO_DEVICE:
242 identify->device_type = SAS_PHY_UNUSED;
244 case MPI2_SAS_DEVICE_INFO_END_DEVICE:
245 identify->device_type = SAS_END_DEVICE;
247 case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER:
248 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
250 case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER:
251 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
255 /* initiator_port_protocols */
256 if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR)
257 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
258 if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR)
259 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
260 if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR)
261 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
262 if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST)
263 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
265 /* target_port_protocols */
266 if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET)
267 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
268 if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
269 identify->target_port_protocols |= SAS_PROTOCOL_STP;
270 if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET)
271 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
272 if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
273 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
279 * mpt3sas_transport_done - internal transport layer callback handler.
280 * @ioc: per adapter object
281 * @smid: system request message index
282 * @msix_index: MSIX table index supplied by the OS
283 * @reply: reply message frame(lower 32bit addr)
285 * Callback handler when sending internal generated transport cmds.
286 * The callback index passed is `ioc->transport_cb_idx`
288 * Return: 1 meaning mf should be freed from _base_interrupt
289 * 0 means the mf is freed from this function.
292 mpt3sas_transport_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
295 MPI2DefaultReply_t *mpi_reply;
297 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
298 if (ioc->transport_cmds.status == MPT3_CMD_NOT_USED)
300 if (ioc->transport_cmds.smid != smid)
302 ioc->transport_cmds.status |= MPT3_CMD_COMPLETE;
304 memcpy(ioc->transport_cmds.reply, mpi_reply,
305 mpi_reply->MsgLength*4);
306 ioc->transport_cmds.status |= MPT3_CMD_REPLY_VALID;
308 ioc->transport_cmds.status &= ~MPT3_CMD_PENDING;
309 complete(&ioc->transport_cmds.done);
313 /* report manufacture request structure */
314 struct rep_manu_request {
321 /* report manufacture reply structure */
322 struct rep_manu_reply {
323 u8 smp_frame_type; /* 0x41 */
324 u8 function; /* 0x01 */
327 u16 expander_change_count;
331 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
332 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
333 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
334 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
336 u8 component_revision_id;
338 u8 vendor_specific[8];
342 * _transport_expander_report_manufacture - obtain SMP report_manufacture
343 * @ioc: per adapter object
344 * @sas_address: expander sas address
345 * @edev: the sas_expander_device object
346 * @port_id: Port ID number
348 * Fills in the sas_expander_device object when SMP port is created.
350 * Return: 0 for success, non-zero for failure.
353 _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc,
354 u64 sas_address, struct sas_expander_device *edev, u8 port_id)
356 Mpi2SmpPassthroughRequest_t *mpi_request;
357 Mpi2SmpPassthroughReply_t *mpi_reply;
358 struct rep_manu_reply *manufacture_reply;
359 struct rep_manu_request *manufacture_request;
364 void *data_out = NULL;
365 dma_addr_t data_out_dma;
366 dma_addr_t data_in_dma;
370 if (ioc->shost_recovery || ioc->pci_error_recovery) {
371 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
375 mutex_lock(&ioc->transport_cmds.mutex);
377 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
378 ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
382 ioc->transport_cmds.status = MPT3_CMD_PENDING;
384 rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
388 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
390 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
396 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
397 ioc->transport_cmds.smid = smid;
399 data_out_sz = sizeof(struct rep_manu_request);
400 data_in_sz = sizeof(struct rep_manu_reply);
401 data_out = dma_alloc_coherent(&ioc->pdev->dev, data_out_sz + data_in_sz,
402 &data_out_dma, GFP_KERNEL);
404 pr_err("failure at %s:%d/%s()!\n", __FILE__,
407 mpt3sas_base_free_smid(ioc, smid);
411 data_in_dma = data_out_dma + sizeof(struct rep_manu_request);
413 manufacture_request = data_out;
414 manufacture_request->smp_frame_type = 0x40;
415 manufacture_request->function = 1;
416 manufacture_request->reserved = 0;
417 manufacture_request->request_length = 0;
419 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
420 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
421 mpi_request->PhysicalPort = port_id;
422 mpi_request->SASAddress = cpu_to_le64(sas_address);
423 mpi_request->RequestDataLength = cpu_to_le16(data_out_sz);
424 psge = &mpi_request->SGL;
426 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
429 dtransportprintk(ioc,
430 ioc_info(ioc, "report_manufacture - send to sas_addr(0x%016llx)\n",
432 init_completion(&ioc->transport_cmds.done);
433 ioc->put_smid_default(ioc, smid);
434 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
436 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
437 ioc_err(ioc, "%s: timeout\n", __func__);
438 _debug_dump_mf(mpi_request,
439 sizeof(Mpi2SmpPassthroughRequest_t)/4);
440 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
442 goto issue_host_reset;
445 dtransportprintk(ioc, ioc_info(ioc, "report_manufacture - complete\n"));
447 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
450 mpi_reply = ioc->transport_cmds.reply;
452 dtransportprintk(ioc,
453 ioc_info(ioc, "report_manufacture - reply data transfer size(%d)\n",
454 le16_to_cpu(mpi_reply->ResponseDataLength)));
456 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
457 sizeof(struct rep_manu_reply))
460 manufacture_reply = data_out + sizeof(struct rep_manu_request);
461 strncpy(edev->vendor_id, manufacture_reply->vendor_id,
462 SAS_EXPANDER_VENDOR_ID_LEN);
463 strncpy(edev->product_id, manufacture_reply->product_id,
464 SAS_EXPANDER_PRODUCT_ID_LEN);
465 strncpy(edev->product_rev, manufacture_reply->product_rev,
466 SAS_EXPANDER_PRODUCT_REV_LEN);
467 edev->level = manufacture_reply->sas_format & 1;
469 strncpy(edev->component_vendor_id,
470 manufacture_reply->component_vendor_id,
471 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
472 tmp = (u8 *)&manufacture_reply->component_id;
473 edev->component_id = tmp[0] << 8 | tmp[1];
474 edev->component_revision_id =
475 manufacture_reply->component_revision_id;
478 dtransportprintk(ioc,
479 ioc_info(ioc, "report_manufacture - no reply\n"));
483 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
485 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
487 dma_free_coherent(&ioc->pdev->dev, data_out_sz + data_in_sz,
488 data_out, data_out_dma);
490 mutex_unlock(&ioc->transport_cmds.mutex);
496 * _transport_delete_port - helper function to removing a port
497 * @ioc: per adapter object
498 * @mpt3sas_port: mpt3sas per port object
501 _transport_delete_port(struct MPT3SAS_ADAPTER *ioc,
502 struct _sas_port *mpt3sas_port)
504 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
505 struct hba_port *port = mpt3sas_port->hba_port;
506 enum sas_device_type device_type =
507 mpt3sas_port->remote_identify.device_type;
509 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
510 "remove: sas_addr(0x%016llx)\n",
511 (unsigned long long) sas_address);
513 ioc->logging_level |= MPT_DEBUG_TRANSPORT;
514 if (device_type == SAS_END_DEVICE)
515 mpt3sas_device_remove_by_sas_address(ioc,
517 else if (device_type == SAS_EDGE_EXPANDER_DEVICE ||
518 device_type == SAS_FANOUT_EXPANDER_DEVICE)
519 mpt3sas_expander_remove(ioc, sas_address, port);
520 ioc->logging_level &= ~MPT_DEBUG_TRANSPORT;
524 * _transport_delete_phy - helper function to removing single phy from port
525 * @ioc: per adapter object
526 * @mpt3sas_port: mpt3sas per port object
527 * @mpt3sas_phy: mpt3sas per phy object
530 _transport_delete_phy(struct MPT3SAS_ADAPTER *ioc,
531 struct _sas_port *mpt3sas_port, struct _sas_phy *mpt3sas_phy)
533 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
535 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
536 "remove: sas_addr(0x%016llx), phy(%d)\n",
537 (unsigned long long) sas_address, mpt3sas_phy->phy_id);
539 list_del(&mpt3sas_phy->port_siblings);
540 mpt3sas_port->num_phys--;
541 sas_port_delete_phy(mpt3sas_port->port, mpt3sas_phy->phy);
542 mpt3sas_phy->phy_belongs_to_port = 0;
546 * _transport_add_phy - helper function to adding single phy to port
547 * @ioc: per adapter object
548 * @mpt3sas_port: mpt3sas per port object
549 * @mpt3sas_phy: mpt3sas per phy object
552 _transport_add_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_port *mpt3sas_port,
553 struct _sas_phy *mpt3sas_phy)
555 u64 sas_address = mpt3sas_port->remote_identify.sas_address;
557 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
558 "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
559 sas_address, mpt3sas_phy->phy_id);
561 list_add_tail(&mpt3sas_phy->port_siblings, &mpt3sas_port->phy_list);
562 mpt3sas_port->num_phys++;
563 sas_port_add_phy(mpt3sas_port->port, mpt3sas_phy->phy);
564 mpt3sas_phy->phy_belongs_to_port = 1;
568 * mpt3sas_transport_add_phy_to_an_existing_port - adding new phy to existing port
569 * @ioc: per adapter object
570 * @sas_node: sas node object (either expander or sas host)
571 * @mpt3sas_phy: mpt3sas per phy object
572 * @sas_address: sas address of device/expander were phy needs to be added to
573 * @port: hba port entry
576 mpt3sas_transport_add_phy_to_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
577 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy,
578 u64 sas_address, struct hba_port *port)
580 struct _sas_port *mpt3sas_port;
581 struct _sas_phy *phy_srch;
583 if (mpt3sas_phy->phy_belongs_to_port == 1)
589 list_for_each_entry(mpt3sas_port, &sas_node->sas_port_list,
591 if (mpt3sas_port->remote_identify.sas_address !=
594 if (mpt3sas_port->hba_port != port)
596 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
598 if (phy_srch == mpt3sas_phy)
601 _transport_add_phy(ioc, mpt3sas_port, mpt3sas_phy);
608 * mpt3sas_transport_del_phy_from_an_existing_port - delete phy from existing port
609 * @ioc: per adapter object
610 * @sas_node: sas node object (either expander or sas host)
611 * @mpt3sas_phy: mpt3sas per phy object
614 mpt3sas_transport_del_phy_from_an_existing_port(struct MPT3SAS_ADAPTER *ioc,
615 struct _sas_node *sas_node, struct _sas_phy *mpt3sas_phy)
617 struct _sas_port *mpt3sas_port, *next;
618 struct _sas_phy *phy_srch;
620 if (mpt3sas_phy->phy_belongs_to_port == 0)
623 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
625 list_for_each_entry(phy_srch, &mpt3sas_port->phy_list,
627 if (phy_srch != mpt3sas_phy)
631 * Don't delete port during host reset,
634 if (mpt3sas_port->num_phys == 1 && !ioc->shost_recovery)
635 _transport_delete_port(ioc, mpt3sas_port);
637 _transport_delete_phy(ioc, mpt3sas_port,
645 * _transport_sanity_check - sanity check when adding a new port
646 * @ioc: per adapter object
647 * @sas_node: sas node object (either expander or sas host)
648 * @sas_address: sas address of device being added
649 * @port: hba port entry
651 * See the explanation above from _transport_delete_duplicate_port
654 _transport_sanity_check(struct MPT3SAS_ADAPTER *ioc, struct _sas_node *sas_node,
655 u64 sas_address, struct hba_port *port)
659 for (i = 0; i < sas_node->num_phys; i++) {
660 if (sas_node->phy[i].remote_identify.sas_address != sas_address)
662 if (sas_node->phy[i].port != port)
664 if (sas_node->phy[i].phy_belongs_to_port == 1)
665 mpt3sas_transport_del_phy_from_an_existing_port(ioc,
666 sas_node, &sas_node->phy[i]);
671 * mpt3sas_transport_port_add - insert port to the list
672 * @ioc: per adapter object
673 * @handle: handle of attached device
674 * @sas_address: sas address of parent expander or sas host
675 * @hba_port: hba port entry
676 * Context: This function will acquire ioc->sas_node_lock.
678 * Adding new port object to the sas_node->sas_port_list.
680 * Return: mpt3sas_port.
683 mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
684 u64 sas_address, struct hba_port *hba_port)
686 struct _sas_phy *mpt3sas_phy, *next;
687 struct _sas_port *mpt3sas_port;
689 struct _sas_node *sas_node;
690 struct sas_rphy *rphy;
691 struct _sas_device *sas_device = NULL;
693 struct sas_port *port;
694 struct virtual_phy *vphy = NULL;
697 ioc_err(ioc, "failure at %s:%d/%s()!\n",
698 __FILE__, __LINE__, __func__);
702 mpt3sas_port = kzalloc(sizeof(struct _sas_port),
705 ioc_err(ioc, "failure at %s:%d/%s()!\n",
706 __FILE__, __LINE__, __func__);
710 INIT_LIST_HEAD(&mpt3sas_port->port_list);
711 INIT_LIST_HEAD(&mpt3sas_port->phy_list);
712 spin_lock_irqsave(&ioc->sas_node_lock, flags);
713 sas_node = _transport_sas_node_find_by_sas_address(ioc,
714 sas_address, hba_port);
715 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
718 ioc_err(ioc, "%s: Could not find parent sas_address(0x%016llx)!\n",
719 __func__, (u64)sas_address);
723 if ((_transport_set_identify(ioc, handle,
724 &mpt3sas_port->remote_identify))) {
725 ioc_err(ioc, "failure at %s:%d/%s()!\n",
726 __FILE__, __LINE__, __func__);
730 if (mpt3sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
731 ioc_err(ioc, "failure at %s:%d/%s()!\n",
732 __FILE__, __LINE__, __func__);
736 mpt3sas_port->hba_port = hba_port;
737 _transport_sanity_check(ioc, sas_node,
738 mpt3sas_port->remote_identify.sas_address, hba_port);
740 for (i = 0; i < sas_node->num_phys; i++) {
741 if (sas_node->phy[i].remote_identify.sas_address !=
742 mpt3sas_port->remote_identify.sas_address)
744 if (sas_node->phy[i].port != hba_port)
746 list_add_tail(&sas_node->phy[i].port_siblings,
747 &mpt3sas_port->phy_list);
748 mpt3sas_port->num_phys++;
749 if (sas_node->handle <= ioc->sas_hba.num_phys) {
750 if (!sas_node->phy[i].hba_vphy) {
751 hba_port->phy_mask |= (1 << i);
755 vphy = mpt3sas_get_vphy_by_phy(ioc, hba_port, i);
757 ioc_err(ioc, "failure at %s:%d/%s()!\n",
758 __FILE__, __LINE__, __func__);
764 if (!mpt3sas_port->num_phys) {
765 ioc_err(ioc, "failure at %s:%d/%s()!\n",
766 __FILE__, __LINE__, __func__);
770 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
771 sas_device = mpt3sas_get_sdev_by_addr(ioc,
772 mpt3sas_port->remote_identify.sas_address,
773 mpt3sas_port->hba_port);
775 ioc_err(ioc, "failure at %s:%d/%s()!\n",
776 __FILE__, __LINE__, __func__);
779 sas_device->pend_sas_rphy_add = 1;
782 if (!sas_node->parent_dev) {
783 ioc_err(ioc, "failure at %s:%d/%s()!\n",
784 __FILE__, __LINE__, __func__);
787 port = sas_port_alloc_num(sas_node->parent_dev);
788 if (!port || (sas_port_add(port))) {
789 ioc_err(ioc, "failure at %s:%d/%s()!\n",
790 __FILE__, __LINE__, __func__);
794 list_for_each_entry(mpt3sas_phy, &mpt3sas_port->phy_list,
796 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
797 dev_printk(KERN_INFO, &port->dev,
798 "add: handle(0x%04x), sas_addr(0x%016llx), phy(%d)\n",
799 handle, (unsigned long long)
800 mpt3sas_port->remote_identify.sas_address,
801 mpt3sas_phy->phy_id);
802 sas_port_add_phy(port, mpt3sas_phy->phy);
803 mpt3sas_phy->phy_belongs_to_port = 1;
804 mpt3sas_phy->port = hba_port;
807 mpt3sas_port->port = port;
808 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
809 rphy = sas_end_device_alloc(port);
810 sas_device->rphy = rphy;
811 if (sas_node->handle <= ioc->sas_hba.num_phys) {
813 hba_port->sas_address =
814 sas_device->sas_address;
817 sas_device->sas_address;
820 rphy = sas_expander_alloc(port,
821 mpt3sas_port->remote_identify.device_type);
822 if (sas_node->handle <= ioc->sas_hba.num_phys)
823 hba_port->sas_address =
824 mpt3sas_port->remote_identify.sas_address;
828 ioc_err(ioc, "failure at %s:%d/%s()!\n",
829 __FILE__, __LINE__, __func__);
830 goto out_delete_port;
833 rphy->identify = mpt3sas_port->remote_identify;
835 if ((sas_rphy_add(rphy))) {
836 ioc_err(ioc, "failure at %s:%d/%s()!\n",
837 __FILE__, __LINE__, __func__);
840 goto out_delete_port;
843 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
844 sas_device->pend_sas_rphy_add = 0;
845 sas_device_put(sas_device);
849 "add: handle(0x%04x), sas_addr(0x%016llx)\n", handle,
850 (unsigned long long)mpt3sas_port->remote_identify.sas_address);
852 mpt3sas_port->rphy = rphy;
853 spin_lock_irqsave(&ioc->sas_node_lock, flags);
854 list_add_tail(&mpt3sas_port->port_list, &sas_node->sas_port_list);
855 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
857 /* fill in report manufacture */
858 if (mpt3sas_port->remote_identify.device_type ==
859 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
860 mpt3sas_port->remote_identify.device_type ==
861 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
862 _transport_expander_report_manufacture(ioc,
863 mpt3sas_port->remote_identify.sas_address,
864 rphy_to_expander_device(rphy), hba_port->port_id);
868 sas_port_delete(port);
871 list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
873 list_del(&mpt3sas_phy->port_siblings);
879 * mpt3sas_transport_port_remove - remove port from the list
880 * @ioc: per adapter object
881 * @sas_address: sas address of attached device
882 * @sas_address_parent: sas address of parent expander or sas host
883 * @port: hba port entry
884 * Context: This function will acquire ioc->sas_node_lock.
886 * Removing object and freeing associated memory from the
887 * ioc->sas_port_list.
890 mpt3sas_transport_port_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
891 u64 sas_address_parent, struct hba_port *port)
895 struct _sas_port *mpt3sas_port, *next;
896 struct _sas_node *sas_node;
898 struct _sas_phy *mpt3sas_phy, *next_phy;
899 struct hba_port *hba_port_next, *hba_port = NULL;
900 struct virtual_phy *vphy, *vphy_next = NULL;
905 spin_lock_irqsave(&ioc->sas_node_lock, flags);
906 sas_node = _transport_sas_node_find_by_sas_address(ioc,
907 sas_address_parent, port);
909 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
912 list_for_each_entry_safe(mpt3sas_port, next, &sas_node->sas_port_list,
914 if (mpt3sas_port->remote_identify.sas_address != sas_address)
916 if (mpt3sas_port->hba_port != port)
919 list_del(&mpt3sas_port->port_list);
924 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
928 if (sas_node->handle <= ioc->sas_hba.num_phys &&
929 (ioc->multipath_on_hba)) {
930 if (port->vphys_mask) {
931 list_for_each_entry_safe(vphy, vphy_next,
932 &port->vphys_list, list) {
933 if (vphy->sas_address != sas_address)
936 "remove vphy entry: %p of port:%p,from %d port's vphys list\n",
937 vphy, port, port->port_id);
938 port->vphys_mask &= ~vphy->phy_mask;
939 list_del(&vphy->list);
944 list_for_each_entry_safe(hba_port, hba_port_next,
945 &ioc->port_table_list, list) {
946 if (hba_port != port)
949 * Delete hba_port object if
950 * - hba_port object's sas address matches with current
951 * removed device's sas address and no vphy's
952 * associated with it.
953 * - Current removed device is a vSES device and
954 * none of the other direct attached device have
955 * this vSES device's port number (hence hba_port
956 * object sas_address field will be zero).
958 if ((hba_port->sas_address == sas_address ||
959 !hba_port->sas_address) && !hba_port->vphys_mask) {
961 "remove hba_port entry: %p port: %d from hba_port list\n",
962 hba_port, hba_port->port_id);
963 list_del(&hba_port->list);
965 } else if (hba_port->sas_address == sas_address &&
966 hba_port->vphys_mask) {
968 * Current removed device is a non vSES device
969 * and a vSES device has the same port number
970 * as of current device's port number. Hence
971 * only clear the sas_address filed, don't
972 * delete the hba_port object.
975 "clearing sas_address from hba_port entry: %p port: %d from hba_port list\n",
976 hba_port, hba_port->port_id);
977 port->sas_address = 0;
983 for (i = 0; i < sas_node->num_phys; i++) {
984 if (sas_node->phy[i].remote_identify.sas_address == sas_address)
985 memset(&sas_node->phy[i].remote_identify, 0 ,
986 sizeof(struct sas_identify));
989 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
991 list_for_each_entry_safe(mpt3sas_phy, next_phy,
992 &mpt3sas_port->phy_list, port_siblings) {
993 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
994 dev_printk(KERN_INFO, &mpt3sas_port->port->dev,
995 "remove: sas_addr(0x%016llx), phy(%d)\n",
997 mpt3sas_port->remote_identify.sas_address,
998 mpt3sas_phy->phy_id);
999 mpt3sas_phy->phy_belongs_to_port = 0;
1000 if (!ioc->remove_host)
1001 sas_port_delete_phy(mpt3sas_port->port,
1003 list_del(&mpt3sas_phy->port_siblings);
1005 if (!ioc->remove_host)
1006 sas_port_delete(mpt3sas_port->port);
1007 ioc_info(ioc, "%s: removed: sas_addr(0x%016llx)\n",
1008 __func__, (unsigned long long)sas_address);
1009 kfree(mpt3sas_port);
1013 * mpt3sas_transport_add_host_phy - report sas_host phy to transport
1014 * @ioc: per adapter object
1015 * @mpt3sas_phy: mpt3sas per phy object
1016 * @phy_pg0: sas phy page 0
1017 * @parent_dev: parent device class object
1019 * Return: 0 for success, non-zero for failure.
1022 mpt3sas_transport_add_host_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
1023 *mpt3sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev)
1025 struct sas_phy *phy;
1026 int phy_index = mpt3sas_phy->phy_id;
1029 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
1030 phy = sas_phy_alloc(parent_dev, phy_index);
1032 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1033 __FILE__, __LINE__, __func__);
1036 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
1037 &mpt3sas_phy->identify))) {
1038 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1039 __FILE__, __LINE__, __func__);
1043 phy->identify = mpt3sas_phy->identify;
1044 mpt3sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle);
1045 if (mpt3sas_phy->attached_handle)
1046 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
1047 &mpt3sas_phy->remote_identify);
1048 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
1049 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
1050 phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
1051 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
1052 phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
1053 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
1054 phy_pg0.HwLinkRate >> 4);
1055 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1056 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
1057 phy->maximum_linkrate = _transport_convert_phy_link_rate(
1058 phy_pg0.ProgrammedLinkRate >> 4);
1059 phy->hostdata = mpt3sas_phy->port;
1061 if ((sas_phy_add(phy))) {
1062 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1063 __FILE__, __LINE__, __func__);
1067 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
1068 dev_printk(KERN_INFO, &phy->dev,
1069 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
1070 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1071 mpt3sas_phy->handle, (unsigned long long)
1072 mpt3sas_phy->identify.sas_address,
1073 mpt3sas_phy->attached_handle,
1074 (unsigned long long)
1075 mpt3sas_phy->remote_identify.sas_address);
1076 mpt3sas_phy->phy = phy;
1082 * mpt3sas_transport_add_expander_phy - report expander phy to transport
1083 * @ioc: per adapter object
1084 * @mpt3sas_phy: mpt3sas per phy object
1085 * @expander_pg1: expander page 1
1086 * @parent_dev: parent device class object
1088 * Return: 0 for success, non-zero for failure.
1091 mpt3sas_transport_add_expander_phy(struct MPT3SAS_ADAPTER *ioc, struct _sas_phy
1092 *mpt3sas_phy, Mpi2ExpanderPage1_t expander_pg1,
1093 struct device *parent_dev)
1095 struct sas_phy *phy;
1096 int phy_index = mpt3sas_phy->phy_id;
1098 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
1099 phy = sas_phy_alloc(parent_dev, phy_index);
1101 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1102 __FILE__, __LINE__, __func__);
1105 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
1106 &mpt3sas_phy->identify))) {
1107 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1108 __FILE__, __LINE__, __func__);
1112 phy->identify = mpt3sas_phy->identify;
1113 mpt3sas_phy->attached_handle =
1114 le16_to_cpu(expander_pg1.AttachedDevHandle);
1115 if (mpt3sas_phy->attached_handle)
1116 _transport_set_identify(ioc, mpt3sas_phy->attached_handle,
1117 &mpt3sas_phy->remote_identify);
1118 phy->identify.phy_identifier = mpt3sas_phy->phy_id;
1119 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
1120 expander_pg1.NegotiatedLinkRate &
1121 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
1122 phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
1123 expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
1124 phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
1125 expander_pg1.HwLinkRate >> 4);
1126 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1127 expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
1128 phy->maximum_linkrate = _transport_convert_phy_link_rate(
1129 expander_pg1.ProgrammedLinkRate >> 4);
1130 phy->hostdata = mpt3sas_phy->port;
1132 if ((sas_phy_add(phy))) {
1133 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1134 __FILE__, __LINE__, __func__);
1138 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
1139 dev_printk(KERN_INFO, &phy->dev,
1140 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
1141 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1142 mpt3sas_phy->handle, (unsigned long long)
1143 mpt3sas_phy->identify.sas_address,
1144 mpt3sas_phy->attached_handle,
1145 (unsigned long long)
1146 mpt3sas_phy->remote_identify.sas_address);
1147 mpt3sas_phy->phy = phy;
1152 * mpt3sas_transport_update_links - refreshing phy link changes
1153 * @ioc: per adapter object
1154 * @sas_address: sas address of parent expander or sas host
1155 * @handle: attached device handle
1156 * @phy_number: phy number
1157 * @link_rate: new link rate
1158 * @port: hba port entry
1163 mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
1164 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate,
1165 struct hba_port *port)
1167 unsigned long flags;
1168 struct _sas_node *sas_node;
1169 struct _sas_phy *mpt3sas_phy;
1170 struct hba_port *hba_port = NULL;
1172 if (ioc->shost_recovery || ioc->pci_error_recovery)
1175 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1176 sas_node = _transport_sas_node_find_by_sas_address(ioc,
1179 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1183 mpt3sas_phy = &sas_node->phy[phy_number];
1184 mpt3sas_phy->attached_handle = handle;
1185 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1186 if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
1187 _transport_set_identify(ioc, handle,
1188 &mpt3sas_phy->remote_identify);
1189 if ((sas_node->handle <= ioc->sas_hba.num_phys) &&
1190 (ioc->multipath_on_hba)) {
1191 list_for_each_entry(hba_port,
1192 &ioc->port_table_list, list) {
1193 if (hba_port->sas_address == sas_address &&
1195 hba_port->phy_mask |=
1196 (1 << mpt3sas_phy->phy_id);
1199 mpt3sas_transport_add_phy_to_an_existing_port(ioc, sas_node,
1200 mpt3sas_phy, mpt3sas_phy->remote_identify.sas_address,
1203 memset(&mpt3sas_phy->remote_identify, 0 , sizeof(struct
1206 if (mpt3sas_phy->phy)
1207 mpt3sas_phy->phy->negotiated_linkrate =
1208 _transport_convert_phy_link_rate(link_rate);
1210 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
1211 dev_printk(KERN_INFO, &mpt3sas_phy->phy->dev,
1212 "refresh: parent sas_addr(0x%016llx),\n"
1213 "\tlink_rate(0x%02x), phy(%d)\n"
1214 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1215 (unsigned long long)sas_address,
1216 link_rate, phy_number, handle, (unsigned long long)
1217 mpt3sas_phy->remote_identify.sas_address);
1220 static inline void *
1221 phy_to_ioc(struct sas_phy *phy)
1223 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
1224 return shost_priv(shost);
1227 static inline void *
1228 rphy_to_ioc(struct sas_rphy *rphy)
1230 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
1231 return shost_priv(shost);
1234 /* report phy error log structure */
1235 struct phy_error_log_request {
1236 u8 smp_frame_type; /* 0x40 */
1237 u8 function; /* 0x11 */
1238 u8 allocated_response_length;
1239 u8 request_length; /* 02 */
1245 /* report phy error log reply structure */
1246 struct phy_error_log_reply {
1247 u8 smp_frame_type; /* 0x41 */
1248 u8 function; /* 0x11 */
1251 __be16 expander_change_count;
1255 __be32 invalid_dword;
1256 __be32 running_disparity_error;
1257 __be32 loss_of_dword_sync;
1258 __be32 phy_reset_problem;
1262 * _transport_get_expander_phy_error_log - return expander counters
1263 * @ioc: per adapter object
1264 * @phy: The sas phy object
1266 * Return: 0 for success, non-zero for failure.
1270 _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER *ioc,
1271 struct sas_phy *phy)
1273 Mpi2SmpPassthroughRequest_t *mpi_request;
1274 Mpi2SmpPassthroughReply_t *mpi_reply;
1275 struct phy_error_log_request *phy_error_log_request;
1276 struct phy_error_log_reply *phy_error_log_reply;
1281 void *data_out = NULL;
1282 dma_addr_t data_out_dma;
1285 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1286 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
1290 mutex_lock(&ioc->transport_cmds.mutex);
1292 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1293 ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
1297 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1299 rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
1303 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1305 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
1310 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1311 ioc->transport_cmds.smid = smid;
1313 sz = sizeof(struct phy_error_log_request) +
1314 sizeof(struct phy_error_log_reply);
1315 data_out = dma_alloc_coherent(&ioc->pdev->dev, sz, &data_out_dma,
1318 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1319 __LINE__, __func__);
1321 mpt3sas_base_free_smid(ioc, smid);
1326 memset(data_out, 0, sz);
1327 phy_error_log_request = data_out;
1328 phy_error_log_request->smp_frame_type = 0x40;
1329 phy_error_log_request->function = 0x11;
1330 phy_error_log_request->request_length = 2;
1331 phy_error_log_request->allocated_response_length = 0;
1332 phy_error_log_request->phy_identifier = phy->number;
1334 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1335 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1336 mpi_request->PhysicalPort = _transport_get_port_id_by_sas_phy(phy);
1337 mpi_request->VF_ID = 0; /* TODO */
1338 mpi_request->VP_ID = 0;
1339 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1340 mpi_request->RequestDataLength =
1341 cpu_to_le16(sizeof(struct phy_error_log_request));
1342 psge = &mpi_request->SGL;
1344 ioc->build_sg(ioc, psge, data_out_dma,
1345 sizeof(struct phy_error_log_request),
1346 data_out_dma + sizeof(struct phy_error_log_request),
1347 sizeof(struct phy_error_log_reply));
1349 dtransportprintk(ioc,
1350 ioc_info(ioc, "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1351 (u64)phy->identify.sas_address,
1353 init_completion(&ioc->transport_cmds.done);
1354 ioc->put_smid_default(ioc, smid);
1355 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1357 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1358 ioc_err(ioc, "%s: timeout\n", __func__);
1359 _debug_dump_mf(mpi_request,
1360 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1361 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1363 goto issue_host_reset;
1366 dtransportprintk(ioc, ioc_info(ioc, "phy_error_log - complete\n"));
1368 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1370 mpi_reply = ioc->transport_cmds.reply;
1372 dtransportprintk(ioc,
1373 ioc_info(ioc, "phy_error_log - reply data transfer size(%d)\n",
1374 le16_to_cpu(mpi_reply->ResponseDataLength)));
1376 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1377 sizeof(struct phy_error_log_reply))
1380 phy_error_log_reply = data_out +
1381 sizeof(struct phy_error_log_request);
1383 dtransportprintk(ioc,
1384 ioc_info(ioc, "phy_error_log - function_result(%d)\n",
1385 phy_error_log_reply->function_result));
1387 phy->invalid_dword_count =
1388 be32_to_cpu(phy_error_log_reply->invalid_dword);
1389 phy->running_disparity_error_count =
1390 be32_to_cpu(phy_error_log_reply->running_disparity_error);
1391 phy->loss_of_dword_sync_count =
1392 be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
1393 phy->phy_reset_problem_count =
1394 be32_to_cpu(phy_error_log_reply->phy_reset_problem);
1397 dtransportprintk(ioc,
1398 ioc_info(ioc, "phy_error_log - no reply\n"));
1402 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1404 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1406 dma_free_coherent(&ioc->pdev->dev, sz, data_out, data_out_dma);
1408 mutex_unlock(&ioc->transport_cmds.mutex);
1413 * _transport_get_linkerrors - return phy counters for both hba and expanders
1414 * @phy: The sas phy object
1416 * Return: 0 for success, non-zero for failure.
1420 _transport_get_linkerrors(struct sas_phy *phy)
1422 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1423 unsigned long flags;
1424 Mpi2ConfigReply_t mpi_reply;
1425 Mpi2SasPhyPage1_t phy_pg1;
1426 struct hba_port *port = phy->hostdata;
1427 int port_id = port->port_id;
1429 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1430 if (_transport_sas_node_find_by_sas_address(ioc,
1431 phy->identify.sas_address,
1432 mpt3sas_get_port_by_id(ioc, port_id, 0)) == NULL) {
1433 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1436 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1438 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1439 return _transport_get_expander_phy_error_log(ioc, phy);
1441 /* get hba phy error logs */
1442 if ((mpt3sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
1444 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1445 __FILE__, __LINE__, __func__);
1449 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1450 ioc_info(ioc, "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1452 le16_to_cpu(mpi_reply.IOCStatus),
1453 le32_to_cpu(mpi_reply.IOCLogInfo));
1455 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
1456 phy->running_disparity_error_count =
1457 le32_to_cpu(phy_pg1.RunningDisparityErrorCount);
1458 phy->loss_of_dword_sync_count =
1459 le32_to_cpu(phy_pg1.LossDwordSynchCount);
1460 phy->phy_reset_problem_count =
1461 le32_to_cpu(phy_pg1.PhyResetProblemCount);
1466 * _transport_get_enclosure_identifier -
1467 * @rphy: The sas phy object
1470 * Obtain the enclosure logical id for an expander.
1471 * Return: 0 for success, non-zero for failure.
1474 _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1476 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1477 struct _sas_device *sas_device;
1478 unsigned long flags;
1481 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1482 sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy);
1484 *identifier = sas_device->enclosure_logical_id;
1486 sas_device_put(sas_device);
1492 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1497 * _transport_get_bay_identifier -
1498 * @rphy: The sas phy object
1500 * Return: the slot id for a device that resides inside an enclosure.
1503 _transport_get_bay_identifier(struct sas_rphy *rphy)
1505 struct MPT3SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
1506 struct _sas_device *sas_device;
1507 unsigned long flags;
1510 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1511 sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy);
1513 rc = sas_device->slot;
1514 sas_device_put(sas_device);
1518 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1522 /* phy control request structure */
1523 struct phy_control_request {
1524 u8 smp_frame_type; /* 0x40 */
1525 u8 function; /* 0x91 */
1526 u8 allocated_response_length;
1527 u8 request_length; /* 0x09 */
1528 u16 expander_change_count;
1533 u64 attached_device_name;
1534 u8 programmed_min_physical_link_rate;
1535 u8 programmed_max_physical_link_rate;
1539 /* phy control reply structure */
1540 struct phy_control_reply {
1541 u8 smp_frame_type; /* 0x41 */
1542 u8 function; /* 0x11 */
1547 #define SMP_PHY_CONTROL_LINK_RESET (0x01)
1548 #define SMP_PHY_CONTROL_HARD_RESET (0x02)
1549 #define SMP_PHY_CONTROL_DISABLE (0x03)
1552 * _transport_expander_phy_control - expander phy control
1553 * @ioc: per adapter object
1554 * @phy: The sas phy object
1557 * Return: 0 for success, non-zero for failure.
1561 _transport_expander_phy_control(struct MPT3SAS_ADAPTER *ioc,
1562 struct sas_phy *phy, u8 phy_operation)
1564 Mpi2SmpPassthroughRequest_t *mpi_request;
1565 Mpi2SmpPassthroughReply_t *mpi_reply;
1566 struct phy_control_request *phy_control_request;
1567 struct phy_control_reply *phy_control_reply;
1572 void *data_out = NULL;
1573 dma_addr_t data_out_dma;
1576 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1577 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
1581 mutex_lock(&ioc->transport_cmds.mutex);
1583 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1584 ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
1588 ioc->transport_cmds.status = MPT3_CMD_PENDING;
1590 rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
1594 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
1596 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
1601 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1602 ioc->transport_cmds.smid = smid;
1604 sz = sizeof(struct phy_control_request) +
1605 sizeof(struct phy_control_reply);
1606 data_out = dma_alloc_coherent(&ioc->pdev->dev, sz, &data_out_dma,
1609 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1610 __LINE__, __func__);
1612 mpt3sas_base_free_smid(ioc, smid);
1617 memset(data_out, 0, sz);
1618 phy_control_request = data_out;
1619 phy_control_request->smp_frame_type = 0x40;
1620 phy_control_request->function = 0x91;
1621 phy_control_request->request_length = 9;
1622 phy_control_request->allocated_response_length = 0;
1623 phy_control_request->phy_identifier = phy->number;
1624 phy_control_request->phy_operation = phy_operation;
1625 phy_control_request->programmed_min_physical_link_rate =
1626 phy->minimum_linkrate << 4;
1627 phy_control_request->programmed_max_physical_link_rate =
1628 phy->maximum_linkrate << 4;
1630 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1631 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1632 mpi_request->PhysicalPort = _transport_get_port_id_by_sas_phy(phy);
1633 mpi_request->VF_ID = 0; /* TODO */
1634 mpi_request->VP_ID = 0;
1635 mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
1636 mpi_request->RequestDataLength =
1637 cpu_to_le16(sizeof(struct phy_error_log_request));
1638 psge = &mpi_request->SGL;
1640 ioc->build_sg(ioc, psge, data_out_dma,
1641 sizeof(struct phy_control_request),
1642 data_out_dma + sizeof(struct phy_control_request),
1643 sizeof(struct phy_control_reply));
1645 dtransportprintk(ioc,
1646 ioc_info(ioc, "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1647 (u64)phy->identify.sas_address,
1648 phy->number, phy_operation));
1649 init_completion(&ioc->transport_cmds.done);
1650 ioc->put_smid_default(ioc, smid);
1651 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
1653 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1654 ioc_err(ioc, "%s: timeout\n", __func__);
1655 _debug_dump_mf(mpi_request,
1656 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1657 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
1659 goto issue_host_reset;
1662 dtransportprintk(ioc, ioc_info(ioc, "phy_control - complete\n"));
1664 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
1666 mpi_reply = ioc->transport_cmds.reply;
1668 dtransportprintk(ioc,
1669 ioc_info(ioc, "phy_control - reply data transfer size(%d)\n",
1670 le16_to_cpu(mpi_reply->ResponseDataLength)));
1672 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1673 sizeof(struct phy_control_reply))
1676 phy_control_reply = data_out +
1677 sizeof(struct phy_control_request);
1679 dtransportprintk(ioc,
1680 ioc_info(ioc, "phy_control - function_result(%d)\n",
1681 phy_control_reply->function_result));
1685 dtransportprintk(ioc,
1686 ioc_info(ioc, "phy_control - no reply\n"));
1690 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1692 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
1694 dma_free_coherent(&ioc->pdev->dev, sz, data_out,
1697 mutex_unlock(&ioc->transport_cmds.mutex);
1702 * _transport_phy_reset -
1703 * @phy: The sas phy object
1706 * Return: 0 for success, non-zero for failure.
1709 _transport_phy_reset(struct sas_phy *phy, int hard_reset)
1711 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1712 Mpi2SasIoUnitControlReply_t mpi_reply;
1713 Mpi2SasIoUnitControlRequest_t mpi_request;
1714 struct hba_port *port = phy->hostdata;
1715 int port_id = port->port_id;
1716 unsigned long flags;
1718 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1719 if (_transport_sas_node_find_by_sas_address(ioc,
1720 phy->identify.sas_address,
1721 mpt3sas_get_port_by_id(ioc, port_id, 0)) == NULL) {
1722 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1725 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1727 /* handle expander phys */
1728 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1729 return _transport_expander_phy_control(ioc, phy,
1730 (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET :
1731 SMP_PHY_CONTROL_LINK_RESET);
1733 /* handle hba phys */
1734 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
1735 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
1736 mpi_request.Operation = hard_reset ?
1737 MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET;
1738 mpi_request.PhyNum = phy->number;
1740 if ((mpt3sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
1741 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1742 __FILE__, __LINE__, __func__);
1746 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1747 ioc_info(ioc, "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1748 phy->number, le16_to_cpu(mpi_reply.IOCStatus),
1749 le32_to_cpu(mpi_reply.IOCLogInfo));
1755 * _transport_phy_enable - enable/disable phys
1756 * @phy: The sas phy object
1757 * @enable: enable phy when true
1759 * Only support sas_host direct attached phys.
1760 * Return: 0 for success, non-zero for failure.
1763 _transport_phy_enable(struct sas_phy *phy, int enable)
1765 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1766 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1767 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
1768 Mpi2ConfigReply_t mpi_reply;
1772 unsigned long flags;
1773 int i, discovery_active;
1774 struct hba_port *port = phy->hostdata;
1775 int port_id = port->port_id;
1777 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1778 if (_transport_sas_node_find_by_sas_address(ioc,
1779 phy->identify.sas_address,
1780 mpt3sas_get_port_by_id(ioc, port_id, 0)) == NULL) {
1781 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1784 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1786 /* handle expander phys */
1787 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1788 return _transport_expander_phy_control(ioc, phy,
1789 (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET :
1790 SMP_PHY_CONTROL_DISABLE);
1792 /* handle hba phys */
1794 /* read sas_iounit page 0 */
1795 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
1796 sizeof(Mpi2SasIOUnit0PhyData_t));
1797 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
1798 if (!sas_iounit_pg0) {
1799 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1800 __FILE__, __LINE__, __func__);
1804 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
1805 sas_iounit_pg0, sz))) {
1806 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1807 __FILE__, __LINE__, __func__);
1811 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1812 MPI2_IOCSTATUS_MASK;
1813 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1814 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1815 __FILE__, __LINE__, __func__);
1820 /* unable to enable/disable phys when when discovery is active */
1821 for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) {
1822 if (sas_iounit_pg0->PhyData[i].PortFlags &
1823 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
1824 ioc_err(ioc, "discovery is active on port = %d, phy = %d: unable to enable/disable phys, try again later!\n",
1825 sas_iounit_pg0->PhyData[i].Port, i);
1826 discovery_active = 1;
1830 if (discovery_active) {
1835 /* read sas_iounit page 1 */
1836 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1837 sizeof(Mpi2SasIOUnit1PhyData_t));
1838 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1839 if (!sas_iounit_pg1) {
1840 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1841 __FILE__, __LINE__, __func__);
1845 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1846 sas_iounit_pg1, sz))) {
1847 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1848 __FILE__, __LINE__, __func__);
1852 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1853 MPI2_IOCSTATUS_MASK;
1854 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1855 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1856 __FILE__, __LINE__, __func__);
1861 /* copy Port/PortFlags/PhyFlags from page 0 */
1862 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
1863 sas_iounit_pg1->PhyData[i].Port =
1864 sas_iounit_pg0->PhyData[i].Port;
1865 sas_iounit_pg1->PhyData[i].PortFlags =
1866 (sas_iounit_pg0->PhyData[i].PortFlags &
1867 MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG);
1868 sas_iounit_pg1->PhyData[i].PhyFlags =
1869 (sas_iounit_pg0->PhyData[i].PhyFlags &
1870 (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED +
1871 MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED));
1875 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1876 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1878 sas_iounit_pg1->PhyData[phy->number].PhyFlags
1879 |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1881 mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
1885 _transport_phy_reset(phy, 0);
1888 kfree(sas_iounit_pg1);
1889 kfree(sas_iounit_pg0);
1894 * _transport_phy_speed - set phy min/max link rates
1895 * @phy: The sas phy object
1896 * @rates: rates defined in sas_phy_linkrates
1898 * Only support sas_host direct attached phys.
1900 * Return: 0 for success, non-zero for failure.
1903 _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
1905 struct MPT3SAS_ADAPTER *ioc = phy_to_ioc(phy);
1906 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1907 Mpi2SasPhyPage0_t phy_pg0;
1908 Mpi2ConfigReply_t mpi_reply;
1913 unsigned long flags;
1914 struct hba_port *port = phy->hostdata;
1915 int port_id = port->port_id;
1917 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1918 if (_transport_sas_node_find_by_sas_address(ioc,
1919 phy->identify.sas_address,
1920 mpt3sas_get_port_by_id(ioc, port_id, 0)) == NULL) {
1921 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1924 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1926 if (!rates->minimum_linkrate)
1927 rates->minimum_linkrate = phy->minimum_linkrate;
1928 else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
1929 rates->minimum_linkrate = phy->minimum_linkrate_hw;
1931 if (!rates->maximum_linkrate)
1932 rates->maximum_linkrate = phy->maximum_linkrate;
1933 else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
1934 rates->maximum_linkrate = phy->maximum_linkrate_hw;
1936 /* handle expander phys */
1937 if (phy->identify.sas_address != ioc->sas_hba.sas_address) {
1938 phy->minimum_linkrate = rates->minimum_linkrate;
1939 phy->maximum_linkrate = rates->maximum_linkrate;
1940 return _transport_expander_phy_control(ioc, phy,
1941 SMP_PHY_CONTROL_LINK_RESET);
1944 /* handle hba phys */
1946 /* sas_iounit page 1 */
1947 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1948 sizeof(Mpi2SasIOUnit1PhyData_t));
1949 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1950 if (!sas_iounit_pg1) {
1951 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1952 __FILE__, __LINE__, __func__);
1956 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1957 sas_iounit_pg1, sz))) {
1958 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1959 __FILE__, __LINE__, __func__);
1963 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1964 MPI2_IOCSTATUS_MASK;
1965 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1966 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1967 __FILE__, __LINE__, __func__);
1972 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
1973 if (phy->number != i) {
1974 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1975 (ioc->sas_hba.phy[i].phy->minimum_linkrate +
1976 (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
1978 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1979 (rates->minimum_linkrate +
1980 (rates->maximum_linkrate << 4));
1984 if (mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
1986 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1987 __FILE__, __LINE__, __func__);
1993 _transport_phy_reset(phy, 0);
1995 /* read phy page 0, then update the rates in the sas transport phy */
1996 if (!mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
1998 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1999 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
2000 phy->maximum_linkrate = _transport_convert_phy_link_rate(
2001 phy_pg0.ProgrammedLinkRate >> 4);
2002 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
2003 phy_pg0.NegotiatedLinkRate &
2004 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
2008 kfree(sas_iounit_pg1);
2013 _transport_map_smp_buffer(struct device *dev, struct bsg_buffer *buf,
2014 dma_addr_t *dma_addr, size_t *dma_len, void **p)
2016 /* Check if the request is split across multiple segments */
2017 if (buf->sg_cnt > 1) {
2018 *p = dma_alloc_coherent(dev, buf->payload_len, dma_addr,
2022 *dma_len = buf->payload_len;
2024 if (!dma_map_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL))
2026 *dma_addr = sg_dma_address(buf->sg_list);
2027 *dma_len = sg_dma_len(buf->sg_list);
2035 _transport_unmap_smp_buffer(struct device *dev, struct bsg_buffer *buf,
2036 dma_addr_t dma_addr, void *p)
2039 dma_free_coherent(dev, buf->payload_len, p, dma_addr);
2041 dma_unmap_sg(dev, buf->sg_list, 1, DMA_BIDIRECTIONAL);
2045 * _transport_smp_handler - transport portal for smp passthru
2047 * @shost: shost object
2048 * @rphy: sas transport rphy object
2050 * This used primarily for smp_utils.
2052 * smp_rep_general /sys/class/bsg/expander-5:0
2055 _transport_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2056 struct sas_rphy *rphy)
2058 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2059 Mpi2SmpPassthroughRequest_t *mpi_request;
2060 Mpi2SmpPassthroughReply_t *mpi_reply;
2064 dma_addr_t dma_addr_in;
2065 dma_addr_t dma_addr_out;
2066 void *addr_in = NULL;
2067 void *addr_out = NULL;
2070 unsigned int reslen = 0;
2072 if (ioc->shost_recovery || ioc->pci_error_recovery) {
2073 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
2078 rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex);
2082 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
2083 ioc_err(ioc, "%s: transport_cmds in use\n",
2088 ioc->transport_cmds.status = MPT3_CMD_PENDING;
2090 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->request_payload,
2091 &dma_addr_out, &dma_len_out, &addr_out);
2095 sg_copy_to_buffer(job->request_payload.sg_list,
2096 job->request_payload.sg_cnt, addr_out,
2097 job->request_payload.payload_len);
2100 rc = _transport_map_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
2101 &dma_addr_in, &dma_len_in, &addr_in);
2105 rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
2109 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
2111 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
2117 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2118 ioc->transport_cmds.smid = smid;
2120 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
2121 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
2122 mpi_request->PhysicalPort = _transport_get_port_id_by_rphy(ioc, rphy);
2123 mpi_request->SASAddress = (rphy) ?
2124 cpu_to_le64(rphy->identify.sas_address) :
2125 cpu_to_le64(ioc->sas_hba.sas_address);
2126 mpi_request->RequestDataLength = cpu_to_le16(dma_len_out - 4);
2127 psge = &mpi_request->SGL;
2129 ioc->build_sg(ioc, psge, dma_addr_out, dma_len_out - 4, dma_addr_in,
2132 dtransportprintk(ioc,
2133 ioc_info(ioc, "%s: sending smp request\n", __func__));
2135 init_completion(&ioc->transport_cmds.done);
2136 ioc->put_smid_default(ioc, smid);
2137 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
2139 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
2140 ioc_err(ioc, "%s: timeout\n", __func__);
2141 _debug_dump_mf(mpi_request,
2142 sizeof(Mpi2SmpPassthroughRequest_t)/4);
2143 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET)) {
2144 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2150 dtransportprintk(ioc, ioc_info(ioc, "%s - complete\n", __func__));
2152 if (!(ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID)) {
2153 dtransportprintk(ioc,
2154 ioc_info(ioc, "%s: no reply\n", __func__));
2159 mpi_reply = ioc->transport_cmds.reply;
2161 dtransportprintk(ioc,
2162 ioc_info(ioc, "%s: reply data transfer size(%d)\n",
2164 le16_to_cpu(mpi_reply->ResponseDataLength)));
2166 memcpy(job->reply, mpi_reply, sizeof(*mpi_reply));
2167 job->reply_len = sizeof(*mpi_reply);
2168 reslen = le16_to_cpu(mpi_reply->ResponseDataLength);
2171 sg_copy_to_buffer(job->reply_payload.sg_list,
2172 job->reply_payload.sg_cnt, addr_in,
2173 job->reply_payload.payload_len);
2178 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->reply_payload,
2179 dma_addr_in, addr_in);
2181 _transport_unmap_smp_buffer(&ioc->pdev->dev, &job->request_payload,
2182 dma_addr_out, addr_out);
2184 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
2185 mutex_unlock(&ioc->transport_cmds.mutex);
2187 bsg_job_done(job, rc, reslen);
2190 struct sas_function_template mpt3sas_transport_functions = {
2191 .get_linkerrors = _transport_get_linkerrors,
2192 .get_enclosure_identifier = _transport_get_enclosure_identifier,
2193 .get_bay_identifier = _transport_get_bay_identifier,
2194 .phy_reset = _transport_phy_reset,
2195 .phy_enable = _transport_phy_enable,
2196 .set_phy_speed = _transport_phy_speed,
2197 .smp_handler = _transport_smp_handler,
2200 struct scsi_transport_template *mpt3sas_transport_template;