Skip to content

Commit ffa381d

Browse files
sreekanthbrcmmartinkpetersen
authored andcommitted
scsi: mpt3sas: Handle vSES vphy object during HBA reset
During HBA reset the Port ID of vSES device may change. As a result, it is necessary to refresh virtual_phy objects after reset. Each Port's vphy_list table needs to be updated after updating the HBA port table. The algorithm is as follows: - Loop over each port entry from HBA port table * Loop over each virtual phy entry from port's vphys_list table - Mark virtual phy entry as dirty by setting dirty bit in virtual phy entry's flags field - Read SASIOUnitPage0 page - Loop over each HBA Phy's Phy data from SASIOUnitPage0 * If phy's remote attached device is not SES device then continue with processing next HBA Phy's Phy data; * Read SASPhyPage0 data for this Phy number and determine whether current phy is a virtual phy or not. If it is not a virtual phy then continue with next Phy data; * Get the current phy's remote attached vSES device's SAS Address; * Loop over each port entry from HBA port table - If Port's vphys_mask field is zero then continue with next Port entry, - Loop over each virtual phy entry from Port's vphy_list table - If the current phy's remote SAS Address is different from virtual phy entry's SAS Address then continue with next virtual phy entry, - Set bit corresponding to current phy number in virtual phy entry's phy_mask field, - Get the HBA port table's Port entry corresponding to Phy data's 'Port' value, * If there is no Port entry corresponding to Phy data's 'Port' value in HBA port table then create a new port entry and add it to HBA port table. - If this retrieved Port entry is the same as the current Port entry then don't do anything, just clear the dirty bit from virtual phy entry's flag field and continue with processing next HBA Phy's Phy data. - If this retrieved Port entry is different from the current Port entry then move the current virtual phy entry from current Port's vphys_list to retrieved Port entry's vphys_list. * Clear current phy bit in current Port entry's vphys_mask and set the current phy bit in the retrieved Port entry's vphys_mask field. * Clear the dirty bit from virtual phy entry's flag field and continue with next HBA Phy's Phy data. - Delete the 'virtual phy' entries and HBA's 'Port table' entries which are still marked as 'dirty'. Link: https://lore.kernel.org/r/20201027130847.9962-13-sreekanth.reddy@broadcom.com Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 34b0a78 commit ffa381d

1 file changed

Lines changed: 233 additions & 0 deletions

File tree

‎drivers/scsi/mpt3sas/mpt3sas_scsih.c‎

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5847,6 +5847,204 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
58475847
return 0;
58485848
}
58495849

5850+
/**
5851+
* _scsih_update_vphys_after_reset - update the Port's
5852+
* vphys_list after reset
5853+
* @ioc: per adapter object
5854+
*
5855+
* Returns nothing.
5856+
*/
5857+
static void
5858+
_scsih_update_vphys_after_reset(struct MPT3SAS_ADAPTER *ioc)
5859+
{
5860+
u16 sz, ioc_status;
5861+
int i;
5862+
Mpi2ConfigReply_t mpi_reply;
5863+
Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5864+
u16 attached_handle;
5865+
u64 attached_sas_addr;
5866+
u8 found = 0, port_id;
5867+
Mpi2SasPhyPage0_t phy_pg0;
5868+
struct hba_port *port, *port_next, *mport;
5869+
struct virtual_phy *vphy, *vphy_next;
5870+
struct _sas_device *sas_device;
5871+
5872+
/*
5873+
* Mark all the vphys objects as dirty.
5874+
*/
5875+
list_for_each_entry_safe(port, port_next,
5876+
&ioc->port_table_list, list) {
5877+
if (!port->vphys_mask)
5878+
continue;
5879+
list_for_each_entry_safe(vphy, vphy_next,
5880+
&port->vphys_list, list) {
5881+
vphy->flags |= MPT_VPHY_FLAG_DIRTY_PHY;
5882+
}
5883+
}
5884+
5885+
/*
5886+
* Read SASIOUnitPage0 to get each HBA Phy's data.
5887+
*/
5888+
sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) +
5889+
(ioc->sas_hba.num_phys * sizeof(Mpi2SasIOUnit0PhyData_t));
5890+
sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5891+
if (!sas_iounit_pg0) {
5892+
ioc_err(ioc, "failure at %s:%d/%s()!\n",
5893+
__FILE__, __LINE__, __func__);
5894+
return;
5895+
}
5896+
if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5897+
sas_iounit_pg0, sz)) != 0)
5898+
goto out;
5899+
ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5900+
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5901+
goto out;
5902+
/*
5903+
* Loop over each HBA Phy.
5904+
*/
5905+
for (i = 0; i < ioc->sas_hba.num_phys; i++) {
5906+
/*
5907+
* Check whether Phy's Negotiation Link Rate is > 1.5G or not.
5908+
*/
5909+
if ((sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4) <
5910+
MPI2_SAS_NEG_LINK_RATE_1_5)
5911+
continue;
5912+
/*
5913+
* Check whether Phy is connected to SEP device or not,
5914+
* if it is SEP device then read the Phy's SASPHYPage0 data to
5915+
* determine whether Phy is a virtual Phy or not. if it is
5916+
* virtual phy then it is conformed that the attached remote
5917+
* device is a HBA's vSES device.
5918+
*/
5919+
if (!(le32_to_cpu(
5920+
sas_iounit_pg0->PhyData[i].ControllerPhyDeviceInfo) &
5921+
MPI2_SAS_DEVICE_INFO_SEP))
5922+
continue;
5923+
5924+
if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5925+
i))) {
5926+
ioc_err(ioc, "failure at %s:%d/%s()!\n",
5927+
__FILE__, __LINE__, __func__);
5928+
continue;
5929+
}
5930+
5931+
if (!(le32_to_cpu(phy_pg0.PhyInfo) &
5932+
MPI2_SAS_PHYINFO_VIRTUAL_PHY))
5933+
continue;
5934+
/*
5935+
* Get the vSES device's SAS Address.
5936+
*/
5937+
attached_handle = le16_to_cpu(
5938+
sas_iounit_pg0->PhyData[i].AttachedDevHandle);
5939+
if (_scsih_get_sas_address(ioc, attached_handle,
5940+
&attached_sas_addr) != 0) {
5941+
ioc_err(ioc, "failure at %s:%d/%s()!\n",
5942+
__FILE__, __LINE__, __func__);
5943+
continue;
5944+
}
5945+
5946+
found = 0;
5947+
port = port_next = NULL;
5948+
/*
5949+
* Loop over each virtual_phy object from
5950+
* each port's vphys_list.
5951+
*/
5952+
list_for_each_entry_safe(port,
5953+
port_next, &ioc->port_table_list, list) {
5954+
if (!port->vphys_mask)
5955+
continue;
5956+
list_for_each_entry_safe(vphy, vphy_next,
5957+
&port->vphys_list, list) {
5958+
/*
5959+
* Continue with next virtual_phy object
5960+
* if the object is not marked as dirty.
5961+
*/
5962+
if (!(vphy->flags & MPT_VPHY_FLAG_DIRTY_PHY))
5963+
continue;
5964+
5965+
/*
5966+
* Continue with next virtual_phy object
5967+
* if the object's SAS Address is not equals
5968+
* to current Phy's vSES device SAS Address.
5969+
*/
5970+
if (vphy->sas_address != attached_sas_addr)
5971+
continue;
5972+
/*
5973+
* Enable current Phy number bit in object's
5974+
* phy_mask field.
5975+
*/
5976+
if (!(vphy->phy_mask & (1 << i)))
5977+
vphy->phy_mask = (1 << i);
5978+
/*
5979+
* Get hba_port object from hba_port table
5980+
* corresponding to current phy's Port ID.
5981+
* if there is no hba_port object corresponding
5982+
* to Phy's Port ID then create a new hba_port
5983+
* object & add to hba_port table.
5984+
*/
5985+
port_id = sas_iounit_pg0->PhyData[i].Port;
5986+
mport = mpt3sas_get_port_by_id(ioc, port_id, 1);
5987+
if (!mport) {
5988+
mport = kzalloc(
5989+
sizeof(struct hba_port), GFP_KERNEL);
5990+
if (!mport)
5991+
break;
5992+
mport->port_id = port_id;
5993+
ioc_info(ioc,
5994+
"%s: hba_port entry: %p, port: %d is added to hba_port list\n",
5995+
__func__, mport, mport->port_id);
5996+
list_add_tail(&mport->list,
5997+
&ioc->port_table_list);
5998+
}
5999+
/*
6000+
* If mport & port pointers are not pointing to
6001+
* same hba_port object then it means that vSES
6002+
* device's Port ID got changed after reset and
6003+
* hence move current virtual_phy object from
6004+
* port's vphys_list to mport's vphys_list.
6005+
*/
6006+
if (port != mport) {
6007+
if (!mport->vphys_mask)
6008+
INIT_LIST_HEAD(
6009+
&mport->vphys_list);
6010+
mport->vphys_mask |= (1 << i);
6011+
port->vphys_mask &= ~(1 << i);
6012+
list_move(&vphy->list,
6013+
&mport->vphys_list);
6014+
sas_device = mpt3sas_get_sdev_by_addr(
6015+
ioc, attached_sas_addr, port);
6016+
if (sas_device)
6017+
sas_device->port = mport;
6018+
}
6019+
/*
6020+
* Earlier while updating the hba_port table,
6021+
* it is determined that there is no other
6022+
* direct attached device with mport's Port ID,
6023+
* Hence mport was marked as dirty. Only vSES
6024+
* device has this Port ID, so unmark the mport
6025+
* as dirt.
6026+
*/
6027+
if (mport->flags & HBA_PORT_FLAG_DIRTY_PORT) {
6028+
mport->sas_address = 0;
6029+
mport->phy_mask = 0;
6030+
mport->flags &=
6031+
~HBA_PORT_FLAG_DIRTY_PORT;
6032+
}
6033+
/*
6034+
* Unmark current virtual_phy object as dirty.
6035+
*/
6036+
vphy->flags &= ~MPT_VPHY_FLAG_DIRTY_PHY;
6037+
found = 1;
6038+
break;
6039+
}
6040+
if (found)
6041+
break;
6042+
}
6043+
}
6044+
out:
6045+
kfree(sas_iounit_pg0);
6046+
}
6047+
58506048
/**
58516049
* _scsih_get_port_table_after_reset - Construct temporary port table
58526050
* @ioc: per adapter object
@@ -6067,6 +6265,39 @@ _scsih_add_or_del_phys_from_existing_port(struct MPT3SAS_ADAPTER *ioc,
60676265
}
60686266
}
60696267

6268+
/**
6269+
* _scsih_del_dirty_vphy - delete virtual_phy objects marked as dirty.
6270+
* @ioc: per adapter object
6271+
*
6272+
* Returns nothing.
6273+
*/
6274+
static void
6275+
_scsih_del_dirty_vphy(struct MPT3SAS_ADAPTER *ioc)
6276+
{
6277+
struct hba_port *port, *port_next;
6278+
struct virtual_phy *vphy, *vphy_next;
6279+
6280+
list_for_each_entry_safe(port, port_next,
6281+
&ioc->port_table_list, list) {
6282+
if (!port->vphys_mask)
6283+
continue;
6284+
list_for_each_entry_safe(vphy, vphy_next,
6285+
&port->vphys_list, list) {
6286+
if (vphy->flags & MPT_VPHY_FLAG_DIRTY_PHY) {
6287+
drsprintk(ioc, ioc_info(ioc,
6288+
"Deleting vphy %p entry from port id: %d\t, Phy_mask 0x%08x\n",
6289+
vphy, port->port_id,
6290+
vphy->phy_mask));
6291+
port->vphys_mask &= ~vphy->phy_mask;
6292+
list_del(&vphy->list);
6293+
kfree(vphy);
6294+
}
6295+
}
6296+
if (!port->vphys_mask && !port->sas_address)
6297+
port->flags |= HBA_PORT_FLAG_DIRTY_PORT;
6298+
}
6299+
}
6300+
60706301
/**
60716302
* _scsih_del_dirty_port_entries - delete dirty port entries from port list
60726303
* after host reset
@@ -10247,6 +10478,7 @@ mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
1024710478
if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
1024810479
!ioc->sas_hba.num_phys)) {
1024910480
_scsih_sas_port_refresh(ioc);
10481+
_scsih_update_vphys_after_reset(ioc);
1025010482
_scsih_prep_device_scan(ioc);
1025110483
_scsih_create_enclosure_list_after_reset(ioc);
1025210484
_scsih_search_responding_sas_devices(ioc);
@@ -10294,6 +10526,7 @@ _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
1029410526
ssleep(1);
1029510527
}
1029610528
_scsih_remove_unresponding_devices(ioc);
10529+
_scsih_del_dirty_vphy(ioc);
1029710530
_scsih_del_dirty_port_entries(ioc);
1029810531
_scsih_scan_for_devices_after_reset(ioc);
1029910532
_scsih_set_nvme_max_shutdown_latency(ioc);

0 commit comments

Comments
 (0)