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-2013 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/sched.h>
49 #include <linux/workqueue.h>
50 #include <linux/delay.h>
51 #include <linux/pci.h>
53 #include <scsi/scsi.h>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_device.h>
56 #include <scsi/scsi_host.h>
57 #include <scsi/scsi_transport_sas.h>
58 #include <scsi/scsi_dbg.h>
60 #include "mpt3sas_base.h"
63 * _transport_sas_node_find_by_sas_address - sas node search
64 * @ioc: per adapter object
65 * @sas_address: sas address of expander or sas host
66 * Context: Calling function should acquire ioc->sas_node_lock.
68 * Search for either hba phys or expander device based on handle, then returns
69 * the sas_node object.
71 static struct _sas_node
*
72 _transport_sas_node_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
75 if (ioc
->sas_hba
.sas_address
== sas_address
)
78 return mpt3sas_scsih_expander_find_by_sas_address(ioc
,
83 * _transport_convert_phy_link_rate -
84 * @link_rate: link rate returned from mpt firmware
86 * Convert link_rate from mpi fusion into sas_transport form.
88 static enum sas_linkrate
89 _transport_convert_phy_link_rate(u8 link_rate
)
94 case MPI2_SAS_NEG_LINK_RATE_1_5
:
95 rc
= SAS_LINK_RATE_1_5_GBPS
;
97 case MPI2_SAS_NEG_LINK_RATE_3_0
:
98 rc
= SAS_LINK_RATE_3_0_GBPS
;
100 case MPI2_SAS_NEG_LINK_RATE_6_0
:
101 rc
= SAS_LINK_RATE_6_0_GBPS
;
103 case MPI25_SAS_NEG_LINK_RATE_12_0
:
104 rc
= SAS_LINK_RATE_12_0_GBPS
;
106 case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED
:
107 rc
= SAS_PHY_DISABLED
;
109 case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED
:
110 rc
= SAS_LINK_RATE_FAILED
;
112 case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR
:
113 rc
= SAS_SATA_PORT_SELECTOR
;
115 case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS
:
116 rc
= SAS_PHY_RESET_IN_PROGRESS
;
120 case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE
:
121 case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE
:
122 rc
= SAS_LINK_RATE_UNKNOWN
;
129 * _transport_set_identify - set identify for phys and end devices
130 * @ioc: per adapter object
131 * @handle: device handle
132 * @identify: sas identify info
134 * Populates sas identify info.
136 * Returns 0 for success, non-zero for failure.
139 _transport_set_identify(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
140 struct sas_identify
*identify
)
142 Mpi2SasDevicePage0_t sas_device_pg0
;
143 Mpi2ConfigReply_t mpi_reply
;
147 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
148 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
149 __func__
, ioc
->name
);
153 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
154 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
155 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
156 ioc
->name
, __FILE__
, __LINE__
, __func__
);
160 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
162 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
164 "handle(0x%04x), ioc_status(0x%04x)\nfailure at %s:%d/%s()!\n",
165 ioc
->name
, handle
, ioc_status
,
166 __FILE__
, __LINE__
, __func__
);
170 memset(identify
, 0, sizeof(struct sas_identify
));
171 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
174 identify
->sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
176 /* phy number of the parent device this device is linked to */
177 identify
->phy_identifier
= sas_device_pg0
.PhyNum
;
180 switch (device_info
& MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE
) {
181 case MPI2_SAS_DEVICE_INFO_NO_DEVICE
:
182 identify
->device_type
= SAS_PHY_UNUSED
;
184 case MPI2_SAS_DEVICE_INFO_END_DEVICE
:
185 identify
->device_type
= SAS_END_DEVICE
;
187 case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
:
188 identify
->device_type
= SAS_EDGE_EXPANDER_DEVICE
;
190 case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
:
191 identify
->device_type
= SAS_FANOUT_EXPANDER_DEVICE
;
195 /* initiator_port_protocols */
196 if (device_info
& MPI2_SAS_DEVICE_INFO_SSP_INITIATOR
)
197 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SSP
;
198 if (device_info
& MPI2_SAS_DEVICE_INFO_STP_INITIATOR
)
199 identify
->initiator_port_protocols
|= SAS_PROTOCOL_STP
;
200 if (device_info
& MPI2_SAS_DEVICE_INFO_SMP_INITIATOR
)
201 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SMP
;
202 if (device_info
& MPI2_SAS_DEVICE_INFO_SATA_HOST
)
203 identify
->initiator_port_protocols
|= SAS_PROTOCOL_SATA
;
205 /* target_port_protocols */
206 if (device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
207 identify
->target_port_protocols
|= SAS_PROTOCOL_SSP
;
208 if (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
209 identify
->target_port_protocols
|= SAS_PROTOCOL_STP
;
210 if (device_info
& MPI2_SAS_DEVICE_INFO_SMP_TARGET
)
211 identify
->target_port_protocols
|= SAS_PROTOCOL_SMP
;
212 if (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
213 identify
->target_port_protocols
|= SAS_PROTOCOL_SATA
;
219 * mpt3sas_transport_done - internal transport layer callback handler.
220 * @ioc: per adapter object
221 * @smid: system request message index
222 * @msix_index: MSIX table index supplied by the OS
223 * @reply: reply message frame(lower 32bit addr)
225 * Callback handler when sending internal generated transport cmds.
226 * The callback index passed is `ioc->transport_cb_idx`
228 * Return 1 meaning mf should be freed from _base_interrupt
229 * 0 means the mf is freed from this function.
232 mpt3sas_transport_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
235 MPI2DefaultReply_t
*mpi_reply
;
237 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
238 if (ioc
->transport_cmds
.status
== MPT3_CMD_NOT_USED
)
240 if (ioc
->transport_cmds
.smid
!= smid
)
242 ioc
->transport_cmds
.status
|= MPT3_CMD_COMPLETE
;
244 memcpy(ioc
->transport_cmds
.reply
, mpi_reply
,
245 mpi_reply
->MsgLength
*4);
246 ioc
->transport_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
248 ioc
->transport_cmds
.status
&= ~MPT3_CMD_PENDING
;
249 complete(&ioc
->transport_cmds
.done
);
253 /* report manufacture request structure */
254 struct rep_manu_request
{
261 /* report manufacture reply structure */
262 struct rep_manu_reply
{
263 u8 smp_frame_type
; /* 0x41 */
264 u8 function
; /* 0x01 */
267 u16 expander_change_count
;
271 u8 vendor_id
[SAS_EXPANDER_VENDOR_ID_LEN
];
272 u8 product_id
[SAS_EXPANDER_PRODUCT_ID_LEN
];
273 u8 product_rev
[SAS_EXPANDER_PRODUCT_REV_LEN
];
274 u8 component_vendor_id
[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN
];
276 u8 component_revision_id
;
278 u8 vendor_specific
[8];
282 * transport_expander_report_manufacture - obtain SMP report_manufacture
283 * @ioc: per adapter object
284 * @sas_address: expander sas address
285 * @edev: the sas_expander_device object
287 * Fills in the sas_expander_device object when SMP port is created.
289 * Returns 0 for success, non-zero for failure.
292 _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER
*ioc
,
293 u64 sas_address
, struct sas_expander_device
*edev
)
295 Mpi2SmpPassthroughRequest_t
*mpi_request
;
296 Mpi2SmpPassthroughReply_t
*mpi_reply
;
297 struct rep_manu_reply
*manufacture_reply
;
298 struct rep_manu_request
*manufacture_request
;
302 unsigned long timeleft
;
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 timeleft
= wait_for_completion_timeout(&ioc
->transport_cmds
.done
,
399 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_COMPLETE
)) {
400 pr_err(MPT3SAS_FMT
"%s: timeout\n",
401 ioc
->name
, __func__
);
402 _debug_dump_mf(mpi_request
,
403 sizeof(Mpi2SmpPassthroughRequest_t
)/4);
404 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_RESET
))
406 goto issue_host_reset
;
409 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
410 "report_manufacture - complete\n", ioc
->name
));
412 if (ioc
->transport_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
415 mpi_reply
= ioc
->transport_cmds
.reply
;
417 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
418 "report_manufacture - reply data transfer size(%d)\n",
419 ioc
->name
, le16_to_cpu(mpi_reply
->ResponseDataLength
)));
421 if (le16_to_cpu(mpi_reply
->ResponseDataLength
) !=
422 sizeof(struct rep_manu_reply
))
425 manufacture_reply
= data_out
+ sizeof(struct rep_manu_request
);
426 strncpy(edev
->vendor_id
, manufacture_reply
->vendor_id
,
427 SAS_EXPANDER_VENDOR_ID_LEN
);
428 strncpy(edev
->product_id
, manufacture_reply
->product_id
,
429 SAS_EXPANDER_PRODUCT_ID_LEN
);
430 strncpy(edev
->product_rev
, manufacture_reply
->product_rev
,
431 SAS_EXPANDER_PRODUCT_REV_LEN
);
432 edev
->level
= manufacture_reply
->sas_format
& 1;
434 strncpy(edev
->component_vendor_id
,
435 manufacture_reply
->component_vendor_id
,
436 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN
);
437 tmp
= (u8
*)&manufacture_reply
->component_id
;
438 edev
->component_id
= tmp
[0] << 8 | tmp
[1];
439 edev
->component_revision_id
=
440 manufacture_reply
->component_revision_id
;
443 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
444 "report_manufacture - no reply\n", ioc
->name
));
448 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
451 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
453 pci_free_consistent(ioc
->pdev
, data_out_sz
+ data_in_sz
,
454 data_out
, data_out_dma
);
456 mutex_unlock(&ioc
->transport_cmds
.mutex
);
462 * _transport_delete_port - helper function to removing a port
463 * @ioc: per adapter object
464 * @mpt3sas_port: mpt3sas per port object
469 _transport_delete_port(struct MPT3SAS_ADAPTER
*ioc
,
470 struct _sas_port
*mpt3sas_port
)
472 u64 sas_address
= mpt3sas_port
->remote_identify
.sas_address
;
473 enum sas_device_type device_type
=
474 mpt3sas_port
->remote_identify
.device_type
;
476 dev_printk(KERN_INFO
, &mpt3sas_port
->port
->dev
,
477 "remove: sas_addr(0x%016llx)\n",
478 (unsigned long long) sas_address
);
480 ioc
->logging_level
|= MPT_DEBUG_TRANSPORT
;
481 if (device_type
== SAS_END_DEVICE
)
482 mpt3sas_device_remove_by_sas_address(ioc
, sas_address
);
483 else if (device_type
== SAS_EDGE_EXPANDER_DEVICE
||
484 device_type
== SAS_FANOUT_EXPANDER_DEVICE
)
485 mpt3sas_expander_remove(ioc
, sas_address
);
486 ioc
->logging_level
&= ~MPT_DEBUG_TRANSPORT
;
490 * _transport_delete_phy - helper function to removing single phy from port
491 * @ioc: per adapter object
492 * @mpt3sas_port: mpt3sas per port object
493 * @mpt3sas_phy: mpt3sas per phy object
498 _transport_delete_phy(struct MPT3SAS_ADAPTER
*ioc
,
499 struct _sas_port
*mpt3sas_port
, struct _sas_phy
*mpt3sas_phy
)
501 u64 sas_address
= mpt3sas_port
->remote_identify
.sas_address
;
503 dev_printk(KERN_INFO
, &mpt3sas_phy
->phy
->dev
,
504 "remove: sas_addr(0x%016llx), phy(%d)\n",
505 (unsigned long long) sas_address
, mpt3sas_phy
->phy_id
);
507 list_del(&mpt3sas_phy
->port_siblings
);
508 mpt3sas_port
->num_phys
--;
509 sas_port_delete_phy(mpt3sas_port
->port
, mpt3sas_phy
->phy
);
510 mpt3sas_phy
->phy_belongs_to_port
= 0;
514 * _transport_add_phy - helper function to adding single phy to port
515 * @ioc: per adapter object
516 * @mpt3sas_port: mpt3sas per port object
517 * @mpt3sas_phy: mpt3sas per phy object
522 _transport_add_phy(struct MPT3SAS_ADAPTER
*ioc
, struct _sas_port
*mpt3sas_port
,
523 struct _sas_phy
*mpt3sas_phy
)
525 u64 sas_address
= mpt3sas_port
->remote_identify
.sas_address
;
527 dev_printk(KERN_INFO
, &mpt3sas_phy
->phy
->dev
,
528 "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
529 sas_address
, mpt3sas_phy
->phy_id
);
531 list_add_tail(&mpt3sas_phy
->port_siblings
, &mpt3sas_port
->phy_list
);
532 mpt3sas_port
->num_phys
++;
533 sas_port_add_phy(mpt3sas_port
->port
, mpt3sas_phy
->phy
);
534 mpt3sas_phy
->phy_belongs_to_port
= 1;
538 * _transport_add_phy_to_an_existing_port - adding new phy to existing port
539 * @ioc: per adapter object
540 * @sas_node: sas node object (either expander or sas host)
541 * @mpt3sas_phy: mpt3sas per phy object
542 * @sas_address: sas address of device/expander were phy needs to be added to
547 _transport_add_phy_to_an_existing_port(struct MPT3SAS_ADAPTER
*ioc
,
548 struct _sas_node
*sas_node
, struct _sas_phy
*mpt3sas_phy
,
551 struct _sas_port
*mpt3sas_port
;
552 struct _sas_phy
*phy_srch
;
554 if (mpt3sas_phy
->phy_belongs_to_port
== 1)
557 list_for_each_entry(mpt3sas_port
, &sas_node
->sas_port_list
,
559 if (mpt3sas_port
->remote_identify
.sas_address
!=
562 list_for_each_entry(phy_srch
, &mpt3sas_port
->phy_list
,
564 if (phy_srch
== mpt3sas_phy
)
567 _transport_add_phy(ioc
, mpt3sas_port
, mpt3sas_phy
);
574 * _transport_del_phy_from_an_existing_port - delete phy from existing port
575 * @ioc: per adapter object
576 * @sas_node: sas node object (either expander or sas host)
577 * @mpt3sas_phy: mpt3sas per phy object
582 _transport_del_phy_from_an_existing_port(struct MPT3SAS_ADAPTER
*ioc
,
583 struct _sas_node
*sas_node
, struct _sas_phy
*mpt3sas_phy
)
585 struct _sas_port
*mpt3sas_port
, *next
;
586 struct _sas_phy
*phy_srch
;
588 if (mpt3sas_phy
->phy_belongs_to_port
== 0)
591 list_for_each_entry_safe(mpt3sas_port
, next
, &sas_node
->sas_port_list
,
593 list_for_each_entry(phy_srch
, &mpt3sas_port
->phy_list
,
595 if (phy_srch
!= mpt3sas_phy
)
598 if (mpt3sas_port
->num_phys
== 1)
599 _transport_delete_port(ioc
, mpt3sas_port
);
601 _transport_delete_phy(ioc
, mpt3sas_port
,
609 * _transport_sanity_check - sanity check when adding a new port
610 * @ioc: per adapter object
611 * @sas_node: sas node object (either expander or sas host)
612 * @sas_address: sas address of device being added
614 * See the explanation above from _transport_delete_duplicate_port
617 _transport_sanity_check(struct MPT3SAS_ADAPTER
*ioc
, struct _sas_node
*sas_node
,
622 for (i
= 0; i
< sas_node
->num_phys
; i
++) {
623 if (sas_node
->phy
[i
].remote_identify
.sas_address
!= sas_address
)
625 if (sas_node
->phy
[i
].phy_belongs_to_port
== 1)
626 _transport_del_phy_from_an_existing_port(ioc
, sas_node
,
632 * mpt3sas_transport_port_add - insert port to the list
633 * @ioc: per adapter object
634 * @handle: handle of attached device
635 * @sas_address: sas address of parent expander or sas host
636 * Context: This function will acquire ioc->sas_node_lock.
638 * Adding new port object to the sas_node->sas_port_list.
640 * Returns mpt3sas_port.
643 mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
646 struct _sas_phy
*mpt3sas_phy
, *next
;
647 struct _sas_port
*mpt3sas_port
;
649 struct _sas_node
*sas_node
;
650 struct sas_rphy
*rphy
;
652 struct sas_port
*port
;
654 mpt3sas_port
= kzalloc(sizeof(struct _sas_port
),
657 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
658 ioc
->name
, __FILE__
, __LINE__
, __func__
);
662 INIT_LIST_HEAD(&mpt3sas_port
->port_list
);
663 INIT_LIST_HEAD(&mpt3sas_port
->phy_list
);
664 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
665 sas_node
= _transport_sas_node_find_by_sas_address(ioc
, sas_address
);
666 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
670 "%s: Could not find parent sas_address(0x%016llx)!\n",
671 ioc
->name
, __func__
, (unsigned long long)sas_address
);
675 if ((_transport_set_identify(ioc
, handle
,
676 &mpt3sas_port
->remote_identify
))) {
677 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
678 ioc
->name
, __FILE__
, __LINE__
, __func__
);
682 if (mpt3sas_port
->remote_identify
.device_type
== SAS_PHY_UNUSED
) {
683 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
684 ioc
->name
, __FILE__
, __LINE__
, __func__
);
688 _transport_sanity_check(ioc
, sas_node
,
689 mpt3sas_port
->remote_identify
.sas_address
);
691 for (i
= 0; i
< sas_node
->num_phys
; i
++) {
692 if (sas_node
->phy
[i
].remote_identify
.sas_address
!=
693 mpt3sas_port
->remote_identify
.sas_address
)
695 list_add_tail(&sas_node
->phy
[i
].port_siblings
,
696 &mpt3sas_port
->phy_list
);
697 mpt3sas_port
->num_phys
++;
700 if (!mpt3sas_port
->num_phys
) {
701 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
702 ioc
->name
, __FILE__
, __LINE__
, __func__
);
706 port
= sas_port_alloc_num(sas_node
->parent_dev
);
707 if ((sas_port_add(port
))) {
708 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
709 ioc
->name
, __FILE__
, __LINE__
, __func__
);
713 list_for_each_entry(mpt3sas_phy
, &mpt3sas_port
->phy_list
,
715 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
716 dev_printk(KERN_INFO
, &port
->dev
,
717 "add: handle(0x%04x), sas_addr(0x%016llx), phy(%d)\n",
718 handle
, (unsigned long long)
719 mpt3sas_port
->remote_identify
.sas_address
,
720 mpt3sas_phy
->phy_id
);
721 sas_port_add_phy(port
, mpt3sas_phy
->phy
);
722 mpt3sas_phy
->phy_belongs_to_port
= 1;
725 mpt3sas_port
->port
= port
;
726 if (mpt3sas_port
->remote_identify
.device_type
== SAS_END_DEVICE
)
727 rphy
= sas_end_device_alloc(port
);
729 rphy
= sas_expander_alloc(port
,
730 mpt3sas_port
->remote_identify
.device_type
);
732 rphy
->identify
= mpt3sas_port
->remote_identify
;
733 if ((sas_rphy_add(rphy
))) {
734 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
735 ioc
->name
, __FILE__
, __LINE__
, __func__
);
737 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
738 dev_printk(KERN_INFO
, &rphy
->dev
,
739 "add: handle(0x%04x), sas_addr(0x%016llx)\n",
740 handle
, (unsigned long long)
741 mpt3sas_port
->remote_identify
.sas_address
);
742 mpt3sas_port
->rphy
= rphy
;
743 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
744 list_add_tail(&mpt3sas_port
->port_list
, &sas_node
->sas_port_list
);
745 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
747 /* fill in report manufacture */
748 if (mpt3sas_port
->remote_identify
.device_type
==
749 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER
||
750 mpt3sas_port
->remote_identify
.device_type
==
751 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER
)
752 _transport_expander_report_manufacture(ioc
,
753 mpt3sas_port
->remote_identify
.sas_address
,
754 rphy_to_expander_device(rphy
));
758 list_for_each_entry_safe(mpt3sas_phy
, next
, &mpt3sas_port
->phy_list
,
760 list_del(&mpt3sas_phy
->port_siblings
);
766 * mpt3sas_transport_port_remove - remove port from the list
767 * @ioc: per adapter object
768 * @sas_address: sas address of attached device
769 * @sas_address_parent: sas address of parent expander or sas host
770 * Context: This function will acquire ioc->sas_node_lock.
772 * Removing object and freeing associated memory from the
773 * ioc->sas_port_list.
778 mpt3sas_transport_port_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
779 u64 sas_address_parent
)
783 struct _sas_port
*mpt3sas_port
, *next
;
784 struct _sas_node
*sas_node
;
786 struct _sas_phy
*mpt3sas_phy
, *next_phy
;
788 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
789 sas_node
= _transport_sas_node_find_by_sas_address(ioc
,
792 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
795 list_for_each_entry_safe(mpt3sas_port
, next
, &sas_node
->sas_port_list
,
797 if (mpt3sas_port
->remote_identify
.sas_address
!= sas_address
)
800 list_del(&mpt3sas_port
->port_list
);
805 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
809 for (i
= 0; i
< sas_node
->num_phys
; i
++) {
810 if (sas_node
->phy
[i
].remote_identify
.sas_address
== sas_address
)
811 memset(&sas_node
->phy
[i
].remote_identify
, 0 ,
812 sizeof(struct sas_identify
));
815 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
817 list_for_each_entry_safe(mpt3sas_phy
, next_phy
,
818 &mpt3sas_port
->phy_list
, port_siblings
) {
819 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
820 dev_printk(KERN_INFO
, &mpt3sas_port
->port
->dev
,
821 "remove: sas_addr(0x%016llx), phy(%d)\n",
823 mpt3sas_port
->remote_identify
.sas_address
,
824 mpt3sas_phy
->phy_id
);
825 mpt3sas_phy
->phy_belongs_to_port
= 0;
826 sas_port_delete_phy(mpt3sas_port
->port
, mpt3sas_phy
->phy
);
827 list_del(&mpt3sas_phy
->port_siblings
);
829 sas_port_delete(mpt3sas_port
->port
);
834 * mpt3sas_transport_add_host_phy - report sas_host phy to transport
835 * @ioc: per adapter object
836 * @mpt3sas_phy: mpt3sas per phy object
837 * @phy_pg0: sas phy page 0
838 * @parent_dev: parent device class object
840 * Returns 0 for success, non-zero for failure.
843 mpt3sas_transport_add_host_phy(struct MPT3SAS_ADAPTER
*ioc
, struct _sas_phy
844 *mpt3sas_phy
, Mpi2SasPhyPage0_t phy_pg0
, struct device
*parent_dev
)
847 int phy_index
= mpt3sas_phy
->phy_id
;
850 INIT_LIST_HEAD(&mpt3sas_phy
->port_siblings
);
851 phy
= sas_phy_alloc(parent_dev
, phy_index
);
853 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
854 ioc
->name
, __FILE__
, __LINE__
, __func__
);
857 if ((_transport_set_identify(ioc
, mpt3sas_phy
->handle
,
858 &mpt3sas_phy
->identify
))) {
859 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
860 ioc
->name
, __FILE__
, __LINE__
, __func__
);
864 phy
->identify
= mpt3sas_phy
->identify
;
865 mpt3sas_phy
->attached_handle
= le16_to_cpu(phy_pg0
.AttachedDevHandle
);
866 if (mpt3sas_phy
->attached_handle
)
867 _transport_set_identify(ioc
, mpt3sas_phy
->attached_handle
,
868 &mpt3sas_phy
->remote_identify
);
869 phy
->identify
.phy_identifier
= mpt3sas_phy
->phy_id
;
870 phy
->negotiated_linkrate
= _transport_convert_phy_link_rate(
871 phy_pg0
.NegotiatedLinkRate
& MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL
);
872 phy
->minimum_linkrate_hw
= _transport_convert_phy_link_rate(
873 phy_pg0
.HwLinkRate
& MPI2_SAS_HWRATE_MIN_RATE_MASK
);
874 phy
->maximum_linkrate_hw
= _transport_convert_phy_link_rate(
875 phy_pg0
.HwLinkRate
>> 4);
876 phy
->minimum_linkrate
= _transport_convert_phy_link_rate(
877 phy_pg0
.ProgrammedLinkRate
& MPI2_SAS_PRATE_MIN_RATE_MASK
);
878 phy
->maximum_linkrate
= _transport_convert_phy_link_rate(
879 phy_pg0
.ProgrammedLinkRate
>> 4);
881 if ((sas_phy_add(phy
))) {
882 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
883 ioc
->name
, __FILE__
, __LINE__
, __func__
);
887 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
888 dev_printk(KERN_INFO
, &phy
->dev
,
889 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
890 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
891 mpt3sas_phy
->handle
, (unsigned long long)
892 mpt3sas_phy
->identify
.sas_address
,
893 mpt3sas_phy
->attached_handle
,
895 mpt3sas_phy
->remote_identify
.sas_address
);
896 mpt3sas_phy
->phy
= phy
;
902 * mpt3sas_transport_add_expander_phy - report expander phy to transport
903 * @ioc: per adapter object
904 * @mpt3sas_phy: mpt3sas per phy object
905 * @expander_pg1: expander page 1
906 * @parent_dev: parent device class object
908 * Returns 0 for success, non-zero for failure.
911 mpt3sas_transport_add_expander_phy(struct MPT3SAS_ADAPTER
*ioc
, struct _sas_phy
912 *mpt3sas_phy
, Mpi2ExpanderPage1_t expander_pg1
,
913 struct device
*parent_dev
)
916 int phy_index
= mpt3sas_phy
->phy_id
;
918 INIT_LIST_HEAD(&mpt3sas_phy
->port_siblings
);
919 phy
= sas_phy_alloc(parent_dev
, phy_index
);
921 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
922 ioc
->name
, __FILE__
, __LINE__
, __func__
);
925 if ((_transport_set_identify(ioc
, mpt3sas_phy
->handle
,
926 &mpt3sas_phy
->identify
))) {
927 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
928 ioc
->name
, __FILE__
, __LINE__
, __func__
);
932 phy
->identify
= mpt3sas_phy
->identify
;
933 mpt3sas_phy
->attached_handle
=
934 le16_to_cpu(expander_pg1
.AttachedDevHandle
);
935 if (mpt3sas_phy
->attached_handle
)
936 _transport_set_identify(ioc
, mpt3sas_phy
->attached_handle
,
937 &mpt3sas_phy
->remote_identify
);
938 phy
->identify
.phy_identifier
= mpt3sas_phy
->phy_id
;
939 phy
->negotiated_linkrate
= _transport_convert_phy_link_rate(
940 expander_pg1
.NegotiatedLinkRate
&
941 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL
);
942 phy
->minimum_linkrate_hw
= _transport_convert_phy_link_rate(
943 expander_pg1
.HwLinkRate
& MPI2_SAS_HWRATE_MIN_RATE_MASK
);
944 phy
->maximum_linkrate_hw
= _transport_convert_phy_link_rate(
945 expander_pg1
.HwLinkRate
>> 4);
946 phy
->minimum_linkrate
= _transport_convert_phy_link_rate(
947 expander_pg1
.ProgrammedLinkRate
& MPI2_SAS_PRATE_MIN_RATE_MASK
);
948 phy
->maximum_linkrate
= _transport_convert_phy_link_rate(
949 expander_pg1
.ProgrammedLinkRate
>> 4);
951 if ((sas_phy_add(phy
))) {
952 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
953 ioc
->name
, __FILE__
, __LINE__
, __func__
);
957 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
958 dev_printk(KERN_INFO
, &phy
->dev
,
959 "add: handle(0x%04x), sas_addr(0x%016llx)\n"
960 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
961 mpt3sas_phy
->handle
, (unsigned long long)
962 mpt3sas_phy
->identify
.sas_address
,
963 mpt3sas_phy
->attached_handle
,
965 mpt3sas_phy
->remote_identify
.sas_address
);
966 mpt3sas_phy
->phy
= phy
;
971 * mpt3sas_transport_update_links - refreshing phy link changes
972 * @ioc: per adapter object
973 * @sas_address: sas address of parent expander or sas host
974 * @handle: attached device handle
975 * @phy_numberv: phy number
976 * @link_rate: new link rate
981 mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER
*ioc
,
982 u64 sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
985 struct _sas_node
*sas_node
;
986 struct _sas_phy
*mpt3sas_phy
;
988 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
991 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
992 sas_node
= _transport_sas_node_find_by_sas_address(ioc
, sas_address
);
994 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
998 mpt3sas_phy
= &sas_node
->phy
[phy_number
];
999 mpt3sas_phy
->attached_handle
= handle
;
1000 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1001 if (handle
&& (link_rate
>= MPI2_SAS_NEG_LINK_RATE_1_5
)) {
1002 _transport_set_identify(ioc
, handle
,
1003 &mpt3sas_phy
->remote_identify
);
1004 _transport_add_phy_to_an_existing_port(ioc
, sas_node
,
1005 mpt3sas_phy
, mpt3sas_phy
->remote_identify
.sas_address
);
1007 memset(&mpt3sas_phy
->remote_identify
, 0 , sizeof(struct
1010 if (mpt3sas_phy
->phy
)
1011 mpt3sas_phy
->phy
->negotiated_linkrate
=
1012 _transport_convert_phy_link_rate(link_rate
);
1014 if ((ioc
->logging_level
& MPT_DEBUG_TRANSPORT
))
1015 dev_printk(KERN_INFO
, &mpt3sas_phy
->phy
->dev
,
1016 "refresh: parent sas_addr(0x%016llx),\n"
1017 "\tlink_rate(0x%02x), phy(%d)\n"
1018 "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
1019 (unsigned long long)sas_address
,
1020 link_rate
, phy_number
, handle
, (unsigned long long)
1021 mpt3sas_phy
->remote_identify
.sas_address
);
1024 static inline void *
1025 phy_to_ioc(struct sas_phy
*phy
)
1027 struct Scsi_Host
*shost
= dev_to_shost(phy
->dev
.parent
);
1028 return shost_priv(shost
);
1031 static inline void *
1032 rphy_to_ioc(struct sas_rphy
*rphy
)
1034 struct Scsi_Host
*shost
= dev_to_shost(rphy
->dev
.parent
->parent
);
1035 return shost_priv(shost
);
1038 /* report phy error log structure */
1039 struct phy_error_log_request
{
1040 u8 smp_frame_type
; /* 0x40 */
1041 u8 function
; /* 0x11 */
1042 u8 allocated_response_length
;
1043 u8 request_length
; /* 02 */
1049 /* report phy error log reply structure */
1050 struct phy_error_log_reply
{
1051 u8 smp_frame_type
; /* 0x41 */
1052 u8 function
; /* 0x11 */
1055 __be16 expander_change_count
;
1059 __be32 invalid_dword
;
1060 __be32 running_disparity_error
;
1061 __be32 loss_of_dword_sync
;
1062 __be32 phy_reset_problem
;
1066 * _transport_get_expander_phy_error_log - return expander counters
1067 * @ioc: per adapter object
1068 * @phy: The sas phy object
1070 * Returns 0 for success, non-zero for failure.
1074 _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER
*ioc
,
1075 struct sas_phy
*phy
)
1077 Mpi2SmpPassthroughRequest_t
*mpi_request
;
1078 Mpi2SmpPassthroughReply_t
*mpi_reply
;
1079 struct phy_error_log_request
*phy_error_log_request
;
1080 struct phy_error_log_reply
*phy_error_log_reply
;
1084 unsigned long timeleft
;
1087 void *data_out
= NULL
;
1088 dma_addr_t data_out_dma
;
1090 u16 wait_state_count
;
1092 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
1093 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
1094 __func__
, ioc
->name
);
1098 mutex_lock(&ioc
->transport_cmds
.mutex
);
1100 if (ioc
->transport_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1101 pr_err(MPT3SAS_FMT
"%s: transport_cmds in use\n",
1102 ioc
->name
, __func__
);
1106 ioc
->transport_cmds
.status
= MPT3_CMD_PENDING
;
1108 wait_state_count
= 0;
1109 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1110 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1111 if (wait_state_count
++ == 10) {
1113 "%s: failed due to ioc not operational\n",
1114 ioc
->name
, __func__
);
1119 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1121 "%s: waiting for operational state(count=%d)\n",
1122 ioc
->name
, __func__
, wait_state_count
);
1124 if (wait_state_count
)
1125 pr_info(MPT3SAS_FMT
"%s: ioc is operational\n",
1126 ioc
->name
, __func__
);
1128 smid
= mpt3sas_base_get_smid(ioc
, ioc
->transport_cb_idx
);
1130 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1131 ioc
->name
, __func__
);
1136 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1137 ioc
->transport_cmds
.smid
= smid
;
1139 sz
= sizeof(struct phy_error_log_request
) +
1140 sizeof(struct phy_error_log_reply
);
1141 data_out
= pci_alloc_consistent(ioc
->pdev
, sz
, &data_out_dma
);
1143 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
1144 __LINE__
, __func__
);
1146 mpt3sas_base_free_smid(ioc
, smid
);
1151 memset(data_out
, 0, sz
);
1152 phy_error_log_request
= data_out
;
1153 phy_error_log_request
->smp_frame_type
= 0x40;
1154 phy_error_log_request
->function
= 0x11;
1155 phy_error_log_request
->request_length
= 2;
1156 phy_error_log_request
->allocated_response_length
= 0;
1157 phy_error_log_request
->phy_identifier
= phy
->number
;
1159 memset(mpi_request
, 0, sizeof(Mpi2SmpPassthroughRequest_t
));
1160 mpi_request
->Function
= MPI2_FUNCTION_SMP_PASSTHROUGH
;
1161 mpi_request
->PhysicalPort
= 0xFF;
1162 mpi_request
->VF_ID
= 0; /* TODO */
1163 mpi_request
->VP_ID
= 0;
1164 mpi_request
->SASAddress
= cpu_to_le64(phy
->identify
.sas_address
);
1165 mpi_request
->RequestDataLength
=
1166 cpu_to_le16(sizeof(struct phy_error_log_request
));
1167 psge
= &mpi_request
->SGL
;
1169 ioc
->build_sg(ioc
, psge
, data_out_dma
,
1170 sizeof(struct phy_error_log_request
),
1171 data_out_dma
+ sizeof(struct phy_error_log_request
),
1172 sizeof(struct phy_error_log_reply
));
1174 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1175 "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1176 ioc
->name
, (unsigned long long)phy
->identify
.sas_address
,
1178 init_completion(&ioc
->transport_cmds
.done
);
1179 mpt3sas_base_put_smid_default(ioc
, smid
);
1180 timeleft
= wait_for_completion_timeout(&ioc
->transport_cmds
.done
,
1183 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1184 pr_err(MPT3SAS_FMT
"%s: timeout\n",
1185 ioc
->name
, __func__
);
1186 _debug_dump_mf(mpi_request
,
1187 sizeof(Mpi2SmpPassthroughRequest_t
)/4);
1188 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_RESET
))
1190 goto issue_host_reset
;
1193 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1194 "phy_error_log - complete\n", ioc
->name
));
1196 if (ioc
->transport_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
1198 mpi_reply
= ioc
->transport_cmds
.reply
;
1200 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1201 "phy_error_log - reply data transfer size(%d)\n",
1202 ioc
->name
, le16_to_cpu(mpi_reply
->ResponseDataLength
)));
1204 if (le16_to_cpu(mpi_reply
->ResponseDataLength
) !=
1205 sizeof(struct phy_error_log_reply
))
1208 phy_error_log_reply
= data_out
+
1209 sizeof(struct phy_error_log_request
);
1211 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1212 "phy_error_log - function_result(%d)\n",
1213 ioc
->name
, phy_error_log_reply
->function_result
));
1215 phy
->invalid_dword_count
=
1216 be32_to_cpu(phy_error_log_reply
->invalid_dword
);
1217 phy
->running_disparity_error_count
=
1218 be32_to_cpu(phy_error_log_reply
->running_disparity_error
);
1219 phy
->loss_of_dword_sync_count
=
1220 be32_to_cpu(phy_error_log_reply
->loss_of_dword_sync
);
1221 phy
->phy_reset_problem_count
=
1222 be32_to_cpu(phy_error_log_reply
->phy_reset_problem
);
1225 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1226 "phy_error_log - no reply\n", ioc
->name
));
1230 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1233 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
1235 pci_free_consistent(ioc
->pdev
, sz
, data_out
, data_out_dma
);
1237 mutex_unlock(&ioc
->transport_cmds
.mutex
);
1242 * _transport_get_linkerrors - return phy counters for both hba and expanders
1243 * @phy: The sas phy object
1245 * Returns 0 for success, non-zero for failure.
1249 _transport_get_linkerrors(struct sas_phy
*phy
)
1251 struct MPT3SAS_ADAPTER
*ioc
= phy_to_ioc(phy
);
1252 unsigned long flags
;
1253 Mpi2ConfigReply_t mpi_reply
;
1254 Mpi2SasPhyPage1_t phy_pg1
;
1256 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1257 if (_transport_sas_node_find_by_sas_address(ioc
,
1258 phy
->identify
.sas_address
) == NULL
) {
1259 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1262 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1264 if (phy
->identify
.sas_address
!= ioc
->sas_hba
.sas_address
)
1265 return _transport_get_expander_phy_error_log(ioc
, phy
);
1267 /* get hba phy error logs */
1268 if ((mpt3sas_config_get_phy_pg1(ioc
, &mpi_reply
, &phy_pg1
,
1270 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1271 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1275 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
)
1277 "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1278 ioc
->name
, phy
->number
,
1279 le16_to_cpu(mpi_reply
.IOCStatus
),
1280 le32_to_cpu(mpi_reply
.IOCLogInfo
));
1282 phy
->invalid_dword_count
= le32_to_cpu(phy_pg1
.InvalidDwordCount
);
1283 phy
->running_disparity_error_count
=
1284 le32_to_cpu(phy_pg1
.RunningDisparityErrorCount
);
1285 phy
->loss_of_dword_sync_count
=
1286 le32_to_cpu(phy_pg1
.LossDwordSynchCount
);
1287 phy
->phy_reset_problem_count
=
1288 le32_to_cpu(phy_pg1
.PhyResetProblemCount
);
1293 * _transport_get_enclosure_identifier -
1294 * @phy: The sas phy object
1296 * Obtain the enclosure logical id for an expander.
1297 * Returns 0 for success, non-zero for failure.
1300 _transport_get_enclosure_identifier(struct sas_rphy
*rphy
, u64
*identifier
)
1302 struct MPT3SAS_ADAPTER
*ioc
= rphy_to_ioc(rphy
);
1303 struct _sas_device
*sas_device
;
1304 unsigned long flags
;
1307 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1308 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1309 rphy
->identify
.sas_address
);
1311 *identifier
= sas_device
->enclosure_logical_id
;
1317 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1322 * _transport_get_bay_identifier -
1323 * @phy: The sas phy object
1325 * Returns the slot id for a device that resides inside an enclosure.
1328 _transport_get_bay_identifier(struct sas_rphy
*rphy
)
1330 struct MPT3SAS_ADAPTER
*ioc
= rphy_to_ioc(rphy
);
1331 struct _sas_device
*sas_device
;
1332 unsigned long flags
;
1335 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1336 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1337 rphy
->identify
.sas_address
);
1339 rc
= sas_device
->slot
;
1342 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1346 /* phy control request structure */
1347 struct phy_control_request
{
1348 u8 smp_frame_type
; /* 0x40 */
1349 u8 function
; /* 0x91 */
1350 u8 allocated_response_length
;
1351 u8 request_length
; /* 0x09 */
1352 u16 expander_change_count
;
1357 u64 attached_device_name
;
1358 u8 programmed_min_physical_link_rate
;
1359 u8 programmed_max_physical_link_rate
;
1363 /* phy control reply structure */
1364 struct phy_control_reply
{
1365 u8 smp_frame_type
; /* 0x41 */
1366 u8 function
; /* 0x11 */
1371 #define SMP_PHY_CONTROL_LINK_RESET (0x01)
1372 #define SMP_PHY_CONTROL_HARD_RESET (0x02)
1373 #define SMP_PHY_CONTROL_DISABLE (0x03)
1376 * _transport_expander_phy_control - expander phy control
1377 * @ioc: per adapter object
1378 * @phy: The sas phy object
1380 * Returns 0 for success, non-zero for failure.
1384 _transport_expander_phy_control(struct MPT3SAS_ADAPTER
*ioc
,
1385 struct sas_phy
*phy
, u8 phy_operation
)
1387 Mpi2SmpPassthroughRequest_t
*mpi_request
;
1388 Mpi2SmpPassthroughReply_t
*mpi_reply
;
1389 struct phy_control_request
*phy_control_request
;
1390 struct phy_control_reply
*phy_control_reply
;
1394 unsigned long timeleft
;
1398 void *data_out
= NULL
;
1399 dma_addr_t data_out_dma
;
1401 u16 wait_state_count
;
1403 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
1404 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
1405 __func__
, ioc
->name
);
1409 mutex_lock(&ioc
->transport_cmds
.mutex
);
1411 if (ioc
->transport_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1412 pr_err(MPT3SAS_FMT
"%s: transport_cmds in use\n",
1413 ioc
->name
, __func__
);
1417 ioc
->transport_cmds
.status
= MPT3_CMD_PENDING
;
1419 wait_state_count
= 0;
1420 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1421 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1422 if (wait_state_count
++ == 10) {
1424 "%s: failed due to ioc not operational\n",
1425 ioc
->name
, __func__
);
1430 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1432 "%s: waiting for operational state(count=%d)\n",
1433 ioc
->name
, __func__
, wait_state_count
);
1435 if (wait_state_count
)
1436 pr_info(MPT3SAS_FMT
"%s: ioc is operational\n",
1437 ioc
->name
, __func__
);
1439 smid
= mpt3sas_base_get_smid(ioc
, ioc
->transport_cb_idx
);
1441 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1442 ioc
->name
, __func__
);
1447 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1448 ioc
->transport_cmds
.smid
= smid
;
1450 sz
= sizeof(struct phy_control_request
) +
1451 sizeof(struct phy_control_reply
);
1452 data_out
= pci_alloc_consistent(ioc
->pdev
, sz
, &data_out_dma
);
1454 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
1455 __LINE__
, __func__
);
1457 mpt3sas_base_free_smid(ioc
, smid
);
1462 memset(data_out
, 0, sz
);
1463 phy_control_request
= data_out
;
1464 phy_control_request
->smp_frame_type
= 0x40;
1465 phy_control_request
->function
= 0x91;
1466 phy_control_request
->request_length
= 9;
1467 phy_control_request
->allocated_response_length
= 0;
1468 phy_control_request
->phy_identifier
= phy
->number
;
1469 phy_control_request
->phy_operation
= phy_operation
;
1470 phy_control_request
->programmed_min_physical_link_rate
=
1471 phy
->minimum_linkrate
<< 4;
1472 phy_control_request
->programmed_max_physical_link_rate
=
1473 phy
->maximum_linkrate
<< 4;
1475 memset(mpi_request
, 0, sizeof(Mpi2SmpPassthroughRequest_t
));
1476 mpi_request
->Function
= MPI2_FUNCTION_SMP_PASSTHROUGH
;
1477 mpi_request
->PhysicalPort
= 0xFF;
1478 mpi_request
->VF_ID
= 0; /* TODO */
1479 mpi_request
->VP_ID
= 0;
1480 mpi_request
->SASAddress
= cpu_to_le64(phy
->identify
.sas_address
);
1481 mpi_request
->RequestDataLength
=
1482 cpu_to_le16(sizeof(struct phy_error_log_request
));
1483 psge
= &mpi_request
->SGL
;
1485 /* WRITE sgel first */
1486 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1487 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1488 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1489 ioc
->base_add_sg_single(psge
, sgl_flags
|
1490 sizeof(struct phy_control_request
), data_out_dma
);
1493 psge
+= ioc
->sge_size
;
1495 /* READ sgel last */
1496 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1497 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1498 MPI2_SGE_FLAGS_END_OF_LIST
);
1499 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1500 ioc
->base_add_sg_single(psge
, sgl_flags
|
1501 sizeof(struct phy_control_reply
), data_out_dma
+
1502 sizeof(struct phy_control_request
));
1504 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1505 "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1506 ioc
->name
, (unsigned long long)phy
->identify
.sas_address
,
1507 phy
->number
, phy_operation
));
1508 init_completion(&ioc
->transport_cmds
.done
);
1509 mpt3sas_base_put_smid_default(ioc
, smid
);
1510 timeleft
= wait_for_completion_timeout(&ioc
->transport_cmds
.done
,
1513 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1514 pr_err(MPT3SAS_FMT
"%s: timeout\n",
1515 ioc
->name
, __func__
);
1516 _debug_dump_mf(mpi_request
,
1517 sizeof(Mpi2SmpPassthroughRequest_t
)/4);
1518 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_RESET
))
1520 goto issue_host_reset
;
1523 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1524 "phy_control - complete\n", ioc
->name
));
1526 if (ioc
->transport_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
1528 mpi_reply
= ioc
->transport_cmds
.reply
;
1530 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1531 "phy_control - reply data transfer size(%d)\n",
1532 ioc
->name
, le16_to_cpu(mpi_reply
->ResponseDataLength
)));
1534 if (le16_to_cpu(mpi_reply
->ResponseDataLength
) !=
1535 sizeof(struct phy_control_reply
))
1538 phy_control_reply
= data_out
+
1539 sizeof(struct phy_control_request
);
1541 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1542 "phy_control - function_result(%d)\n",
1543 ioc
->name
, phy_control_reply
->function_result
));
1547 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
1548 "phy_control - no reply\n", ioc
->name
));
1552 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1555 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
1557 pci_free_consistent(ioc
->pdev
, sz
, data_out
, data_out_dma
);
1559 mutex_unlock(&ioc
->transport_cmds
.mutex
);
1564 * _transport_phy_reset -
1565 * @phy: The sas phy object
1568 * Returns 0 for success, non-zero for failure.
1571 _transport_phy_reset(struct sas_phy
*phy
, int hard_reset
)
1573 struct MPT3SAS_ADAPTER
*ioc
= phy_to_ioc(phy
);
1574 Mpi2SasIoUnitControlReply_t mpi_reply
;
1575 Mpi2SasIoUnitControlRequest_t mpi_request
;
1576 unsigned long flags
;
1578 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1579 if (_transport_sas_node_find_by_sas_address(ioc
,
1580 phy
->identify
.sas_address
) == NULL
) {
1581 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1584 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1586 /* handle expander phys */
1587 if (phy
->identify
.sas_address
!= ioc
->sas_hba
.sas_address
)
1588 return _transport_expander_phy_control(ioc
, phy
,
1589 (hard_reset
== 1) ? SMP_PHY_CONTROL_HARD_RESET
:
1590 SMP_PHY_CONTROL_LINK_RESET
);
1592 /* handle hba phys */
1593 memset(&mpi_request
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
1594 mpi_request
.Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
1595 mpi_request
.Operation
= hard_reset
?
1596 MPI2_SAS_OP_PHY_HARD_RESET
: MPI2_SAS_OP_PHY_LINK_RESET
;
1597 mpi_request
.PhyNum
= phy
->number
;
1599 if ((mpt3sas_base_sas_iounit_control(ioc
, &mpi_reply
, &mpi_request
))) {
1600 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1601 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1605 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
)
1607 "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1608 ioc
->name
, phy
->number
, le16_to_cpu(mpi_reply
.IOCStatus
),
1609 le32_to_cpu(mpi_reply
.IOCLogInfo
));
1615 * _transport_phy_enable - enable/disable phys
1616 * @phy: The sas phy object
1617 * @enable: enable phy when true
1619 * Only support sas_host direct attached phys.
1620 * Returns 0 for success, non-zero for failure.
1623 _transport_phy_enable(struct sas_phy
*phy
, int enable
)
1625 struct MPT3SAS_ADAPTER
*ioc
= phy_to_ioc(phy
);
1626 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
1627 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
1628 Mpi2ConfigReply_t mpi_reply
;
1632 unsigned long flags
;
1633 int i
, discovery_active
;
1635 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1636 if (_transport_sas_node_find_by_sas_address(ioc
,
1637 phy
->identify
.sas_address
) == NULL
) {
1638 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1641 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1643 /* handle expander phys */
1644 if (phy
->identify
.sas_address
!= ioc
->sas_hba
.sas_address
)
1645 return _transport_expander_phy_control(ioc
, phy
,
1646 (enable
== 1) ? SMP_PHY_CONTROL_LINK_RESET
:
1647 SMP_PHY_CONTROL_DISABLE
);
1649 /* handle hba phys */
1651 /* read sas_iounit page 0 */
1652 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
1653 sizeof(Mpi2SasIOUnit0PhyData_t
));
1654 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
1655 if (!sas_iounit_pg0
) {
1656 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1657 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1661 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
1662 sas_iounit_pg0
, sz
))) {
1663 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1664 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1668 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1669 MPI2_IOCSTATUS_MASK
;
1670 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1671 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1672 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1677 /* unable to enable/disable phys when when discovery is active */
1678 for (i
= 0, discovery_active
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
1679 if (sas_iounit_pg0
->PhyData
[i
].PortFlags
&
1680 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS
) {
1681 pr_err(MPT3SAS_FMT
"discovery is active on " \
1682 "port = %d, phy = %d: unable to enable/disable "
1683 "phys, try again later!\n", ioc
->name
,
1684 sas_iounit_pg0
->PhyData
[i
].Port
, i
);
1685 discovery_active
= 1;
1689 if (discovery_active
) {
1694 /* read sas_iounit page 1 */
1695 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
1696 sizeof(Mpi2SasIOUnit1PhyData_t
));
1697 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
1698 if (!sas_iounit_pg1
) {
1699 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1700 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1704 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
1705 sas_iounit_pg1
, sz
))) {
1706 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1707 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1711 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1712 MPI2_IOCSTATUS_MASK
;
1713 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1714 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1715 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1720 /* copy Port/PortFlags/PhyFlags from page 0 */
1721 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
1722 sas_iounit_pg1
->PhyData
[i
].Port
=
1723 sas_iounit_pg0
->PhyData
[i
].Port
;
1724 sas_iounit_pg1
->PhyData
[i
].PortFlags
=
1725 (sas_iounit_pg0
->PhyData
[i
].PortFlags
&
1726 MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG
);
1727 sas_iounit_pg1
->PhyData
[i
].PhyFlags
=
1728 (sas_iounit_pg0
->PhyData
[i
].PhyFlags
&
1729 (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED
+
1730 MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED
));
1734 sas_iounit_pg1
->PhyData
[phy
->number
].PhyFlags
1735 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE
;
1737 sas_iounit_pg1
->PhyData
[phy
->number
].PhyFlags
1738 |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE
;
1740 mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
, sz
);
1744 _transport_phy_reset(phy
, 0);
1747 kfree(sas_iounit_pg1
);
1748 kfree(sas_iounit_pg0
);
1753 * _transport_phy_speed - set phy min/max link rates
1754 * @phy: The sas phy object
1755 * @rates: rates defined in sas_phy_linkrates
1757 * Only support sas_host direct attached phys.
1758 * Returns 0 for success, non-zero for failure.
1761 _transport_phy_speed(struct sas_phy
*phy
, struct sas_phy_linkrates
*rates
)
1763 struct MPT3SAS_ADAPTER
*ioc
= phy_to_ioc(phy
);
1764 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
1765 Mpi2SasPhyPage0_t phy_pg0
;
1766 Mpi2ConfigReply_t mpi_reply
;
1771 unsigned long flags
;
1773 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1774 if (_transport_sas_node_find_by_sas_address(ioc
,
1775 phy
->identify
.sas_address
) == NULL
) {
1776 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1779 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1781 if (!rates
->minimum_linkrate
)
1782 rates
->minimum_linkrate
= phy
->minimum_linkrate
;
1783 else if (rates
->minimum_linkrate
< phy
->minimum_linkrate_hw
)
1784 rates
->minimum_linkrate
= phy
->minimum_linkrate_hw
;
1786 if (!rates
->maximum_linkrate
)
1787 rates
->maximum_linkrate
= phy
->maximum_linkrate
;
1788 else if (rates
->maximum_linkrate
> phy
->maximum_linkrate_hw
)
1789 rates
->maximum_linkrate
= phy
->maximum_linkrate_hw
;
1791 /* handle expander phys */
1792 if (phy
->identify
.sas_address
!= ioc
->sas_hba
.sas_address
) {
1793 phy
->minimum_linkrate
= rates
->minimum_linkrate
;
1794 phy
->maximum_linkrate
= rates
->maximum_linkrate
;
1795 return _transport_expander_phy_control(ioc
, phy
,
1796 SMP_PHY_CONTROL_LINK_RESET
);
1799 /* handle hba phys */
1801 /* sas_iounit page 1 */
1802 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
1803 sizeof(Mpi2SasIOUnit1PhyData_t
));
1804 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
1805 if (!sas_iounit_pg1
) {
1806 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1807 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1811 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
1812 sas_iounit_pg1
, sz
))) {
1813 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1814 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1818 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1819 MPI2_IOCSTATUS_MASK
;
1820 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1821 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1822 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1827 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
1828 if (phy
->number
!= i
) {
1829 sas_iounit_pg1
->PhyData
[i
].MaxMinLinkRate
=
1830 (ioc
->sas_hba
.phy
[i
].phy
->minimum_linkrate
+
1831 (ioc
->sas_hba
.phy
[i
].phy
->maximum_linkrate
<< 4));
1833 sas_iounit_pg1
->PhyData
[i
].MaxMinLinkRate
=
1834 (rates
->minimum_linkrate
+
1835 (rates
->maximum_linkrate
<< 4));
1839 if (mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
1841 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1842 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1848 _transport_phy_reset(phy
, 0);
1850 /* read phy page 0, then update the rates in the sas transport phy */
1851 if (!mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
1853 phy
->minimum_linkrate
= _transport_convert_phy_link_rate(
1854 phy_pg0
.ProgrammedLinkRate
& MPI2_SAS_PRATE_MIN_RATE_MASK
);
1855 phy
->maximum_linkrate
= _transport_convert_phy_link_rate(
1856 phy_pg0
.ProgrammedLinkRate
>> 4);
1857 phy
->negotiated_linkrate
= _transport_convert_phy_link_rate(
1858 phy_pg0
.NegotiatedLinkRate
&
1859 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL
);
1863 kfree(sas_iounit_pg1
);
1868 * _transport_smp_handler - transport portal for smp passthru
1869 * @shost: shost object
1870 * @rphy: sas transport rphy object
1873 * This used primarily for smp_utils.
1875 * smp_rep_general /sys/class/bsg/expander-5:0
1878 _transport_smp_handler(struct Scsi_Host
*shost
, struct sas_rphy
*rphy
,
1879 struct request
*req
)
1881 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1882 Mpi2SmpPassthroughRequest_t
*mpi_request
;
1883 Mpi2SmpPassthroughReply_t
*mpi_reply
;
1887 unsigned long timeleft
;
1890 dma_addr_t dma_addr_in
= 0;
1891 dma_addr_t dma_addr_out
= 0;
1892 dma_addr_t pci_dma_in
= 0;
1893 dma_addr_t pci_dma_out
= 0;
1894 void *pci_addr_in
= NULL
;
1895 void *pci_addr_out
= NULL
;
1896 u16 wait_state_count
;
1897 struct request
*rsp
= req
->next_rq
;
1898 struct bio_vec
*bvec
= NULL
;
1901 pr_err(MPT3SAS_FMT
"%s: the smp response space is missing\n",
1902 ioc
->name
, __func__
);
1906 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
1907 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
1908 __func__
, ioc
->name
);
1912 rc
= mutex_lock_interruptible(&ioc
->transport_cmds
.mutex
);
1916 if (ioc
->transport_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1917 pr_err(MPT3SAS_FMT
"%s: transport_cmds in use\n", ioc
->name
,
1922 ioc
->transport_cmds
.status
= MPT3_CMD_PENDING
;
1924 /* Check if the request is split across multiple segments */
1925 if (req
->bio
->bi_vcnt
> 1) {
1928 /* Allocate memory and copy the request */
1929 pci_addr_out
= pci_alloc_consistent(ioc
->pdev
,
1930 blk_rq_bytes(req
), &pci_dma_out
);
1931 if (!pci_addr_out
) {
1932 pr_info(MPT3SAS_FMT
"%s(): PCI Addr out = NULL\n",
1933 ioc
->name
, __func__
);
1938 bio_for_each_segment(bvec
, req
->bio
, i
) {
1939 memcpy(pci_addr_out
+ offset
,
1940 page_address(bvec
->bv_page
) + bvec
->bv_offset
,
1942 offset
+= bvec
->bv_len
;
1945 dma_addr_out
= pci_map_single(ioc
->pdev
, bio_data(req
->bio
),
1946 blk_rq_bytes(req
), PCI_DMA_BIDIRECTIONAL
);
1947 if (!dma_addr_out
) {
1948 pr_info(MPT3SAS_FMT
"%s(): DMA Addr out = NULL\n",
1949 ioc
->name
, __func__
);
1955 /* Check if the response needs to be populated across
1956 * multiple segments */
1957 if (rsp
->bio
->bi_vcnt
> 1) {
1958 pci_addr_in
= pci_alloc_consistent(ioc
->pdev
, blk_rq_bytes(rsp
),
1961 pr_info(MPT3SAS_FMT
"%s(): PCI Addr in = NULL\n",
1962 ioc
->name
, __func__
);
1967 dma_addr_in
= pci_map_single(ioc
->pdev
, bio_data(rsp
->bio
),
1968 blk_rq_bytes(rsp
), PCI_DMA_BIDIRECTIONAL
);
1970 pr_info(MPT3SAS_FMT
"%s(): DMA Addr in = NULL\n",
1971 ioc
->name
, __func__
);
1977 wait_state_count
= 0;
1978 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1979 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1980 if (wait_state_count
++ == 10) {
1982 "%s: failed due to ioc not operational\n",
1983 ioc
->name
, __func__
);
1988 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1990 "%s: waiting for operational state(count=%d)\n",
1991 ioc
->name
, __func__
, wait_state_count
);
1993 if (wait_state_count
)
1994 pr_info(MPT3SAS_FMT
"%s: ioc is operational\n",
1995 ioc
->name
, __func__
);
1997 smid
= mpt3sas_base_get_smid(ioc
, ioc
->transport_cb_idx
);
1999 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2000 ioc
->name
, __func__
);
2006 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2007 ioc
->transport_cmds
.smid
= smid
;
2009 memset(mpi_request
, 0, sizeof(Mpi2SmpPassthroughRequest_t
));
2010 mpi_request
->Function
= MPI2_FUNCTION_SMP_PASSTHROUGH
;
2011 mpi_request
->PhysicalPort
= 0xFF;
2012 mpi_request
->SASAddress
= (rphy
) ?
2013 cpu_to_le64(rphy
->identify
.sas_address
) :
2014 cpu_to_le64(ioc
->sas_hba
.sas_address
);
2015 mpi_request
->RequestDataLength
= cpu_to_le16(blk_rq_bytes(req
) - 4);
2016 psge
= &mpi_request
->SGL
;
2018 if (req
->bio
->bi_vcnt
> 1)
2019 ioc
->build_sg(ioc
, psge
, pci_dma_out
, (blk_rq_bytes(req
) - 4),
2020 pci_dma_in
, (blk_rq_bytes(rsp
) + 4));
2022 ioc
->build_sg(ioc
, psge
, dma_addr_out
, (blk_rq_bytes(req
) - 4),
2023 dma_addr_in
, (blk_rq_bytes(rsp
) + 4));
2025 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
2026 "%s - sending smp request\n", ioc
->name
, __func__
));
2028 init_completion(&ioc
->transport_cmds
.done
);
2029 mpt3sas_base_put_smid_default(ioc
, smid
);
2030 timeleft
= wait_for_completion_timeout(&ioc
->transport_cmds
.done
,
2033 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2034 pr_err(MPT3SAS_FMT
"%s : timeout\n",
2035 __func__
, ioc
->name
);
2036 _debug_dump_mf(mpi_request
,
2037 sizeof(Mpi2SmpPassthroughRequest_t
)/4);
2038 if (!(ioc
->transport_cmds
.status
& MPT3_CMD_RESET
))
2040 goto issue_host_reset
;
2043 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
2044 "%s - complete\n", ioc
->name
, __func__
));
2046 if (ioc
->transport_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2048 mpi_reply
= ioc
->transport_cmds
.reply
;
2050 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
2051 "%s - reply data transfer size(%d)\n",
2052 ioc
->name
, __func__
,
2053 le16_to_cpu(mpi_reply
->ResponseDataLength
)));
2055 memcpy(req
->sense
, mpi_reply
, sizeof(*mpi_reply
));
2056 req
->sense_len
= sizeof(*mpi_reply
);
2059 le16_to_cpu(mpi_reply
->ResponseDataLength
);
2061 /* check if the resp needs to be copied from the allocated
2063 if (rsp
->bio
->bi_vcnt
> 1) {
2066 le16_to_cpu(mpi_reply
->ResponseDataLength
);
2067 bio_for_each_segment(bvec
, rsp
->bio
, i
) {
2068 if (bytes_to_copy
<= bvec
->bv_len
) {
2069 memcpy(page_address(bvec
->bv_page
) +
2070 bvec
->bv_offset
, pci_addr_in
+
2071 offset
, bytes_to_copy
);
2074 memcpy(page_address(bvec
->bv_page
) +
2075 bvec
->bv_offset
, pci_addr_in
+
2076 offset
, bvec
->bv_len
);
2077 bytes_to_copy
-= bvec
->bv_len
;
2079 offset
+= bvec
->bv_len
;
2083 dtransportprintk(ioc
, pr_info(MPT3SAS_FMT
2084 "%s - no reply\n", ioc
->name
, __func__
));
2090 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2097 pci_unmap_single(ioc
->pdev
, dma_addr_out
, blk_rq_bytes(req
),
2098 PCI_DMA_BIDIRECTIONAL
);
2100 pci_unmap_single(ioc
->pdev
, dma_addr_in
, blk_rq_bytes(rsp
),
2101 PCI_DMA_BIDIRECTIONAL
);
2105 pci_free_consistent(ioc
->pdev
, blk_rq_bytes(req
), pci_addr_out
,
2109 pci_free_consistent(ioc
->pdev
, blk_rq_bytes(rsp
), pci_addr_in
,
2113 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
2114 mutex_unlock(&ioc
->transport_cmds
.mutex
);
2118 struct sas_function_template mpt3sas_transport_functions
= {
2119 .get_linkerrors
= _transport_get_linkerrors
,
2120 .get_enclosure_identifier
= _transport_get_enclosure_identifier
,
2121 .get_bay_identifier
= _transport_get_bay_identifier
,
2122 .phy_reset
= _transport_phy_reset
,
2123 .phy_enable
= _transport_phy_enable
,
2124 .set_phy_speed
= _transport_phy_speed
,
2125 .smp_handler
= _transport_smp_handler
,
2128 struct scsi_transport_template
*mpt3sas_transport_template
;