drivers/scsi/pmcraid.c:3350:48: sparse: incorrect type in argument 2 (different address spaces)

From: kbuild test robot
Date: Mon May 08 2017 - 20:33:47 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 2d3e4866dea96b0506395b47bfefb234f2088dac
commit: beba3a20bf90ce1b93e24592c3ebf0d0bb581bbe x86: switch to RAW_COPY_USER
date: 6 weeks ago
reproduce:
# apt-get install sparse
git checkout beba3a20bf90ce1b93e24592c3ebf0d0bb581bbe
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

drivers/scsi/pmcraid.c:163:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:163:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:163:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:163:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:163:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:178:57: sparse: restricted __le16 degrades to integer
drivers/scsi/pmcraid.c:333:41: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:333:41: left side has type restricted __le64
drivers/scsi/pmcraid.c:333:41: right side has type unsigned long long
drivers/scsi/pmcraid.c:348:29: sparse: Using plain integer as NULL pointer
drivers/scsi/pmcraid.c:901:19: sparse: cast to restricted __le32
drivers/scsi/pmcraid.c:901:19: sparse: cast from restricted __le64
drivers/scsi/pmcraid.c:5727:30: sparse: incorrect type in initializer (different base types)
drivers/scsi/pmcraid.c:5727:30: expected int [signed] cfg_table_size
drivers/scsi/pmcraid.c:5727:30: got restricted __be32 [usertype] <noident>
drivers/scsi/pmcraid.c:5729:13: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:5729:13: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:5729:13: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:5729:13: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:5729:13: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:5729:13: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:5729:13: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:5729:13: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:5752:33: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:5752:33: left side has type restricted __le64
drivers/scsi/pmcraid.c:5752:33: right side has type unsigned long long
drivers/scsi/pmcraid.c:1054:33: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:1054:33: left side has type restricted __le64
drivers/scsi/pmcraid.c:1054:33: right side has type unsigned long long
drivers/scsi/pmcraid.c:1080:25: sparse: incorrect type in initializer (different base types)
drivers/scsi/pmcraid.c:1080:25: expected unsigned int [unsigned] [usertype] hrrq_size
drivers/scsi/pmcraid.c:1080:25: got restricted __be32 [usertype] <noident>
drivers/scsi/pmcraid.c:1205:26: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:1205:26: expected restricted __le64 [usertype] address
drivers/scsi/pmcraid.c:1205:26: got restricted __le32 [usertype] <noident>
drivers/scsi/pmcraid.c:1240:59: sparse: incorrect type in initializer (different base types)
drivers/scsi/pmcraid.c:1240:59: expected restricted __be64 [usertype] ioarcb_addr
drivers/scsi/pmcraid.c:1240:59: got restricted __le64 [usertype] ioarcb_bus_addr
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: incorrect type in argument 1 (different base types)
drivers/scsi/pmcraid.c:1254:23: expected unsigned long long [unsigned] [usertype] val
drivers/scsi/pmcraid.c:1254:23: got restricted __be64 [usertype] ioarcb_addr
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1254:23: sparse: cast from restricted __be64
drivers/scsi/pmcraid.c:1496:52: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:1511:52: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:1555:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:1555:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:1555:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:1555:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:1555:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:1555:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:1555:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:1555:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:1557:9: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:1557:9: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:1557:9: sparse: restricted __le16 degrades to integer
drivers/scsi/pmcraid.c:1661:57: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:1661:57: left side has type restricted __le16
drivers/scsi/pmcraid.c:1661:57: right side has type int
drivers/scsi/pmcraid.c:1717:9: sparse: cast to restricted __le32
drivers/scsi/pmcraid.c:5555:19: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:5555:19: expected restricted __le64 [usertype] timestamp
drivers/scsi/pmcraid.c:5555:19: got signed long long
drivers/scsi/pmcraid.c:5557:52: sparse: cast from restricted __le64
drivers/scsi/pmcraid.c:5558:59: sparse: restricted __le64 degrades to integer
drivers/scsi/pmcraid.c:5559:59: sparse: restricted __le64 degrades to integer
drivers/scsi/pmcraid.c:5560:59: sparse: restricted __le64 degrades to integer
drivers/scsi/pmcraid.c:5561:59: sparse: restricted __le64 degrades to integer
drivers/scsi/pmcraid.c:5562:59: sparse: restricted __le64 degrades to integer
drivers/scsi/pmcraid.c:5575:33: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:5575:33: left side has type restricted __le64
drivers/scsi/pmcraid.c:5575:33: right side has type unsigned long long
drivers/scsi/pmcraid.c:2036:41: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:2036:41: expected restricted __le32 [usertype] ilid
drivers/scsi/pmcraid.c:2036:41: got restricted __be32 [usertype] <noident>
drivers/scsi/pmcraid.c:2532:33: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:2532:33: left side has type restricted __le64
drivers/scsi/pmcraid.c:2532:33: right side has type unsigned long long
drivers/scsi/pmcraid.c:2695:48: sparse: incorrect type in initializer (different base types)
drivers/scsi/pmcraid.c:2695:48: expected short [signed] sense_len
drivers/scsi/pmcraid.c:2695:48: got restricted __le16 [usertype] auto_sense_length
drivers/scsi/pmcraid.c:2696:41: sparse: cast to restricted __le16
drivers/scsi/pmcraid.c:2916:9: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:3143:31: sparse: restricted __le16 degrades to integer
drivers/scsi/pmcraid.c:3144:30: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:3144:30: expected restricted __le32 [usertype] ioadl_length
drivers/scsi/pmcraid.c:3144:30: got unsigned long
drivers/scsi/pmcraid.c:3153:41: sparse: invalid assignment: &=
drivers/scsi/pmcraid.c:3153:41: left side has type restricted __le64
drivers/scsi/pmcraid.c:3153:41: right side has type unsigned long long
drivers/scsi/pmcraid.c:3166:41: sparse: invalid assignment: |=
drivers/scsi/pmcraid.c:3166:41: left side has type restricted __le64
drivers/scsi/pmcraid.c:3166:41: right side has type int
>> drivers/scsi/pmcraid.c:3350:48: sparse: incorrect type in argument 2 (different address spaces)
drivers/scsi/pmcraid.c:3350:48: expected void const [noderef] <asn:1>*from
drivers/scsi/pmcraid.c:3350:48: got void *<noident>
>> drivers/scsi/pmcraid.c:3353:46: sparse: incorrect type in argument 1 (different address spaces)
drivers/scsi/pmcraid.c:3353:46: expected void [noderef] <asn:1>*to
drivers/scsi/pmcraid.c:3353:46: got void *<noident>
drivers/scsi/pmcraid.c:3372:48: sparse: incorrect type in argument 2 (different address spaces)
drivers/scsi/pmcraid.c:3372:48: expected void const [noderef] <asn:1>*from
drivers/scsi/pmcraid.c:3372:48: got void *<noident>
drivers/scsi/pmcraid.c:3375:46: sparse: incorrect type in argument 1 (different address spaces)
drivers/scsi/pmcraid.c:3375:46: expected void [noderef] <asn:1>*to
drivers/scsi/pmcraid.c:3375:46: got void *<noident>
drivers/scsi/pmcraid.c:3420:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:3420:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:3420:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:3420:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:3420:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:3420:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:3420:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:3420:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:3491:9: sparse: restricted __le16 degrades to integer
>> drivers/scsi/pmcraid.c:3705:31: sparse: incorrect type in argument 2 (different address spaces)
drivers/scsi/pmcraid.c:3705:31: expected void const [noderef] <asn:1>*from
drivers/scsi/pmcraid.c:3705:31: got struct pmcraid_passthrough_ioctl_buffer *<noident>
drivers/scsi/pmcraid.c:3718:22: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:3718:22: expected int [signed] request_size
drivers/scsi/pmcraid.c:3718:22: got restricted __le32 [usertype] data_transfer_length
drivers/scsi/pmcraid.c:3729:22: sparse: incorrect type in argument 1 (different base types)
drivers/scsi/pmcraid.c:3729:22: expected void const volatile [noderef] <asn:1>*<noident>
drivers/scsi/pmcraid.c:3729:22: got unsigned long [unsigned] arg
drivers/scsi/pmcraid.c:3741:27: sparse: restricted __le16 degrades to integer
drivers/scsi/pmcraid.c:3773:39: sparse: incorrect type in argument 3 (different base types)
drivers/scsi/pmcraid.c:3773:39: expected unsigned long [unsigned] [usertype] len
drivers/scsi/pmcraid.c:3773:39: got restricted __le16 [usertype] add_cmd_param_length
drivers/scsi/pmcraid.c:3843:56: sparse: restricted __le16 degrades to integer
drivers/scsi/pmcraid.c:3845:17: sparse: restricted __le32 degrades to integer
drivers/scsi/pmcraid.c:3845:17: sparse: cast to restricted __le32
drivers/scsi/pmcraid.c:3855:31: sparse: incorrect type in assignment (different base types)
drivers/scsi/pmcraid.c:3855:31: expected unsigned int [unsigned] [usertype] ioasc
drivers/scsi/pmcraid.c:3855:31: got restricted __le32 [usertype] ioasc
drivers/scsi/pmcraid.c:3889:26: sparse: incorrect type in argument 1 (different address spaces)
drivers/scsi/pmcraid.c:3889:26: expected void [noderef] <asn:1>*to
drivers/scsi/pmcraid.c:3889:26: got void *[assigned] ioasa
include/linux/uaccess.h:168:18: sparse: incorrect type in argument 1 (different modifiers)
include/linux/uaccess.h:168:18: expected void *<noident>
include/linux/uaccess.h:168:18: got void const *from
drivers/scsi/pmcraid.c:4033:51: sparse: incorrect type in argument 2 (different address spaces)
drivers/scsi/pmcraid.c:4033:51: expected void [noderef] <asn:1>*arg
drivers/scsi/pmcraid.c:4033:51: got void *<noident>
drivers/scsi/pmcraid.c:4423:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:4423:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:4423:22: sparse: cast to restricted __be16
drivers/scsi/pmcraid.c:4423:22: sparse: cast from restricted __le16
drivers/scsi/pmcraid.c:4423:22: sparse: too many warnings
--
>> kernel/trace/trace_kprobe.c:216:64: sparse: incorrect type in argument 2 (different address spaces)
kernel/trace/trace_kprobe.c:216:64: expected void const [noderef] <asn:1>*from
kernel/trace/trace_kprobe.c:216:64: got unsigned char [usertype] *

vim +3350 drivers/scsi/pmcraid.c

89a36810 Anil Ravindranath 2009-08-25 3147 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) {
89a36810 Anil Ravindranath 2009-08-25 3148 /* external ioadls start at offset 0x80 from control_block
89a36810 Anil Ravindranath 2009-08-25 3149 * structure, re-using 24 out of 27 ioadls part of IOARCB.
89a36810 Anil Ravindranath 2009-08-25 3150 * It is necessary to indicate to firmware that driver is
89a36810 Anil Ravindranath 2009-08-25 3151 * using ioadls to be treated as external to IOARCB.
89a36810 Anil Ravindranath 2009-08-25 3152 */
89a36810 Anil Ravindranath 2009-08-25 @3153 ioarcb->ioarcb_bus_addr &= ~(0x1FULL);
89a36810 Anil Ravindranath 2009-08-25 3154 ioarcb->ioadl_bus_addr =
89a36810 Anil Ravindranath 2009-08-25 3155 cpu_to_le64((cmd->ioa_cb_bus_addr) +
89a36810 Anil Ravindranath 2009-08-25 3156 offsetof(struct pmcraid_ioarcb,
89a36810 Anil Ravindranath 2009-08-25 3157 add_data.u.ioadl[3]));
89a36810 Anil Ravindranath 2009-08-25 3158 ioadl = &ioarcb->add_data.u.ioadl[3];
89a36810 Anil Ravindranath 2009-08-25 3159 } else {
89a36810 Anil Ravindranath 2009-08-25 3160 ioarcb->ioadl_bus_addr =
89a36810 Anil Ravindranath 2009-08-25 3161 cpu_to_le64((cmd->ioa_cb_bus_addr) +
89a36810 Anil Ravindranath 2009-08-25 3162 offsetof(struct pmcraid_ioarcb,
89a36810 Anil Ravindranath 2009-08-25 3163 add_data.u.ioadl[ioadl_count]));
89a36810 Anil Ravindranath 2009-08-25 3164
89a36810 Anil Ravindranath 2009-08-25 3165 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count];
89a36810 Anil Ravindranath 2009-08-25 3166 ioarcb->ioarcb_bus_addr |=
89a36810 Anil Ravindranath 2009-08-25 3167 DIV_ROUND_CLOSEST(sgcount + ioadl_count, 8);
89a36810 Anil Ravindranath 2009-08-25 3168 }
89a36810 Anil Ravindranath 2009-08-25 3169
89a36810 Anil Ravindranath 2009-08-25 3170 return ioadl;
89a36810 Anil Ravindranath 2009-08-25 3171 }
89a36810 Anil Ravindranath 2009-08-25 3172
89a36810 Anil Ravindranath 2009-08-25 3173 /**
89a36810 Anil Ravindranath 2009-08-25 3174 * pmcraid_build_ioadl - Build a scatter/gather list and map the buffer
89a36810 Anil Ravindranath 2009-08-25 3175 * @pinstance: pointer to adapter instance structure
89a36810 Anil Ravindranath 2009-08-25 3176 * @cmd: pmcraid command struct
89a36810 Anil Ravindranath 2009-08-25 3177 *
89a36810 Anil Ravindranath 2009-08-25 3178 * This function is invoked by queuecommand entry point while sending a command
89a36810 Anil Ravindranath 2009-08-25 3179 * to firmware. This builds ioadl descriptors and sets up ioarcb fields.
89a36810 Anil Ravindranath 2009-08-25 3180 *
89a36810 Anil Ravindranath 2009-08-25 3181 * Return value:
89a36810 Anil Ravindranath 2009-08-25 3182 * 0 on success or -1 on failure
89a36810 Anil Ravindranath 2009-08-25 3183 */
89a36810 Anil Ravindranath 2009-08-25 3184 static int pmcraid_build_ioadl(
89a36810 Anil Ravindranath 2009-08-25 3185 struct pmcraid_instance *pinstance,
89a36810 Anil Ravindranath 2009-08-25 3186 struct pmcraid_cmd *cmd
89a36810 Anil Ravindranath 2009-08-25 3187 )
89a36810 Anil Ravindranath 2009-08-25 3188 {
89a36810 Anil Ravindranath 2009-08-25 3189 int i, nseg;
89a36810 Anil Ravindranath 2009-08-25 3190 struct scatterlist *sglist;
89a36810 Anil Ravindranath 2009-08-25 3191
89a36810 Anil Ravindranath 2009-08-25 3192 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd;
89a36810 Anil Ravindranath 2009-08-25 3193 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb);
89a36810 Anil Ravindranath 2009-08-25 3194 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
89a36810 Anil Ravindranath 2009-08-25 3195
89a36810 Anil Ravindranath 2009-08-25 3196 u32 length = scsi_bufflen(scsi_cmd);
89a36810 Anil Ravindranath 2009-08-25 3197
89a36810 Anil Ravindranath 2009-08-25 3198 if (!length)
89a36810 Anil Ravindranath 2009-08-25 3199 return 0;
89a36810 Anil Ravindranath 2009-08-25 3200
89a36810 Anil Ravindranath 2009-08-25 3201 nseg = scsi_dma_map(scsi_cmd);
89a36810 Anil Ravindranath 2009-08-25 3202
89a36810 Anil Ravindranath 2009-08-25 3203 if (nseg < 0) {
34876402 Anil Ravindranath 2009-09-09 3204 scmd_printk(KERN_ERR, scsi_cmd, "scsi_map_dma failed!\n");
89a36810 Anil Ravindranath 2009-08-25 3205 return -1;
89a36810 Anil Ravindranath 2009-08-25 3206 } else if (nseg > PMCRAID_MAX_IOADLS) {
89a36810 Anil Ravindranath 2009-08-25 3207 scsi_dma_unmap(scsi_cmd);
34876402 Anil Ravindranath 2009-09-09 3208 scmd_printk(KERN_ERR, scsi_cmd,
89a36810 Anil Ravindranath 2009-08-25 3209 "sg count is (%d) more than allowed!\n", nseg);
89a36810 Anil Ravindranath 2009-08-25 3210 return -1;
89a36810 Anil Ravindranath 2009-08-25 3211 }
89a36810 Anil Ravindranath 2009-08-25 3212
89a36810 Anil Ravindranath 2009-08-25 3213 /* Initialize IOARCB data transfer length fields */
89a36810 Anil Ravindranath 2009-08-25 3214 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE)
89a36810 Anil Ravindranath 2009-08-25 3215 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE;
89a36810 Anil Ravindranath 2009-08-25 3216
89a36810 Anil Ravindranath 2009-08-25 3217 ioarcb->request_flags0 |= NO_LINK_DESCS;
89a36810 Anil Ravindranath 2009-08-25 3218 ioarcb->data_transfer_length = cpu_to_le32(length);
89a36810 Anil Ravindranath 2009-08-25 3219 ioadl = pmcraid_init_ioadls(cmd, nseg);
89a36810 Anil Ravindranath 2009-08-25 3220
89a36810 Anil Ravindranath 2009-08-25 3221 /* Initialize IOADL descriptor addresses */
89a36810 Anil Ravindranath 2009-08-25 3222 scsi_for_each_sg(scsi_cmd, sglist, nseg, i) {
89a36810 Anil Ravindranath 2009-08-25 3223 ioadl[i].data_len = cpu_to_le32(sg_dma_len(sglist));
89a36810 Anil Ravindranath 2009-08-25 3224 ioadl[i].address = cpu_to_le64(sg_dma_address(sglist));
89a36810 Anil Ravindranath 2009-08-25 3225 ioadl[i].flags = 0;
89a36810 Anil Ravindranath 2009-08-25 3226 }
89a36810 Anil Ravindranath 2009-08-25 3227 /* setup last descriptor */
88197966 Anil Ravindranath 2009-09-24 3228 ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC;
89a36810 Anil Ravindranath 2009-08-25 3229
89a36810 Anil Ravindranath 2009-08-25 3230 return 0;
89a36810 Anil Ravindranath 2009-08-25 3231 }
89a36810 Anil Ravindranath 2009-08-25 3232
89a36810 Anil Ravindranath 2009-08-25 3233 /**
89a36810 Anil Ravindranath 2009-08-25 3234 * pmcraid_free_sglist - Frees an allocated SG buffer list
89a36810 Anil Ravindranath 2009-08-25 3235 * @sglist: scatter/gather list pointer
89a36810 Anil Ravindranath 2009-08-25 3236 *
89a36810 Anil Ravindranath 2009-08-25 3237 * Free a DMA'able memory previously allocated with pmcraid_alloc_sglist
89a36810 Anil Ravindranath 2009-08-25 3238 *
89a36810 Anil Ravindranath 2009-08-25 3239 * Return value:
89a36810 Anil Ravindranath 2009-08-25 3240 * none
89a36810 Anil Ravindranath 2009-08-25 3241 */
89a36810 Anil Ravindranath 2009-08-25 3242 static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
89a36810 Anil Ravindranath 2009-08-25 3243 {
89a36810 Anil Ravindranath 2009-08-25 3244 int i;
89a36810 Anil Ravindranath 2009-08-25 3245
89a36810 Anil Ravindranath 2009-08-25 3246 for (i = 0; i < sglist->num_sg; i++)
89a36810 Anil Ravindranath 2009-08-25 3247 __free_pages(sg_page(&(sglist->scatterlist[i])),
89a36810 Anil Ravindranath 2009-08-25 3248 sglist->order);
89a36810 Anil Ravindranath 2009-08-25 3249
89a36810 Anil Ravindranath 2009-08-25 3250 kfree(sglist);
89a36810 Anil Ravindranath 2009-08-25 3251 }
89a36810 Anil Ravindranath 2009-08-25 3252
89a36810 Anil Ravindranath 2009-08-25 3253 /**
89a36810 Anil Ravindranath 2009-08-25 3254 * pmcraid_alloc_sglist - Allocates memory for a SG list
89a36810 Anil Ravindranath 2009-08-25 3255 * @buflen: buffer length
89a36810 Anil Ravindranath 2009-08-25 3256 *
89a36810 Anil Ravindranath 2009-08-25 3257 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
89a36810 Anil Ravindranath 2009-08-25 3258 * list.
89a36810 Anil Ravindranath 2009-08-25 3259 *
89a36810 Anil Ravindranath 2009-08-25 3260 * Return value
89a36810 Anil Ravindranath 2009-08-25 3261 * pointer to sglist / NULL on failure
89a36810 Anil Ravindranath 2009-08-25 3262 */
89a36810 Anil Ravindranath 2009-08-25 3263 static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
89a36810 Anil Ravindranath 2009-08-25 3264 {
89a36810 Anil Ravindranath 2009-08-25 3265 struct pmcraid_sglist *sglist;
89a36810 Anil Ravindranath 2009-08-25 3266 struct scatterlist *scatterlist;
89a36810 Anil Ravindranath 2009-08-25 3267 struct page *page;
89a36810 Anil Ravindranath 2009-08-25 3268 int num_elem, i, j;
89a36810 Anil Ravindranath 2009-08-25 3269 int sg_size;
89a36810 Anil Ravindranath 2009-08-25 3270 int order;
89a36810 Anil Ravindranath 2009-08-25 3271 int bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3272
89a36810 Anil Ravindranath 2009-08-25 3273 sg_size = buflen / (PMCRAID_MAX_IOADLS - 1);
89a36810 Anil Ravindranath 2009-08-25 3274 order = (sg_size > 0) ? get_order(sg_size) : 0;
89a36810 Anil Ravindranath 2009-08-25 3275 bsize_elem = PAGE_SIZE * (1 << order);
89a36810 Anil Ravindranath 2009-08-25 3276
89a36810 Anil Ravindranath 2009-08-25 3277 /* Determine the actual number of sg entries needed */
89a36810 Anil Ravindranath 2009-08-25 3278 if (buflen % bsize_elem)
89a36810 Anil Ravindranath 2009-08-25 3279 num_elem = (buflen / bsize_elem) + 1;
89a36810 Anil Ravindranath 2009-08-25 3280 else
89a36810 Anil Ravindranath 2009-08-25 3281 num_elem = buflen / bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3282
89a36810 Anil Ravindranath 2009-08-25 3283 /* Allocate a scatter/gather list for the DMA */
89a36810 Anil Ravindranath 2009-08-25 3284 sglist = kzalloc(sizeof(struct pmcraid_sglist) +
89a36810 Anil Ravindranath 2009-08-25 3285 (sizeof(struct scatterlist) * (num_elem - 1)),
89a36810 Anil Ravindranath 2009-08-25 3286 GFP_KERNEL);
89a36810 Anil Ravindranath 2009-08-25 3287
89a36810 Anil Ravindranath 2009-08-25 3288 if (sglist == NULL)
89a36810 Anil Ravindranath 2009-08-25 3289 return NULL;
89a36810 Anil Ravindranath 2009-08-25 3290
89a36810 Anil Ravindranath 2009-08-25 3291 scatterlist = sglist->scatterlist;
89a36810 Anil Ravindranath 2009-08-25 3292 sg_init_table(scatterlist, num_elem);
89a36810 Anil Ravindranath 2009-08-25 3293 sglist->order = order;
89a36810 Anil Ravindranath 2009-08-25 3294 sglist->num_sg = num_elem;
89a36810 Anil Ravindranath 2009-08-25 3295 sg_size = buflen;
89a36810 Anil Ravindranath 2009-08-25 3296
89a36810 Anil Ravindranath 2009-08-25 3297 for (i = 0; i < num_elem; i++) {
592488a3 Anil Ravindranath 2010-10-13 3298 page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order);
89a36810 Anil Ravindranath 2009-08-25 3299 if (!page) {
89a36810 Anil Ravindranath 2009-08-25 3300 for (j = i - 1; j >= 0; j--)
89a36810 Anil Ravindranath 2009-08-25 3301 __free_pages(sg_page(&scatterlist[j]), order);
89a36810 Anil Ravindranath 2009-08-25 3302 kfree(sglist);
89a36810 Anil Ravindranath 2009-08-25 3303 return NULL;
89a36810 Anil Ravindranath 2009-08-25 3304 }
89a36810 Anil Ravindranath 2009-08-25 3305
89a36810 Anil Ravindranath 2009-08-25 3306 sg_set_page(&scatterlist[i], page,
89a36810 Anil Ravindranath 2009-08-25 3307 sg_size < bsize_elem ? sg_size : bsize_elem, 0);
89a36810 Anil Ravindranath 2009-08-25 3308 sg_size -= bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3309 }
89a36810 Anil Ravindranath 2009-08-25 3310
89a36810 Anil Ravindranath 2009-08-25 3311 return sglist;
89a36810 Anil Ravindranath 2009-08-25 3312 }
89a36810 Anil Ravindranath 2009-08-25 3313
89a36810 Anil Ravindranath 2009-08-25 3314 /**
89a36810 Anil Ravindranath 2009-08-25 3315 * pmcraid_copy_sglist - Copy user buffer to kernel buffer's SG list
89a36810 Anil Ravindranath 2009-08-25 3316 * @sglist: scatter/gather list pointer
89a36810 Anil Ravindranath 2009-08-25 3317 * @buffer: buffer pointer
89a36810 Anil Ravindranath 2009-08-25 3318 * @len: buffer length
89a36810 Anil Ravindranath 2009-08-25 3319 * @direction: data transfer direction
89a36810 Anil Ravindranath 2009-08-25 3320 *
89a36810 Anil Ravindranath 2009-08-25 3321 * Copy a user buffer into a buffer allocated by pmcraid_alloc_sglist
89a36810 Anil Ravindranath 2009-08-25 3322 *
89a36810 Anil Ravindranath 2009-08-25 3323 * Return value:
89a36810 Anil Ravindranath 2009-08-25 3324 * 0 on success / other on failure
89a36810 Anil Ravindranath 2009-08-25 3325 */
89a36810 Anil Ravindranath 2009-08-25 3326 static int pmcraid_copy_sglist(
89a36810 Anil Ravindranath 2009-08-25 3327 struct pmcraid_sglist *sglist,
89a36810 Anil Ravindranath 2009-08-25 3328 unsigned long buffer,
89a36810 Anil Ravindranath 2009-08-25 3329 u32 len,
89a36810 Anil Ravindranath 2009-08-25 3330 int direction
89a36810 Anil Ravindranath 2009-08-25 3331 )
89a36810 Anil Ravindranath 2009-08-25 3332 {
89a36810 Anil Ravindranath 2009-08-25 3333 struct scatterlist *scatterlist;
89a36810 Anil Ravindranath 2009-08-25 3334 void *kaddr;
89a36810 Anil Ravindranath 2009-08-25 3335 int bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3336 int i;
89a36810 Anil Ravindranath 2009-08-25 3337 int rc = 0;
89a36810 Anil Ravindranath 2009-08-25 3338
89a36810 Anil Ravindranath 2009-08-25 3339 /* Determine the actual number of bytes per element */
89a36810 Anil Ravindranath 2009-08-25 3340 bsize_elem = PAGE_SIZE * (1 << sglist->order);
89a36810 Anil Ravindranath 2009-08-25 3341
89a36810 Anil Ravindranath 2009-08-25 3342 scatterlist = sglist->scatterlist;
89a36810 Anil Ravindranath 2009-08-25 3343
89a36810 Anil Ravindranath 2009-08-25 3344 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
89a36810 Anil Ravindranath 2009-08-25 3345 struct page *page = sg_page(&scatterlist[i]);
89a36810 Anil Ravindranath 2009-08-25 3346
89a36810 Anil Ravindranath 2009-08-25 3347 kaddr = kmap(page);
89a36810 Anil Ravindranath 2009-08-25 3348 if (direction == DMA_TO_DEVICE)
89a36810 Anil Ravindranath 2009-08-25 3349 rc = __copy_from_user(kaddr,
89a36810 Anil Ravindranath 2009-08-25 @3350 (void *)buffer,
89a36810 Anil Ravindranath 2009-08-25 3351 bsize_elem);
89a36810 Anil Ravindranath 2009-08-25 3352 else
89a36810 Anil Ravindranath 2009-08-25 @3353 rc = __copy_to_user((void *)buffer, kaddr, bsize_elem);
89a36810 Anil Ravindranath 2009-08-25 3354
89a36810 Anil Ravindranath 2009-08-25 3355 kunmap(page);
89a36810 Anil Ravindranath 2009-08-25 3356
89a36810 Anil Ravindranath 2009-08-25 3357 if (rc) {
89a36810 Anil Ravindranath 2009-08-25 3358 pmcraid_err("failed to copy user data into sg list\n");
89a36810 Anil Ravindranath 2009-08-25 3359 return -EFAULT;
89a36810 Anil Ravindranath 2009-08-25 3360 }
89a36810 Anil Ravindranath 2009-08-25 3361
89a36810 Anil Ravindranath 2009-08-25 3362 scatterlist[i].length = bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3363 }
89a36810 Anil Ravindranath 2009-08-25 3364
89a36810 Anil Ravindranath 2009-08-25 3365 if (len % bsize_elem) {
89a36810 Anil Ravindranath 2009-08-25 3366 struct page *page = sg_page(&scatterlist[i]);
89a36810 Anil Ravindranath 2009-08-25 3367
89a36810 Anil Ravindranath 2009-08-25 3368 kaddr = kmap(page);
89a36810 Anil Ravindranath 2009-08-25 3369
89a36810 Anil Ravindranath 2009-08-25 3370 if (direction == DMA_TO_DEVICE)
89a36810 Anil Ravindranath 2009-08-25 3371 rc = __copy_from_user(kaddr,
89a36810 Anil Ravindranath 2009-08-25 3372 (void *)buffer,
89a36810 Anil Ravindranath 2009-08-25 3373 len % bsize_elem);
89a36810 Anil Ravindranath 2009-08-25 3374 else
89a36810 Anil Ravindranath 2009-08-25 3375 rc = __copy_to_user((void *)buffer,
89a36810 Anil Ravindranath 2009-08-25 3376 kaddr,
89a36810 Anil Ravindranath 2009-08-25 3377 len % bsize_elem);
89a36810 Anil Ravindranath 2009-08-25 3378
89a36810 Anil Ravindranath 2009-08-25 3379 kunmap(page);
89a36810 Anil Ravindranath 2009-08-25 3380
89a36810 Anil Ravindranath 2009-08-25 3381 scatterlist[i].length = len % bsize_elem;
89a36810 Anil Ravindranath 2009-08-25 3382 }
89a36810 Anil Ravindranath 2009-08-25 3383
89a36810 Anil Ravindranath 2009-08-25 3384 if (rc) {
89a36810 Anil Ravindranath 2009-08-25 3385 pmcraid_err("failed to copy user data into sg list\n");
89a36810 Anil Ravindranath 2009-08-25 3386 rc = -EFAULT;
89a36810 Anil Ravindranath 2009-08-25 3387 }
89a36810 Anil Ravindranath 2009-08-25 3388
89a36810 Anil Ravindranath 2009-08-25 3389 return rc;
89a36810 Anil Ravindranath 2009-08-25 3390 }
89a36810 Anil Ravindranath 2009-08-25 3391
89a36810 Anil Ravindranath 2009-08-25 3392 /**
89a36810 Anil Ravindranath 2009-08-25 3393 * pmcraid_queuecommand - Queue a mid-layer request
89a36810 Anil Ravindranath 2009-08-25 3394 * @scsi_cmd: scsi command struct
89a36810 Anil Ravindranath 2009-08-25 3395 * @done: done function
89a36810 Anil Ravindranath 2009-08-25 3396 *
89a36810 Anil Ravindranath 2009-08-25 3397 * This function queues a request generated by the mid-layer. Midlayer calls
89a36810 Anil Ravindranath 2009-08-25 3398 * this routine within host->lock. Some of the functions called by queuecommand
89a36810 Anil Ravindranath 2009-08-25 3399 * would use cmd block queue locks (free_pool_lock and pending_pool_lock)
89a36810 Anil Ravindranath 2009-08-25 3400 *
89a36810 Anil Ravindranath 2009-08-25 3401 * Return value:
89a36810 Anil Ravindranath 2009-08-25 3402 * 0 on success
89a36810 Anil Ravindranath 2009-08-25 3403 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
89a36810 Anil Ravindranath 2009-08-25 3404 * SCSI_MLQUEUE_HOST_BUSY if host is busy
89a36810 Anil Ravindranath 2009-08-25 3405 */
f281233d Jeff Garzik 2010-11-16 3406 static int pmcraid_queuecommand_lck(
89a36810 Anil Ravindranath 2009-08-25 3407 struct scsi_cmnd *scsi_cmd,
89a36810 Anil Ravindranath 2009-08-25 3408 void (*done) (struct scsi_cmnd *)
89a36810 Anil Ravindranath 2009-08-25 3409 )
89a36810 Anil Ravindranath 2009-08-25 3410 {
89a36810 Anil Ravindranath 2009-08-25 3411 struct pmcraid_instance *pinstance;
89a36810 Anil Ravindranath 2009-08-25 3412 struct pmcraid_resource_entry *res;
89a36810 Anil Ravindranath 2009-08-25 3413 struct pmcraid_ioarcb *ioarcb;
89a36810 Anil Ravindranath 2009-08-25 3414 struct pmcraid_cmd *cmd;
c20c4267 Anil Ravindranath 2010-06-08 3415 u32 fw_version;
89a36810 Anil Ravindranath 2009-08-25 3416 int rc = 0;
89a36810 Anil Ravindranath 2009-08-25 3417
89a36810 Anil Ravindranath 2009-08-25 3418 pinstance =
89a36810 Anil Ravindranath 2009-08-25 3419 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata;
c20c4267 Anil Ravindranath 2010-06-08 @3420 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
89a36810 Anil Ravindranath 2009-08-25 3421 scsi_cmd->scsi_done = done;
89a36810 Anil Ravindranath 2009-08-25 3422 res = scsi_cmd->device->hostdata;
89a36810 Anil Ravindranath 2009-08-25 3423 scsi_cmd->result = (DID_OK << 16);

:::::: The code at line 3350 was first introduced by commit
:::::: 89a3681041507773dfee1b88c1c90c8a811a79d3 [SCSI] pmcraid: PMC-Sierra MaxRAID driver to support 6Gb/s SAS RAID controller

:::::: TO: Anil Ravindranath <anil_ravindranath@xxxxxxxxxxxxxx>
:::::: CC: James Bottomley <James.Bottomley@xxxxxxx>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation