hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/pmcraid.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * pmcraid.c -- driver for PMC Sierra MaxRAID controller adapters
34 *
....@@ -5,22 +6,6 @@
56 * PMC-Sierra Inc
67 *
78 * Copyright (C) 2008, 2009 PMC Sierra Inc
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
22
- * USA
23
- *
249 */
2510 #include <linux/fs.h>
2611 #include <linux/init.h>
....@@ -846,16 +831,9 @@
846831 cmd->ioa_cb->ioarcb.cdb[0], ioasc);
847832 }
848833
849
- /* if we had allocated sense buffers for request sense, copy the sense
850
- * release the buffers
851
- */
852
- if (cmd->sense_buffer != NULL) {
853
- memcpy(scsi_cmd->sense_buffer,
854
- cmd->sense_buffer,
855
- SCSI_SENSE_BUFFERSIZE);
856
- pci_free_consistent(pinstance->pdev,
857
- SCSI_SENSE_BUFFERSIZE,
858
- cmd->sense_buffer, cmd->sense_buffer_dma);
834
+ if (cmd->sense_buffer) {
835
+ dma_unmap_single(&pinstance->pdev->dev, cmd->sense_buffer_dma,
836
+ SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
859837 cmd->sense_buffer = NULL;
860838 cmd->sense_buffer_dma = 0;
861839 }
....@@ -2444,13 +2422,12 @@
24442422 {
24452423 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
24462424 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
2425
+ struct device *dev = &cmd->drv_inst->pdev->dev;
24472426
2448
- /* allocate DMAable memory for sense buffers */
2449
- cmd->sense_buffer = pci_alloc_consistent(cmd->drv_inst->pdev,
2450
- SCSI_SENSE_BUFFERSIZE,
2451
- &cmd->sense_buffer_dma);
2452
-
2453
- if (cmd->sense_buffer == NULL) {
2427
+ cmd->sense_buffer = cmd->scsi_cmd->sense_buffer;
2428
+ cmd->sense_buffer_dma = dma_map_single(dev, cmd->sense_buffer,
2429
+ SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
2430
+ if (dma_mapping_error(dev, cmd->sense_buffer_dma)) {
24542431 pmcraid_err
24552432 ("couldn't allocate sense buffer for request sense\n");
24562433 pmcraid_erp_done(cmd);
....@@ -2491,17 +2468,15 @@
24912468 /**
24922469 * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error recovery
24932470 * @cmd: command that failed
2494
- * @sense: true if request_sense is required after cancel all
2471
+ * @need_sense: true if request_sense is required after cancel all
24952472 *
24962473 * This function sends a cancel all to a device to clear the queue.
24972474 */
2498
-static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, u32 sense)
2475
+static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, bool need_sense)
24992476 {
25002477 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd;
25012478 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
25022479 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata;
2503
- void (*cmd_done) (struct pmcraid_cmd *) = sense ? pmcraid_erp_done
2504
- : pmcraid_request_sense;
25052480
25062481 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN);
25072482 ioarcb->request_flags0 = SYNC_OVERRIDE;
....@@ -2519,7 +2494,8 @@
25192494 /* writing to IOARRIN must be protected by host_lock, as mid-layer
25202495 * schedule queuecommand while we are doing this
25212496 */
2522
- pmcraid_send_cmd(cmd, cmd_done,
2497
+ pmcraid_send_cmd(cmd, need_sense ?
2498
+ pmcraid_erp_done : pmcraid_request_sense,
25232499 PMCRAID_REQUEST_SENSE_TIMEOUT,
25242500 pmcraid_timeout_handler);
25252501 }
....@@ -2612,7 +2588,7 @@
26122588 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa;
26132589 u32 ioasc = le32_to_cpu(ioasa->ioasc);
26142590 u32 masked_ioasc = ioasc & PMCRAID_IOASC_SENSE_MASK;
2615
- u32 sense_copied = 0;
2591
+ bool sense_copied = false;
26162592
26172593 if (!res) {
26182594 pmcraid_info("resource pointer is NULL\n");
....@@ -2684,7 +2660,7 @@
26842660 memcpy(scsi_cmd->sense_buffer,
26852661 ioasa->sense_data,
26862662 data_size);
2687
- sense_copied = 1;
2663
+ sense_copied = true;
26882664 }
26892665
26902666 if (RES_IS_GSCSI(res->cfg_entry))
....@@ -2884,10 +2860,8 @@
28842860 {
28852861 struct pmcraid_cmd *cancel_cmd;
28862862 struct pmcraid_instance *pinstance;
2887
- struct pmcraid_resource_entry *res;
28882863
28892864 pinstance = (struct pmcraid_instance *)cmd->drv_inst;
2890
- res = cmd->scsi_cmd->device->hostdata;
28912865
28922866 cancel_cmd = pmcraid_get_free_cmd(pinstance);
28932867
....@@ -3279,7 +3253,7 @@
32793253 int direction
32803254 )
32813255 {
3282
- struct scatterlist *scatterlist;
3256
+ struct scatterlist *sg;
32833257 void *kaddr;
32843258 int bsize_elem;
32853259 int i;
....@@ -3288,10 +3262,10 @@
32883262 /* Determine the actual number of bytes per element */
32893263 bsize_elem = PAGE_SIZE * (1 << sglist->order);
32903264
3291
- scatterlist = sglist->scatterlist;
3265
+ sg = sglist->scatterlist;
32923266
3293
- for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3294
- struct page *page = sg_page(&scatterlist[i]);
3267
+ for (i = 0; i < (len / bsize_elem); i++, sg = sg_next(sg), buffer += bsize_elem) {
3268
+ struct page *page = sg_page(sg);
32953269
32963270 kaddr = kmap(page);
32973271 if (direction == DMA_TO_DEVICE)
....@@ -3306,11 +3280,11 @@
33063280 return -EFAULT;
33073281 }
33083282
3309
- scatterlist[i].length = bsize_elem;
3283
+ sg->length = bsize_elem;
33103284 }
33113285
33123286 if (len % bsize_elem) {
3313
- struct page *page = sg_page(&scatterlist[i]);
3287
+ struct page *page = sg_page(sg);
33143288
33153289 kaddr = kmap(page);
33163290
....@@ -3321,7 +3295,7 @@
33213295
33223296 kunmap(page);
33233297
3324
- scatterlist[i].length = len % bsize_elem;
3298
+ sg->length = len % bsize_elem;
33253299 }
33263300
33273301 if (rc) {
....@@ -3523,7 +3497,7 @@
35233497 return -ENOMEM;
35243498 }
35253499
3526
- sglist->num_dma_sg = pci_map_sg(cmd->drv_inst->pdev,
3500
+ sglist->num_dma_sg = dma_map_sg(&cmd->drv_inst->pdev->dev,
35273501 sglist->scatterlist,
35283502 sglist->num_sg, direction);
35293503
....@@ -3572,7 +3546,7 @@
35723546 struct pmcraid_sglist *sglist = cmd->sglist;
35733547
35743548 if (buflen > 0) {
3575
- pci_unmap_sg(cmd->drv_inst->pdev,
3549
+ dma_unmap_sg(&cmd->drv_inst->pdev->dev,
35763550 sglist->scatterlist,
35773551 sglist->num_sg,
35783552 direction);
....@@ -3609,7 +3583,7 @@
36093583 u32 ioasc;
36103584 int request_size;
36113585 int buffer_size;
3612
- u8 access, direction;
3586
+ u8 direction;
36133587 int rc = 0;
36143588
36153589 /* If IOA reset is in progress, wait 10 secs for reset to complete */
....@@ -3658,10 +3632,8 @@
36583632 request_size = le32_to_cpu(buffer->ioarcb.data_transfer_length);
36593633
36603634 if (buffer->ioarcb.request_flags0 & TRANSFER_DIR_WRITE) {
3661
- access = VERIFY_READ;
36623635 direction = DMA_TO_DEVICE;
36633636 } else {
3664
- access = VERIFY_WRITE;
36653637 direction = DMA_FROM_DEVICE;
36663638 }
36673639
....@@ -3999,9 +3971,7 @@
39993971 .open = pmcraid_chr_open,
40003972 .fasync = pmcraid_chr_fasync,
40013973 .unlocked_ioctl = pmcraid_chr_ioctl,
4002
-#ifdef CONFIG_COMPAT
4003
- .compat_ioctl = pmcraid_chr_ioctl,
4004
-#endif
3974
+ .compat_ioctl = compat_ptr_ioctl,
40053975 .llseek = noop_llseek,
40063976 };
40073977
....@@ -4158,7 +4128,6 @@
41584128 .max_sectors = PMCRAID_IOA_MAX_SECTORS,
41594129 .no_write_same = 1,
41604130 .cmd_per_lun = PMCRAID_MAX_CMD_PER_LUN,
4161
- .use_clustering = ENABLE_CLUSTERING,
41624131 .shost_attrs = pmcraid_host_attrs,
41634132 .proc_name = PMCRAID_DRIVER_NAME,
41644133 };
....@@ -4559,7 +4528,7 @@
45594528 return 0;
45604529
45614530 out_unwind:
4562
- while (--i > 0)
4531
+ while (--i >= 0)
45634532 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]);
45644533 pci_free_irq_vectors(pdev);
45654534 return rc;
....@@ -4681,7 +4650,7 @@
46814650
46824651 for (i = 0; i < PMCRAID_MAX_CMD; i++) {
46834652 pinstance->cmd_list[i]->ioa_cb =
4684
- dma_pool_alloc(
4653
+ dma_pool_zalloc(
46854654 pinstance->control_pool,
46864655 GFP_KERNEL,
46874656 &(pinstance->cmd_list[i]->ioa_cb_bus_addr));
....@@ -4690,8 +4659,6 @@
46904659 pmcraid_release_control_blocks(pinstance, i);
46914660 return -ENOMEM;
46924661 }
4693
- memset(pinstance->cmd_list[i]->ioa_cb, 0,
4694
- sizeof(struct pmcraid_control_block));
46954662 }
46964663 return 0;
46974664 }
....@@ -4708,9 +4675,9 @@
47084675 pmcraid_release_host_rrqs(struct pmcraid_instance *pinstance, int maxindex)
47094676 {
47104677 int i;
4711
- for (i = 0; i < maxindex; i++) {
47124678
4713
- pci_free_consistent(pinstance->pdev,
4679
+ for (i = 0; i < maxindex; i++) {
4680
+ dma_free_coherent(&pinstance->pdev->dev,
47144681 HRRQ_ENTRY_SIZE * PMCRAID_MAX_CMD,
47154682 pinstance->hrrq_start[i],
47164683 pinstance->hrrq_start_bus_addr[i]);
....@@ -4737,11 +4704,9 @@
47374704
47384705 for (i = 0; i < pinstance->num_hrrq; i++) {
47394706 pinstance->hrrq_start[i] =
4740
- pci_alloc_consistent(
4741
- pinstance->pdev,
4742
- buffer_size,
4743
- &(pinstance->hrrq_start_bus_addr[i]));
4744
-
4707
+ dma_alloc_coherent(&pinstance->pdev->dev, buffer_size,
4708
+ &pinstance->hrrq_start_bus_addr[i],
4709
+ GFP_KERNEL);
47454710 if (!pinstance->hrrq_start[i]) {
47464711 pmcraid_err("pci_alloc failed for hrrq vector : %d\n",
47474712 i);
....@@ -4749,7 +4714,6 @@
47494714 return -ENOMEM;
47504715 }
47514716
4752
- memset(pinstance->hrrq_start[i], 0, buffer_size);
47534717 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i];
47544718 pinstance->hrrq_end[i] =
47554719 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1;
....@@ -4770,7 +4734,7 @@
47704734 static void pmcraid_release_hcams(struct pmcraid_instance *pinstance)
47714735 {
47724736 if (pinstance->ccn.msg != NULL) {
4773
- pci_free_consistent(pinstance->pdev,
4737
+ dma_free_coherent(&pinstance->pdev->dev,
47744738 PMCRAID_AEN_HDR_SIZE +
47754739 sizeof(struct pmcraid_hcam_ccn_ext),
47764740 pinstance->ccn.msg,
....@@ -4782,7 +4746,7 @@
47824746 }
47834747
47844748 if (pinstance->ldn.msg != NULL) {
4785
- pci_free_consistent(pinstance->pdev,
4749
+ dma_free_coherent(&pinstance->pdev->dev,
47864750 PMCRAID_AEN_HDR_SIZE +
47874751 sizeof(struct pmcraid_hcam_ldn),
47884752 pinstance->ldn.msg,
....@@ -4803,17 +4767,15 @@
48034767 */
48044768 static int pmcraid_allocate_hcams(struct pmcraid_instance *pinstance)
48054769 {
4806
- pinstance->ccn.msg = pci_alloc_consistent(
4807
- pinstance->pdev,
4770
+ pinstance->ccn.msg = dma_alloc_coherent(&pinstance->pdev->dev,
48084771 PMCRAID_AEN_HDR_SIZE +
48094772 sizeof(struct pmcraid_hcam_ccn_ext),
4810
- &(pinstance->ccn.baddr));
4773
+ &pinstance->ccn.baddr, GFP_KERNEL);
48114774
4812
- pinstance->ldn.msg = pci_alloc_consistent(
4813
- pinstance->pdev,
4775
+ pinstance->ldn.msg = dma_alloc_coherent(&pinstance->pdev->dev,
48144776 PMCRAID_AEN_HDR_SIZE +
48154777 sizeof(struct pmcraid_hcam_ldn),
4816
- &(pinstance->ldn.baddr));
4778
+ &pinstance->ldn.baddr, GFP_KERNEL);
48174779
48184780 if (pinstance->ldn.msg == NULL || pinstance->ccn.msg == NULL) {
48194781 pmcraid_release_hcams(pinstance);
....@@ -4841,7 +4803,7 @@
48414803 {
48424804 if (pinstance->cfg_table != NULL &&
48434805 pinstance->cfg_table_bus_addr != 0) {
4844
- pci_free_consistent(pinstance->pdev,
4806
+ dma_free_coherent(&pinstance->pdev->dev,
48454807 sizeof(struct pmcraid_config_table),
48464808 pinstance->cfg_table,
48474809 pinstance->cfg_table_bus_addr);
....@@ -4886,10 +4848,10 @@
48864848 list_add_tail(&pinstance->res_entries[i].queue,
48874849 &pinstance->free_res_q);
48884850
4889
- pinstance->cfg_table =
4890
- pci_alloc_consistent(pinstance->pdev,
4851
+ pinstance->cfg_table = dma_alloc_coherent(&pinstance->pdev->dev,
48914852 sizeof(struct pmcraid_config_table),
4892
- &pinstance->cfg_table_bus_addr);
4853
+ &pinstance->cfg_table_bus_addr,
4854
+ GFP_KERNEL);
48934855
48944856 if (NULL == pinstance->cfg_table) {
48954857 pmcraid_err("couldn't alloc DMA memory for config table\n");
....@@ -4954,7 +4916,7 @@
49544916 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq);
49554917
49564918 if (pinstance->inq_data != NULL) {
4957
- pci_free_consistent(pinstance->pdev,
4919
+ dma_free_coherent(&pinstance->pdev->dev,
49584920 sizeof(struct pmcraid_inquiry_data),
49594921 pinstance->inq_data,
49604922 pinstance->inq_data_baddr);
....@@ -4964,7 +4926,7 @@
49644926 }
49654927
49664928 if (pinstance->timestamp_data != NULL) {
4967
- pci_free_consistent(pinstance->pdev,
4929
+ dma_free_coherent(&pinstance->pdev->dev,
49684930 sizeof(struct pmcraid_timestamp_data),
49694931 pinstance->timestamp_data,
49704932 pinstance->timestamp_data_baddr);
....@@ -4981,8 +4943,8 @@
49814943 * This routine pre-allocates memory based on the type of block as below:
49824944 * cmdblocks(PMCRAID_MAX_CMD): kernel memory using kernel's slab_allocator,
49834945 * IOARCBs(PMCRAID_MAX_CMD) : DMAable memory, using pci pool allocator
4984
- * config-table entries : DMAable memory using pci_alloc_consistent
4985
- * HostRRQs : DMAable memory, using pci_alloc_consistent
4946
+ * config-table entries : DMAable memory using dma_alloc_coherent
4947
+ * HostRRQs : DMAable memory, using dma_alloc_coherent
49864948 *
49874949 * Return Value
49884950 * 0 in case all of the blocks are allocated, -ENOMEM otherwise.
....@@ -5019,11 +4981,9 @@
50194981 }
50204982
50214983 /* allocate DMAable memory for page D0 INQUIRY buffer */
5022
- pinstance->inq_data = pci_alloc_consistent(
5023
- pinstance->pdev,
4984
+ pinstance->inq_data = dma_alloc_coherent(&pinstance->pdev->dev,
50244985 sizeof(struct pmcraid_inquiry_data),
5025
- &pinstance->inq_data_baddr);
5026
-
4986
+ &pinstance->inq_data_baddr, GFP_KERNEL);
50274987 if (pinstance->inq_data == NULL) {
50284988 pmcraid_err("couldn't allocate DMA memory for INQUIRY\n");
50294989 pmcraid_release_buffers(pinstance);
....@@ -5031,11 +4991,10 @@
50314991 }
50324992
50334993 /* allocate DMAable memory for set timestamp data buffer */
5034
- pinstance->timestamp_data = pci_alloc_consistent(
5035
- pinstance->pdev,
4994
+ pinstance->timestamp_data = dma_alloc_coherent(&pinstance->pdev->dev,
50364995 sizeof(struct pmcraid_timestamp_data),
5037
- &pinstance->timestamp_data_baddr);
5038
-
4996
+ &pinstance->timestamp_data_baddr,
4997
+ GFP_KERNEL);
50394998 if (pinstance->timestamp_data == NULL) {
50404999 pmcraid_err("couldn't allocate DMA memory for \
50415000 set time_stamp \n");
....@@ -5324,12 +5283,12 @@
53245283
53255284 pci_set_master(pdev);
53265285
5327
- if ((sizeof(dma_addr_t) == 4) ||
5328
- pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
5329
- rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
5286
+ if (sizeof(dma_addr_t) == 4 ||
5287
+ dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)))
5288
+ rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
53305289
53315290 if (rc == 0)
5332
- rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
5291
+ rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
53335292
53345293 if (rc != 0) {
53355294 dev_err(&pdev->dev, "resume: Failed to set PCI DMA mask\n");
....@@ -5733,19 +5692,19 @@
57335692 /* Firmware requires the system bus address of IOARCB to be within
57345693 * 32-bit addressable range though it has 64-bit IOARRIN register.
57355694 * However, firmware supports 64-bit streaming DMA buffers, whereas
5736
- * coherent buffers are to be 32-bit. Since pci_alloc_consistent always
5695
+ * coherent buffers are to be 32-bit. Since dma_alloc_coherent always
57375696 * returns memory within 4GB (if not, change this logic), coherent
57385697 * buffers are within firmware acceptable address ranges.
57395698 */
5740
- if ((sizeof(dma_addr_t) == 4) ||
5741
- pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
5742
- rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
5699
+ if (sizeof(dma_addr_t) == 4 ||
5700
+ dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)))
5701
+ rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
57435702
57445703 /* firmware expects 32-bit DMA addresses for IOARRIN register; set 32
5745
- * bit mask for pci_alloc_consistent to return addresses within 4GB
5704
+ * bit mask for dma_alloc_coherent to return addresses within 4GB
57465705 */
57475706 if (rc == 0)
5748
- rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
5707
+ rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
57495708
57505709 if (rc != 0) {
57515710 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
....@@ -5875,7 +5834,7 @@
58755834 }
58765835
58775836 /*
5878
- * PCI driver structure of pcmraid driver
5837
+ * PCI driver structure of pmcraid driver
58795838 */
58805839 static struct pci_driver pmcraid_driver = {
58815840 .name = PMCRAID_DRIVER_NAME,