Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Scsi Host Layer for MPT (Message Passing Technology) based controllers
0003  *
0004  * Copyright (C) 2012-2014  LSI Corporation
0005  * Copyright (C) 2013-2015 Avago Technologies
0006  *  (mailto: MPT-FusionLinux.pdl@avagotech.com)
0007  *
0008  * This program is free software; you can redistribute it and/or
0009  * modify it under the terms of the GNU General Public License
0010  * as published by the Free Software Foundation; either version 2
0011  * of the License, or (at your option) any later version.
0012  *
0013  * This program is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  *
0018  * NO WARRANTY
0019  * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
0020  * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
0021  * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
0022  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
0023  * solely responsible for determining the appropriateness of using and
0024  * distributing the Program and assumes all risks associated with its
0025  * exercise of rights under this Agreement, including but not limited to
0026  * the risks and costs of program errors, damage to or loss of data,
0027  * programs or equipment, and unavailability or interruption of operations.
0028 
0029  * DISCLAIMER OF LIABILITY
0030  * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
0031  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0032  * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
0033  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
0034  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
0035  * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
0036  * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
0037 
0038  * You should have received a copy of the GNU General Public License
0039  * along with this program.
0040  */
0041 #include <linux/kernel.h>
0042 #include <linux/module.h>
0043 #include <linux/errno.h>
0044 #include <linux/types.h>
0045 #include <asm/unaligned.h>
0046 
0047 #include "mpt3sas_base.h"
0048 
0049 /**
0050  * _warpdrive_disable_ddio - Disable direct I/O for all the volumes
0051  * @ioc: per adapter object
0052  */
0053 static void
0054 _warpdrive_disable_ddio(struct MPT3SAS_ADAPTER *ioc)
0055 {
0056     Mpi2RaidVolPage1_t vol_pg1;
0057     Mpi2ConfigReply_t mpi_reply;
0058     struct _raid_device *raid_device;
0059     u16 handle;
0060     u16 ioc_status;
0061     unsigned long flags;
0062 
0063     handle = 0xFFFF;
0064     while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
0065         &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
0066         ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
0067             MPI2_IOCSTATUS_MASK;
0068         if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
0069             break;
0070         handle = le16_to_cpu(vol_pg1.DevHandle);
0071         spin_lock_irqsave(&ioc->raid_device_lock, flags);
0072         raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
0073         if (raid_device)
0074             raid_device->direct_io_enabled = 0;
0075         spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
0076     }
0077     return;
0078 }
0079 
0080 
0081 /**
0082  * mpt3sas_get_num_volumes - Get number of volumes in the ioc
0083  * @ioc: per adapter object
0084  */
0085 u8
0086 mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc)
0087 {
0088     Mpi2RaidVolPage1_t vol_pg1;
0089     Mpi2ConfigReply_t mpi_reply;
0090     u16 handle;
0091     u8 vol_cnt = 0;
0092     u16 ioc_status;
0093 
0094     handle = 0xFFFF;
0095     while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
0096         &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
0097         ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
0098             MPI2_IOCSTATUS_MASK;
0099         if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
0100             break;
0101         vol_cnt++;
0102         handle = le16_to_cpu(vol_pg1.DevHandle);
0103     }
0104     return vol_cnt;
0105 }
0106 
0107 
0108 /**
0109  * mpt3sas_init_warpdrive_properties - Set properties for warpdrive direct I/O.
0110  * @ioc: per adapter object
0111  * @raid_device: the raid_device object
0112  */
0113 void
0114 mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
0115     struct _raid_device *raid_device)
0116 {
0117     Mpi2RaidVolPage0_t *vol_pg0;
0118     Mpi2RaidPhysDiskPage0_t pd_pg0;
0119     Mpi2ConfigReply_t mpi_reply;
0120     u16 sz;
0121     u8 num_pds, count;
0122     unsigned long stripe_sz, block_sz;
0123     u8 stripe_exp, block_exp;
0124     u64 dev_max_lba;
0125 
0126     if (!ioc->is_warpdrive)
0127         return;
0128 
0129     if (ioc->mfg_pg10_hide_flag ==  MFG_PAGE10_EXPOSE_ALL_DISKS) {
0130         ioc_info(ioc, "WarpDrive : Direct IO is disabled globally as drives are exposed\n");
0131         return;
0132     }
0133     if (mpt3sas_get_num_volumes(ioc) > 1) {
0134         _warpdrive_disable_ddio(ioc);
0135         ioc_info(ioc, "WarpDrive : Direct IO is disabled globally as number of drives > 1\n");
0136         return;
0137     }
0138     if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
0139         &num_pds)) || !num_pds) {
0140         ioc_info(ioc, "WarpDrive : Direct IO is disabled Failure in computing number of drives\n");
0141         return;
0142     }
0143 
0144     sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
0145         sizeof(Mpi2RaidVol0PhysDisk_t));
0146     vol_pg0 = kzalloc(sz, GFP_KERNEL);
0147     if (!vol_pg0) {
0148         ioc_info(ioc, "WarpDrive : Direct IO is disabled Memory allocation failure for RVPG0\n");
0149         return;
0150     }
0151 
0152     if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
0153          MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
0154         ioc_info(ioc, "WarpDrive : Direct IO is disabled Failure in retrieving RVPG0\n");
0155         kfree(vol_pg0);
0156         return;
0157     }
0158 
0159     /*
0160      * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
0161      * assumed for WARPDRIVE, disable direct I/O
0162      */
0163     if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
0164         ioc_warn(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x): num_mem=%d, max_mem_allowed=%d\n",
0165              raid_device->handle, num_pds, MPT_MAX_WARPDRIVE_PDS);
0166         kfree(vol_pg0);
0167         return;
0168     }
0169     for (count = 0; count < num_pds; count++) {
0170         if (mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
0171             &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
0172             vol_pg0->PhysDisk[count].PhysDiskNum) ||
0173             le16_to_cpu(pd_pg0.DevHandle) ==
0174             MPT3SAS_INVALID_DEVICE_HANDLE) {
0175             ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) member handle retrieval failed for member number=%d\n",
0176                  raid_device->handle,
0177                  vol_pg0->PhysDisk[count].PhysDiskNum);
0178             goto out_error;
0179         }
0180         /* Disable direct I/O if member drive lba exceeds 4 bytes */
0181         dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
0182         if (dev_max_lba >> 32) {
0183             ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) member handle (0x%04x) unsupported max lba 0x%016llx\n",
0184                  raid_device->handle,
0185                  le16_to_cpu(pd_pg0.DevHandle),
0186                  (u64)dev_max_lba);
0187             goto out_error;
0188         }
0189 
0190         raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
0191     }
0192 
0193     /*
0194      * Assumption for WD: Direct I/O is not supported if the volume is
0195      * not RAID0
0196      */
0197     if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
0198         ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x): type=%d, s_sz=%uK, blk_size=%u\n",
0199              raid_device->handle, raid_device->volume_type,
0200              (le32_to_cpu(vol_pg0->StripeSize) *
0201               le16_to_cpu(vol_pg0->BlockSize)) / 1024,
0202              le16_to_cpu(vol_pg0->BlockSize));
0203         goto out_error;
0204     }
0205 
0206     stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
0207     stripe_exp = find_first_bit(&stripe_sz, 32);
0208     if (stripe_exp == 32) {
0209         ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) invalid stripe sz %uK\n",
0210              raid_device->handle,
0211              (le32_to_cpu(vol_pg0->StripeSize) *
0212               le16_to_cpu(vol_pg0->BlockSize)) / 1024);
0213         goto out_error;
0214     }
0215     raid_device->stripe_exponent = stripe_exp;
0216     block_sz = le16_to_cpu(vol_pg0->BlockSize);
0217     block_exp = find_first_bit(&block_sz, 16);
0218     if (block_exp == 16) {
0219         ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) invalid block sz %u\n",
0220              raid_device->handle, le16_to_cpu(vol_pg0->BlockSize));
0221         goto out_error;
0222     }
0223     raid_device->block_exponent = block_exp;
0224     raid_device->direct_io_enabled = 1;
0225 
0226     ioc_info(ioc, "WarpDrive : Direct IO is Enabled for the drive with handle(0x%04x)\n",
0227          raid_device->handle);
0228     /*
0229      * WARPDRIVE: Though the following fields are not used for direct IO,
0230      * stored for future purpose:
0231      */
0232     raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
0233     raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
0234     raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
0235 
0236 
0237     kfree(vol_pg0);
0238     return;
0239 
0240 out_error:
0241     raid_device->direct_io_enabled = 0;
0242     for (count = 0; count < num_pds; count++)
0243         raid_device->pd_handle[count] = 0;
0244     kfree(vol_pg0);
0245     return;
0246 }
0247 
0248 /**
0249  * mpt3sas_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
0250  * @ioc: per adapter object
0251  * @scmd: pointer to scsi command object
0252  * @raid_device: pointer to raid device data structure
0253  * @mpi_request: pointer to the SCSI_IO reqest message frame
0254  */
0255 void
0256 mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
0257     struct _raid_device *raid_device, Mpi25SCSIIORequest_t *mpi_request)
0258 {
0259     sector_t v_lba, p_lba, stripe_off, column, io_size;
0260     u32 stripe_sz, stripe_exp;
0261     u8 num_pds, cmd = scmd->cmnd[0];
0262     struct scsiio_tracker *st = scsi_cmd_priv(scmd);
0263 
0264     if (cmd != READ_10 && cmd != WRITE_10 &&
0265         cmd != READ_16 && cmd != WRITE_16)
0266         return;
0267 
0268     if (cmd == READ_10 || cmd == WRITE_10)
0269         v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
0270     else
0271         v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
0272 
0273     io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
0274 
0275     if (v_lba + io_size - 1 > raid_device->max_lba)
0276         return;
0277 
0278     stripe_sz = raid_device->stripe_sz;
0279     stripe_exp = raid_device->stripe_exponent;
0280     stripe_off = v_lba & (stripe_sz - 1);
0281 
0282     /* Return unless IO falls within a stripe */
0283     if (stripe_off + io_size > stripe_sz)
0284         return;
0285 
0286     num_pds = raid_device->num_pds;
0287     p_lba = v_lba >> stripe_exp;
0288     column = sector_div(p_lba, num_pds);
0289     p_lba = (p_lba << stripe_exp) + stripe_off;
0290     mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
0291 
0292     if (cmd == READ_10 || cmd == WRITE_10)
0293         put_unaligned_be32(lower_32_bits(p_lba),
0294                    &mpi_request->CDB.CDB32[2]);
0295     else
0296         put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
0297 
0298     st->direct_io = 1;
0299 }