hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/hpsa.c
....@@ -1,5 +1,6 @@
11 /*
22 * Disk Array driver for HP Smart Array SAS controllers
3
+ * Copyright (c) 2019-2020 Microchip Technology Inc. and its subsidiaries
34 * Copyright 2016 Microsemi Corporation
45 * Copyright 2014-2015 PMC-Sierra, Inc.
56 * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P.
....@@ -21,7 +22,6 @@
2122 #include <linux/interrupt.h>
2223 #include <linux/types.h>
2324 #include <linux/pci.h>
24
-#include <linux/pci-aspm.h>
2525 #include <linux/kernel.h>
2626 #include <linux/slab.h>
2727 #include <linux/delay.h>
....@@ -60,7 +60,7 @@
6060 * HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.'
6161 * with an optional trailing '-' followed by a byte value (0-255).
6262 */
63
-#define HPSA_DRIVER_VERSION "3.4.20-125"
63
+#define HPSA_DRIVER_VERSION "3.4.20-200"
6464 #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")"
6565 #define HPSA "hpsa"
6666
....@@ -73,6 +73,8 @@
7373
7474 /*define how many times we will try a command because of bus resets */
7575 #define MAX_CMD_RETRIES 3
76
+/* How long to wait before giving up on a command */
77
+#define HPSA_EH_PTRAID_TIMEOUT (240 * HZ)
7678
7779 /* Embedded module documentation macros - see modules.h */
7880 MODULE_AUTHOR("Hewlett-Packard Company");
....@@ -251,10 +253,15 @@
251253
252254 static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id);
253255 static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id);
254
-static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
256
+static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd,
257
+ void __user *arg);
258
+static int hpsa_passthru_ioctl(struct ctlr_info *h,
259
+ IOCTL_Command_struct *iocommand);
260
+static int hpsa_big_passthru_ioctl(struct ctlr_info *h,
261
+ BIG_IOCTL_Command_struct *ioc);
255262
256263 #ifdef CONFIG_COMPAT
257
-static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd,
264
+static int hpsa_compat_ioctl(struct scsi_device *dev, unsigned int cmd,
258265 void __user *arg);
259266 #endif
260267
....@@ -341,11 +348,6 @@
341348 static inline bool hpsa_is_cmd_idle(struct CommandList *c)
342349 {
343350 return c->scsi_cmd == SCSI_CMD_IDLE;
344
-}
345
-
346
-static inline bool hpsa_is_pending_event(struct CommandList *c)
347
-{
348
- return c->reset_pending;
349351 }
350352
351353 /* extract sense key, asc, and ascq from sense data. -1 means invalid. */
....@@ -971,7 +973,6 @@
971973 .scan_finished = hpsa_scan_finished,
972974 .change_queue_depth = hpsa_change_queue_depth,
973975 .this_id = -1,
974
- .use_clustering = ENABLE_CLUSTERING,
975976 .eh_device_reset_handler = hpsa_eh_device_reset_handler,
976977 .ioctl = hpsa_ioctl,
977978 .slave_alloc = hpsa_slave_alloc,
....@@ -1150,6 +1151,8 @@
11501151 {
11511152 dial_down_lockup_detection_during_fw_flash(h, c);
11521153 atomic_inc(&h->commands_outstanding);
1154
+ if (c->device)
1155
+ atomic_inc(&c->device->commands_outstanding);
11531156
11541157 reply_queue = h->reply_map[raw_smp_processor_id()];
11551158 switch (c->cmd_type) {
....@@ -1173,9 +1176,6 @@
11731176
11741177 static void enqueue_cmd_and_start_io(struct ctlr_info *h, struct CommandList *c)
11751178 {
1176
- if (unlikely(hpsa_is_pending_event(c)))
1177
- return finish_cmd(c);
1178
-
11791179 __enqueue_cmd_and_start_io(h, c, DEFAULT_REPLY_QUEUE);
11801180 }
11811181
....@@ -1334,7 +1334,7 @@
13341334 dev_warn(&h->pdev->dev, "physical device with no LUN=0,"
13351335 " suspect firmware bug or unsupported hardware "
13361336 "configuration.\n");
1337
- return -1;
1337
+ return -1;
13381338 }
13391339
13401340 lun_assigned:
....@@ -1847,25 +1847,33 @@
18471847 return count;
18481848 }
18491849
1850
+#define NUM_WAIT 20
18501851 static void hpsa_wait_for_outstanding_commands_for_dev(struct ctlr_info *h,
18511852 struct hpsa_scsi_dev_t *device)
18521853 {
18531854 int cmds = 0;
18541855 int waits = 0;
1856
+ int num_wait = NUM_WAIT;
1857
+
1858
+ if (device->external)
1859
+ num_wait = HPSA_EH_PTRAID_TIMEOUT;
18551860
18561861 while (1) {
18571862 cmds = hpsa_find_outstanding_commands_for_dev(h, device);
18581863 if (cmds == 0)
18591864 break;
1860
- if (++waits > 20)
1865
+ if (++waits > num_wait)
18611866 break;
18621867 msleep(1000);
18631868 }
18641869
1865
- if (waits > 20)
1870
+ if (waits > num_wait) {
18661871 dev_warn(&h->pdev->dev,
1867
- "%s: removing device with %d outstanding commands!\n",
1868
- __func__, cmds);
1872
+ "%s: removing device [%d:%d:%d:%d] with %d outstanding commands!\n",
1873
+ __func__,
1874
+ h->scsi_host->host_no,
1875
+ device->bus, device->target, device->lun, cmds);
1876
+ }
18691877 }
18701878
18711879 static void hpsa_remove_device(struct ctlr_info *h,
....@@ -2127,6 +2135,7 @@
21272135 }
21282136
21292137 /* configure scsi device based on internal per-device structure */
2138
+#define CTLR_TIMEOUT (120 * HZ)
21302139 static int hpsa_slave_configure(struct scsi_device *sdev)
21312140 {
21322141 struct hpsa_scsi_dev_t *sd;
....@@ -2136,13 +2145,22 @@
21362145 sdev->no_uld_attach = !sd || !sd->expose_device;
21372146
21382147 if (sd) {
2139
- if (sd->external)
2148
+ sd->was_removed = 0;
2149
+ queue_depth = sd->queue_depth != 0 ?
2150
+ sd->queue_depth : sdev->host->can_queue;
2151
+ if (sd->external) {
21402152 queue_depth = EXTERNAL_QD;
2141
- else
2142
- queue_depth = sd->queue_depth != 0 ?
2143
- sd->queue_depth : sdev->host->can_queue;
2144
- } else
2153
+ sdev->eh_timeout = HPSA_EH_PTRAID_TIMEOUT;
2154
+ blk_queue_rq_timeout(sdev->request_queue,
2155
+ HPSA_EH_PTRAID_TIMEOUT);
2156
+ }
2157
+ if (is_hba_lunid(sd->scsi3addr)) {
2158
+ sdev->eh_timeout = CTLR_TIMEOUT;
2159
+ blk_queue_rq_timeout(sdev->request_queue, CTLR_TIMEOUT);
2160
+ }
2161
+ } else {
21452162 queue_depth = sdev->host->can_queue;
2163
+ }
21462164
21472165 scsi_change_queue_depth(sdev, queue_depth);
21482166
....@@ -2151,7 +2169,12 @@
21512169
21522170 static void hpsa_slave_destroy(struct scsi_device *sdev)
21532171 {
2154
- /* nothing to do. */
2172
+ struct hpsa_scsi_dev_t *hdev = NULL;
2173
+
2174
+ hdev = sdev->hostdata;
2175
+
2176
+ if (hdev)
2177
+ hdev->was_removed = 1;
21552178 }
21562179
21572180 static void hpsa_free_ioaccel2_sg_chain_blocks(struct ctlr_info *h)
....@@ -2245,8 +2268,8 @@
22452268
22462269 chain_block = h->ioaccel2_cmd_sg_list[c->cmdindex];
22472270 chain_size = le32_to_cpu(cp->sg[0].length);
2248
- temp64 = pci_map_single(h->pdev, chain_block, chain_size,
2249
- PCI_DMA_TODEVICE);
2271
+ temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_size,
2272
+ DMA_TO_DEVICE);
22502273 if (dma_mapping_error(&h->pdev->dev, temp64)) {
22512274 /* prevent subsequent unmapping */
22522275 cp->sg->address = 0;
....@@ -2266,7 +2289,7 @@
22662289 chain_sg = cp->sg;
22672290 temp64 = le64_to_cpu(chain_sg->address);
22682291 chain_size = le32_to_cpu(cp->sg[0].length);
2269
- pci_unmap_single(h->pdev, temp64, chain_size, PCI_DMA_TODEVICE);
2292
+ dma_unmap_single(&h->pdev->dev, temp64, chain_size, DMA_TO_DEVICE);
22702293 }
22712294
22722295 static int hpsa_map_sg_chain_block(struct ctlr_info *h,
....@@ -2282,8 +2305,8 @@
22822305 chain_len = sizeof(*chain_sg) *
22832306 (le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries);
22842307 chain_sg->Len = cpu_to_le32(chain_len);
2285
- temp64 = pci_map_single(h->pdev, chain_block, chain_len,
2286
- PCI_DMA_TODEVICE);
2308
+ temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_len,
2309
+ DMA_TO_DEVICE);
22872310 if (dma_mapping_error(&h->pdev->dev, temp64)) {
22882311 /* prevent subsequent unmapping */
22892312 chain_sg->Addr = cpu_to_le64(0);
....@@ -2302,8 +2325,8 @@
23022325 return;
23032326
23042327 chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
2305
- pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr),
2306
- le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE);
2328
+ dma_unmap_single(&h->pdev->dev, le64_to_cpu(chain_sg->Addr),
2329
+ le32_to_cpu(chain_sg->Len), DMA_TO_DEVICE);
23072330 }
23082331
23092332
....@@ -2421,13 +2444,16 @@
24212444 break;
24222445 }
24232446
2447
+ if (dev->in_reset)
2448
+ retry = 0;
2449
+
24242450 return retry; /* retry on raid path? */
24252451 }
24262452
24272453 static void hpsa_cmd_resolve_events(struct ctlr_info *h,
24282454 struct CommandList *c)
24292455 {
2430
- bool do_wake = false;
2456
+ struct hpsa_scsi_dev_t *dev = c->device;
24312457
24322458 /*
24332459 * Reset c->scsi_cmd here so that the reset handler will know
....@@ -2436,25 +2462,12 @@
24362462 */
24372463 c->scsi_cmd = SCSI_CMD_IDLE;
24382464 mb(); /* Declare command idle before checking for pending events. */
2439
- if (c->reset_pending) {
2440
- unsigned long flags;
2441
- struct hpsa_scsi_dev_t *dev;
2442
-
2443
- /*
2444
- * There appears to be a reset pending; lock the lock and
2445
- * reconfirm. If so, then decrement the count of outstanding
2446
- * commands and wake the reset command if this is the last one.
2447
- */
2448
- spin_lock_irqsave(&h->lock, flags);
2449
- dev = c->reset_pending; /* Re-fetch under the lock. */
2450
- if (dev && atomic_dec_and_test(&dev->reset_cmds_out))
2451
- do_wake = true;
2452
- c->reset_pending = NULL;
2453
- spin_unlock_irqrestore(&h->lock, flags);
2465
+ if (dev) {
2466
+ atomic_dec(&dev->commands_outstanding);
2467
+ if (dev->in_reset &&
2468
+ atomic_read(&dev->commands_outstanding) <= 0)
2469
+ wake_up_all(&h->event_sync_wait_queue);
24542470 }
2455
-
2456
- if (do_wake)
2457
- wake_up_all(&h->event_sync_wait_queue);
24582471 }
24592472
24602473 static void hpsa_cmd_resolve_and_free(struct ctlr_info *h,
....@@ -2502,6 +2515,11 @@
25022515 if (c2->error_data.status ==
25032516 IOACCEL2_STATUS_SR_IOACCEL_DISABLED) {
25042517 hpsa_turn_off_ioaccel_for_device(dev);
2518
+ }
2519
+
2520
+ if (dev->in_reset) {
2521
+ cmd->result = DID_RESET << 16;
2522
+ return hpsa_cmd_free_and_done(h, c, cmd);
25052523 }
25062524
25072525 return hpsa_retry_cmd(h, c);
....@@ -2582,6 +2600,12 @@
25822600 cmd->result = (DID_OK << 16); /* host byte */
25832601 cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
25842602
2603
+ /* SCSI command has already been cleaned up in SML */
2604
+ if (dev->was_removed) {
2605
+ hpsa_cmd_resolve_and_free(h, cp);
2606
+ return;
2607
+ }
2608
+
25852609 if (cp->cmd_type == CMD_IOACCEL2 || cp->cmd_type == CMD_IOACCEL1) {
25862610 if (dev->physical_device && dev->expose_device &&
25872611 dev->removed) {
....@@ -2602,10 +2626,6 @@
26022626 cmd->result = DID_NO_CONNECT << 16;
26032627 return hpsa_cmd_free_and_done(h, cp, cmd);
26042628 }
2605
-
2606
- if ((unlikely(hpsa_is_pending_event(cp))))
2607
- if (cp->reset_pending)
2608
- return hpsa_cmd_free_and_done(h, cp, cmd);
26092629
26102630 if (cp->cmd_type == CMD_IOACCEL2)
26112631 return process_ioaccel2_completion(h, cp, cmd, dev);
....@@ -2655,8 +2675,19 @@
26552675 decode_sense_data(ei->SenseInfo, sense_data_size,
26562676 &sense_key, &asc, &ascq);
26572677 if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
2658
- if (sense_key == ABORTED_COMMAND) {
2678
+ switch (sense_key) {
2679
+ case ABORTED_COMMAND:
26592680 cmd->result |= DID_SOFT_ERROR << 16;
2681
+ break;
2682
+ case UNIT_ATTENTION:
2683
+ if (asc == 0x3F && ascq == 0x0E)
2684
+ h->drv_req_rescan = 1;
2685
+ break;
2686
+ case ILLEGAL_REQUEST:
2687
+ if (asc == 0x25 && ascq == 0x00) {
2688
+ dev->removed = 1;
2689
+ cmd->result = DID_NO_CONNECT << 16;
2690
+ }
26602691 break;
26612692 }
26622693 break;
....@@ -2767,13 +2798,13 @@
27672798 return hpsa_cmd_free_and_done(h, cp, cmd);
27682799 }
27692800
2770
-static void hpsa_pci_unmap(struct pci_dev *pdev,
2771
- struct CommandList *c, int sg_used, int data_direction)
2801
+static void hpsa_pci_unmap(struct pci_dev *pdev, struct CommandList *c,
2802
+ int sg_used, enum dma_data_direction data_direction)
27722803 {
27732804 int i;
27742805
27752806 for (i = 0; i < sg_used; i++)
2776
- pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr),
2807
+ dma_unmap_single(&pdev->dev, le64_to_cpu(c->SG[i].Addr),
27772808 le32_to_cpu(c->SG[i].Len),
27782809 data_direction);
27792810 }
....@@ -2782,17 +2813,17 @@
27822813 struct CommandList *cp,
27832814 unsigned char *buf,
27842815 size_t buflen,
2785
- int data_direction)
2816
+ enum dma_data_direction data_direction)
27862817 {
27872818 u64 addr64;
27882819
2789
- if (buflen == 0 || data_direction == PCI_DMA_NONE) {
2820
+ if (buflen == 0 || data_direction == DMA_NONE) {
27902821 cp->Header.SGList = 0;
27912822 cp->Header.SGTotal = cpu_to_le16(0);
27922823 return 0;
27932824 }
27942825
2795
- addr64 = pci_map_single(pdev, buf, buflen, data_direction);
2826
+ addr64 = dma_map_single(&pdev->dev, buf, buflen, data_direction);
27962827 if (dma_mapping_error(&pdev->dev, addr64)) {
27972828 /* Prevent subsequent unmap of something never mapped */
27982829 cp->Header.SGList = 0;
....@@ -2853,7 +2884,8 @@
28532884
28542885 #define MAX_DRIVER_CMD_RETRIES 25
28552886 static int hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h,
2856
- struct CommandList *c, int data_direction, unsigned long timeout_msecs)
2887
+ struct CommandList *c, enum dma_data_direction data_direction,
2888
+ unsigned long timeout_msecs)
28572889 {
28582890 int backoff_time = 10, retry_count = 0;
28592891 int rc;
....@@ -2977,8 +3009,8 @@
29773009 rc = -1;
29783010 goto out;
29793011 }
2980
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
2981
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3012
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3013
+ NO_TIMEOUT);
29823014 if (rc)
29833015 goto out;
29843016 ei = c->err_info;
....@@ -3030,8 +3062,8 @@
30303062 rc = -1;
30313063 goto out;
30323064 }
3033
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
3034
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3065
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3066
+ NO_TIMEOUT);
30353067 if (rc)
30363068 goto out;
30373069 ei = c->err_info;
....@@ -3044,7 +3076,7 @@
30443076 return rc;
30453077 }
30463078
3047
-static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr,
3079
+static int hpsa_send_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev,
30483080 u8 reset_type, int reply_queue)
30493081 {
30503082 int rc = IO_OK;
....@@ -3052,11 +3084,10 @@
30523084 struct ErrorInfo *ei;
30533085
30543086 c = cmd_alloc(h);
3055
-
3087
+ c->device = dev;
30563088
30573089 /* fill_cmd can't fail here, no data buffer to map. */
3058
- (void) fill_cmd(c, reset_type, h, NULL, 0, 0,
3059
- scsi3addr, TYPE_MSG);
3090
+ (void) fill_cmd(c, reset_type, h, NULL, 0, 0, dev->scsi3addr, TYPE_MSG);
30603091 rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT);
30613092 if (rc) {
30623093 dev_warn(&h->pdev->dev, "Failed to send reset command\n");
....@@ -3134,9 +3165,8 @@
31343165 }
31353166
31363167 static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev,
3137
- unsigned char *scsi3addr, u8 reset_type, int reply_queue)
3168
+ u8 reset_type, int reply_queue)
31383169 {
3139
- int i;
31403170 int rc = 0;
31413171
31423172 /* We can really only handle one reset at a time */
....@@ -3145,38 +3175,14 @@
31453175 return -EINTR;
31463176 }
31473177
3148
- BUG_ON(atomic_read(&dev->reset_cmds_out) != 0);
3149
-
3150
- for (i = 0; i < h->nr_cmds; i++) {
3151
- struct CommandList *c = h->cmd_pool + i;
3152
- int refcount = atomic_inc_return(&c->refcount);
3153
-
3154
- if (refcount > 1 && hpsa_cmd_dev_match(h, c, dev, scsi3addr)) {
3155
- unsigned long flags;
3156
-
3157
- /*
3158
- * Mark the target command as having a reset pending,
3159
- * then lock a lock so that the command cannot complete
3160
- * while we're considering it. If the command is not
3161
- * idle then count it; otherwise revoke the event.
3162
- */
3163
- c->reset_pending = dev;
3164
- spin_lock_irqsave(&h->lock, flags); /* Implied MB */
3165
- if (!hpsa_is_cmd_idle(c))
3166
- atomic_inc(&dev->reset_cmds_out);
3167
- else
3168
- c->reset_pending = NULL;
3169
- spin_unlock_irqrestore(&h->lock, flags);
3170
- }
3171
-
3172
- cmd_free(h, c);
3173
- }
3174
-
3175
- rc = hpsa_send_reset(h, scsi3addr, reset_type, reply_queue);
3176
- if (!rc)
3178
+ rc = hpsa_send_reset(h, dev, reset_type, reply_queue);
3179
+ if (!rc) {
3180
+ /* incremented by sending the reset request */
3181
+ atomic_dec(&dev->commands_outstanding);
31773182 wait_event(h->event_sync_wait_queue,
3178
- atomic_read(&dev->reset_cmds_out) == 0 ||
3183
+ atomic_read(&dev->commands_outstanding) <= 0 ||
31793184 lockup_detected(h));
3185
+ }
31803186
31813187 if (unlikely(lockup_detected(h))) {
31823188 dev_warn(&h->pdev->dev,
....@@ -3184,10 +3190,8 @@
31843190 rc = -ENODEV;
31853191 }
31863192
3187
- if (unlikely(rc))
3188
- atomic_set(&dev->reset_cmds_out, 0);
3189
- else
3190
- rc = wait_for_device_to_become_ready(h, scsi3addr, 0);
3193
+ if (!rc)
3194
+ rc = wait_for_device_to_become_ready(h, dev->scsi3addr, 0);
31913195
31923196 mutex_unlock(&h->reset_mutex);
31933197 return rc;
....@@ -3314,8 +3318,8 @@
33143318 cmd_free(h, c);
33153319 return -1;
33163320 }
3317
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
3318
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3321
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3322
+ NO_TIMEOUT);
33193323 if (rc)
33203324 goto out;
33213325 ei = c->err_info;
....@@ -3357,8 +3361,8 @@
33573361 c->Request.CDB[2] = bmic_device_index & 0xff;
33583362 c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff;
33593363
3360
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
3361
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3364
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3365
+ NO_TIMEOUT);
33623366 if (rc)
33633367 goto out;
33643368 ei = c->err_info;
....@@ -3385,8 +3389,8 @@
33853389 if (rc)
33863390 goto out;
33873391
3388
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
3389
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3392
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3393
+ NO_TIMEOUT);
33903394 if (rc)
33913395 goto out;
33923396 ei = c->err_info;
....@@ -3416,7 +3420,7 @@
34163420 c->Request.CDB[2] = bmic_device_index & 0xff;
34173421 c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff;
34183422
3419
- hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE,
3423
+ hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
34203424 NO_TIMEOUT);
34213425 ei = c->err_info;
34223426 if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) {
....@@ -3445,8 +3449,13 @@
34453449 struct ErrorInfo *ei = NULL;
34463450 struct bmic_sense_storage_box_params *bssbp = NULL;
34473451 struct bmic_identify_physical_device *id_phys = NULL;
3448
- struct ext_report_lun_entry *rle = &rlep->LUN[rle_index];
3452
+ struct ext_report_lun_entry *rle;
34493453 u16 bmic_device_index = 0;
3454
+
3455
+ if (rle_index < 0 || rle_index >= HPSA_MAX_PHYS_LUN)
3456
+ return;
3457
+
3458
+ rle = &rlep->LUN[rle_index];
34503459
34513460 encl_dev->eli =
34523461 hpsa_get_enclosure_logical_identifier(h, scsi3addr);
....@@ -3492,7 +3501,7 @@
34923501 else
34933502 c->Request.CDB[5] = 0;
34943503
3495
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE,
3504
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
34963505 NO_TIMEOUT);
34973506 if (rc)
34983507 goto out;
....@@ -3746,8 +3755,8 @@
37463755 }
37473756 if (extended_response)
37483757 c->Request.CDB[1] = extended_response;
3749
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
3750
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
3758
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3759
+ NO_TIMEOUT);
37513760 if (rc)
37523761 goto out;
37533762 ei = c->err_info;
....@@ -3970,14 +3979,18 @@
39703979 memset(this_device->device_id, 0,
39713980 sizeof(this_device->device_id));
39723981 if (hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8,
3973
- sizeof(this_device->device_id)) < 0)
3982
+ sizeof(this_device->device_id)) < 0) {
39743983 dev_err(&h->pdev->dev,
3975
- "hpsa%d: %s: can't get device id for host %d:C0:T%d:L%d\t%s\t%.16s\n",
3984
+ "hpsa%d: %s: can't get device id for [%d:%d:%d:%d]\t%s\t%.16s\n",
39763985 h->ctlr, __func__,
39773986 h->scsi_host->host_no,
3978
- this_device->target, this_device->lun,
3987
+ this_device->bus, this_device->target,
3988
+ this_device->lun,
39793989 scsi_device_type(this_device->devtype),
39803990 this_device->model);
3991
+ rc = HPSA_LV_FAILED;
3992
+ goto bail_out;
3993
+ }
39813994
39823995 if ((this_device->devtype == TYPE_DISK ||
39833996 this_device->devtype == TYPE_ZBC) &&
....@@ -4124,7 +4137,7 @@
41244137 "maximum logical LUNs (%d) exceeded. "
41254138 "%d LUNs ignored.\n", HPSA_MAX_LUN,
41264139 *nlogicals - HPSA_MAX_LUN);
4127
- *nlogicals = HPSA_MAX_LUN;
4140
+ *nlogicals = HPSA_MAX_LUN;
41284141 }
41294142 if (*nlogicals + *nphysicals > HPSA_MAX_PHYS_LUN) {
41304143 dev_warn(&h->pdev->dev,
....@@ -4172,6 +4185,9 @@
41724185 int rc;
41734186 struct ext_report_lun_entry *rle;
41744187
4188
+ if (rle_index < 0 || rle_index >= HPSA_MAX_PHYS_LUN)
4189
+ return;
4190
+
41754191 rle = &rlep->LUN[rle_index];
41764192
41774193 dev->ioaccel_handle = rle->ioaccel_handle;
....@@ -4196,7 +4212,12 @@
41964212 struct ReportExtendedLUNdata *rlep, int rle_index,
41974213 struct bmic_identify_physical_device *id_phys)
41984214 {
4199
- struct ext_report_lun_entry *rle = &rlep->LUN[rle_index];
4215
+ struct ext_report_lun_entry *rle;
4216
+
4217
+ if (rle_index < 0 || rle_index >= HPSA_MAX_PHYS_LUN)
4218
+ return;
4219
+
4220
+ rle = &rlep->LUN[rle_index];
42004221
42014222 if ((rle->device_flags & 0x08) && this_device->ioaccel_handle)
42024223 this_device->hba_ioaccel_enabled = 1;
....@@ -4418,7 +4439,8 @@
44184439 /*
44194440 * Skip over some devices such as a spare.
44204441 */
4421
- if (!tmpdevice->external && physical_device) {
4442
+ if (phys_dev_index >= 0 && !tmpdevice->external &&
4443
+ physical_device) {
44224444 skip_device = hpsa_skip_device(h, lunaddrbytes,
44234445 &physdev_list->LUN[phys_dev_index]);
44244446 if (skip_device)
....@@ -4676,6 +4698,7 @@
46764698 case WRITE_6:
46774699 case WRITE_12:
46784700 is_write = 1;
4701
+ fallthrough;
46794702 case READ_6:
46804703 case READ_12:
46814704 if (*cdb_len == 6) {
....@@ -4816,6 +4839,9 @@
48164839 return -1;
48174840
48184841 c->phys_disk = dev;
4842
+
4843
+ if (dev->in_reset)
4844
+ return -1;
48194845
48204846 return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle,
48214847 cmd->cmnd, cmd->cmd_len, dev->scsi3addr, dev);
....@@ -5007,6 +5033,11 @@
50075033 } else
50085034 cp->sg_count = (u8) use_sg;
50095035
5036
+ if (phys_disk->in_reset) {
5037
+ cmd->result = DID_RESET << 16;
5038
+ return -1;
5039
+ }
5040
+
50105041 enqueue_cmd_and_start_io(h, c);
50115042 return 0;
50125043 }
....@@ -5022,6 +5053,9 @@
50225053 return -1;
50235054
50245055 if (!c->scsi_cmd->device->hostdata)
5056
+ return -1;
5057
+
5058
+ if (phys_disk->in_reset)
50255059 return -1;
50265060
50275061 /* Try to honor the device's queue depth */
....@@ -5107,10 +5141,14 @@
51075141 if (!dev)
51085142 return -1;
51095143
5144
+ if (dev->in_reset)
5145
+ return -1;
5146
+
51105147 /* check for valid opcode, get LBA and block count */
51115148 switch (cmd->cmnd[0]) {
51125149 case WRITE_6:
51135150 is_write = 1;
5151
+ fallthrough;
51145152 case READ_6:
51155153 first_block = (((cmd->cmnd[1] & 0x1F) << 16) |
51165154 (cmd->cmnd[2] << 8) |
....@@ -5121,6 +5159,7 @@
51215159 break;
51225160 case WRITE_10:
51235161 is_write = 1;
5162
+ fallthrough;
51245163 case READ_10:
51255164 first_block =
51265165 (((u64) cmd->cmnd[2]) << 24) |
....@@ -5133,6 +5172,7 @@
51335172 break;
51345173 case WRITE_12:
51355174 is_write = 1;
5175
+ fallthrough;
51365176 case READ_12:
51375177 first_block =
51385178 (((u64) cmd->cmnd[2]) << 24) |
....@@ -5147,6 +5187,7 @@
51475187 break;
51485188 case WRITE_16:
51495189 is_write = 1;
5190
+ fallthrough;
51505191 case READ_16:
51515192 first_block =
51525193 (((u64) cmd->cmnd[2]) << 56) |
....@@ -5418,13 +5459,13 @@
54185459 */
54195460 static int hpsa_ciss_submit(struct ctlr_info *h,
54205461 struct CommandList *c, struct scsi_cmnd *cmd,
5421
- unsigned char scsi3addr[])
5462
+ struct hpsa_scsi_dev_t *dev)
54225463 {
54235464 cmd->host_scribble = (unsigned char *) c;
54245465 c->cmd_type = CMD_SCSI;
54255466 c->scsi_cmd = cmd;
54265467 c->Header.ReplyQueue = 0; /* unused in simple mode */
5427
- memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
5468
+ memcpy(&c->Header.LUN.LunAddrBytes[0], &dev->scsi3addr[0], 8);
54285469 c->Header.tag = cpu_to_le64((c->cmdindex << DIRECT_LOOKUP_SHIFT));
54295470
54305471 /* Fill in the request block... */
....@@ -5475,6 +5516,14 @@
54755516 hpsa_cmd_resolve_and_free(h, c);
54765517 return SCSI_MLQUEUE_HOST_BUSY;
54775518 }
5519
+
5520
+ if (dev->in_reset) {
5521
+ hpsa_cmd_resolve_and_free(h, c);
5522
+ return SCSI_MLQUEUE_HOST_BUSY;
5523
+ }
5524
+
5525
+ c->device = dev;
5526
+
54785527 enqueue_cmd_and_start_io(h, c);
54795528 /* the cmd'll come back via intr handler in complete_scsi_command() */
54805529 return 0;
....@@ -5526,8 +5575,7 @@
55265575 }
55275576
55285577 static int hpsa_ioaccel_submit(struct ctlr_info *h,
5529
- struct CommandList *c, struct scsi_cmnd *cmd,
5530
- unsigned char *scsi3addr)
5578
+ struct CommandList *c, struct scsi_cmnd *cmd)
55315579 {
55325580 struct hpsa_scsi_dev_t *dev = cmd->device->hostdata;
55335581 int rc = IO_ACCEL_INELIGIBLE;
....@@ -5535,12 +5583,19 @@
55355583 if (!dev)
55365584 return SCSI_MLQUEUE_HOST_BUSY;
55375585
5586
+ if (dev->in_reset)
5587
+ return SCSI_MLQUEUE_HOST_BUSY;
5588
+
5589
+ if (hpsa_simple_mode)
5590
+ return IO_ACCEL_INELIGIBLE;
5591
+
55385592 cmd->host_scribble = (unsigned char *) c;
55395593
55405594 if (dev->offload_enabled) {
55415595 hpsa_cmd_init(h, c->cmdindex, c);
55425596 c->cmd_type = CMD_SCSI;
55435597 c->scsi_cmd = cmd;
5598
+ c->device = dev;
55445599 rc = hpsa_scsi_ioaccel_raid_map(h, c);
55455600 if (rc < 0) /* scsi_dma_map failed. */
55465601 rc = SCSI_MLQUEUE_HOST_BUSY;
....@@ -5548,6 +5603,7 @@
55485603 hpsa_cmd_init(h, c->cmdindex, c);
55495604 c->cmd_type = CMD_SCSI;
55505605 c->scsi_cmd = cmd;
5606
+ c->device = dev;
55515607 rc = hpsa_scsi_ioaccel_direct_map(h, c);
55525608 if (rc < 0) /* scsi_dma_map failed. */
55535609 rc = SCSI_MLQUEUE_HOST_BUSY;
....@@ -5567,8 +5623,12 @@
55675623 cmd->result = DID_NO_CONNECT << 16;
55685624 return hpsa_cmd_free_and_done(c->h, c, cmd);
55695625 }
5570
- if (c->reset_pending)
5626
+
5627
+ if (dev->in_reset) {
5628
+ cmd->result = DID_RESET << 16;
55715629 return hpsa_cmd_free_and_done(c->h, c, cmd);
5630
+ }
5631
+
55725632 if (c->cmd_type == CMD_IOACCEL2) {
55735633 struct ctlr_info *h = c->h;
55745634 struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex];
....@@ -5576,7 +5636,7 @@
55765636
55775637 if (c2->error_data.serv_response ==
55785638 IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL) {
5579
- rc = hpsa_ioaccel_submit(h, c, cmd, dev->scsi3addr);
5639
+ rc = hpsa_ioaccel_submit(h, c, cmd);
55805640 if (rc == 0)
55815641 return;
55825642 if (rc == SCSI_MLQUEUE_HOST_BUSY) {
....@@ -5592,7 +5652,7 @@
55925652 }
55935653 }
55945654 hpsa_cmd_partial_init(c->h, c->cmdindex, c);
5595
- if (hpsa_ciss_submit(c->h, c, cmd, dev->scsi3addr)) {
5655
+ if (hpsa_ciss_submit(c->h, c, cmd, dev)) {
55965656 /*
55975657 * If we get here, it means dma mapping failed. Try
55985658 * again via scsi mid layer, which will then get
....@@ -5611,7 +5671,6 @@
56115671 {
56125672 struct ctlr_info *h;
56135673 struct hpsa_scsi_dev_t *dev;
5614
- unsigned char scsi3addr[8];
56155674 struct CommandList *c;
56165675 int rc = 0;
56175676
....@@ -5633,14 +5692,18 @@
56335692 return 0;
56345693 }
56355694
5636
- memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr));
5637
-
56385695 if (unlikely(lockup_detected(h))) {
56395696 cmd->result = DID_NO_CONNECT << 16;
56405697 cmd->scsi_done(cmd);
56415698 return 0;
56425699 }
5700
+
5701
+ if (dev->in_reset)
5702
+ return SCSI_MLQUEUE_DEVICE_BUSY;
5703
+
56435704 c = cmd_tagged_alloc(h, cmd);
5705
+ if (c == NULL)
5706
+ return SCSI_MLQUEUE_DEVICE_BUSY;
56445707
56455708 /*
56465709 * This is necessary because the SML doesn't zero out this field during
....@@ -5655,7 +5718,7 @@
56555718 if (likely(cmd->retries == 0 &&
56565719 !blk_rq_is_passthrough(cmd->request) &&
56575720 h->acciopath_status)) {
5658
- rc = hpsa_ioaccel_submit(h, c, cmd, scsi3addr);
5721
+ rc = hpsa_ioaccel_submit(h, c, cmd);
56595722 if (rc == 0)
56605723 return 0;
56615724 if (rc == SCSI_MLQUEUE_HOST_BUSY) {
....@@ -5663,7 +5726,7 @@
56635726 return SCSI_MLQUEUE_HOST_BUSY;
56645727 }
56655728 }
5666
- return hpsa_ciss_submit(h, c, cmd, scsi3addr);
5729
+ return hpsa_ciss_submit(h, c, cmd, dev);
56675730 }
56685731
56695732 static void hpsa_scan_complete(struct ctlr_info *h)
....@@ -5771,7 +5834,7 @@
57715834 {
57725835 struct Scsi_Host *sh;
57735836
5774
- sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h));
5837
+ sh = scsi_host_alloc(&hpsa_driver_template, sizeof(struct ctlr_info));
57755838 if (sh == NULL) {
57765839 dev_err(&h->pdev->dev, "scsi_host_alloc failed\n");
57775840 return -ENOMEM;
....@@ -5839,7 +5902,7 @@
58395902 /* Send the Test Unit Ready, fill_cmd can't fail, no mapping */
58405903 (void) fill_cmd(c, TEST_UNIT_READY, h,
58415904 NULL, 0, 0, lunaddr, TYPE_CMD);
5842
- rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, DEFAULT_TIMEOUT);
5905
+ rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT);
58435906 if (rc)
58445907 return rc;
58455908 /* no unmap needed here because no data xfer. */
....@@ -5945,8 +6008,9 @@
59456008 static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
59466009 {
59476010 int rc = SUCCESS;
6011
+ int i;
59486012 struct ctlr_info *h;
5949
- struct hpsa_scsi_dev_t *dev;
6013
+ struct hpsa_scsi_dev_t *dev = NULL;
59506014 u8 reset_type;
59516015 char msg[48];
59526016 unsigned long flags;
....@@ -6012,9 +6076,19 @@
60126076 reset_type == HPSA_DEVICE_RESET_MSG ? "logical " : "physical ");
60136077 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
60146078
6079
+ /*
6080
+ * wait to see if any commands will complete before sending reset
6081
+ */
6082
+ dev->in_reset = true; /* block any new cmds from OS for this device */
6083
+ for (i = 0; i < 10; i++) {
6084
+ if (atomic_read(&dev->commands_outstanding) > 0)
6085
+ msleep(1000);
6086
+ else
6087
+ break;
6088
+ }
6089
+
60156090 /* send a reset to the SCSI LUN which the command was sent to */
6016
- rc = hpsa_do_reset(h, dev, dev->scsi3addr, reset_type,
6017
- DEFAULT_REPLY_QUEUE);
6091
+ rc = hpsa_do_reset(h, dev, reset_type, DEFAULT_REPLY_QUEUE);
60186092 if (rc == 0)
60196093 rc = SUCCESS;
60206094 else
....@@ -6028,6 +6102,8 @@
60286102 return_reset_status:
60296103 spin_lock_irqsave(&h->reset_lock, flags);
60306104 h->reset_in_progress = 0;
6105
+ if (dev)
6106
+ dev->in_reset = false;
60316107 spin_unlock_irqrestore(&h->reset_lock, flags);
60326108 return rc;
60336109 }
....@@ -6053,7 +6129,6 @@
60536129 BUG();
60546130 }
60556131
6056
- atomic_inc(&c->refcount);
60576132 if (unlikely(!hpsa_is_cmd_idle(c))) {
60586133 /*
60596134 * We expect that the SCSI layer will hand us a unique tag
....@@ -6061,13 +6136,17 @@
60616136 * two requests...because if the selected command isn't idle
60626137 * then someone is going to be very disappointed.
60636138 */
6064
- dev_err(&h->pdev->dev,
6065
- "tag collision (tag=%d) in cmd_tagged_alloc().\n",
6066
- idx);
6067
- if (c->scsi_cmd != NULL)
6068
- scsi_print_command(c->scsi_cmd);
6069
- scsi_print_command(scmd);
6139
+ if (idx != h->last_collision_tag) { /* Print once per tag */
6140
+ dev_warn(&h->pdev->dev,
6141
+ "%s: tag collision (tag=%d)\n", __func__, idx);
6142
+ if (scmd)
6143
+ scsi_print_command(scmd);
6144
+ h->last_collision_tag = idx;
6145
+ }
6146
+ return NULL;
60706147 }
6148
+
6149
+ atomic_inc(&c->refcount);
60716150
60726151 hpsa_cmd_partial_init(h, idx, c);
60736152 return c;
....@@ -6136,6 +6215,7 @@
61366215 break; /* it's ours now. */
61376216 }
61386217 hpsa_cmd_partial_init(h, i, c);
6218
+ c->device = NULL;
61396219 return c;
61406220 }
61416221
....@@ -6158,81 +6238,70 @@
61586238
61596239 #ifdef CONFIG_COMPAT
61606240
6161
-static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd,
6241
+static int hpsa_ioctl32_passthru(struct scsi_device *dev, unsigned int cmd,
61626242 void __user *arg)
61636243 {
6164
- IOCTL32_Command_struct __user *arg32 =
6165
- (IOCTL32_Command_struct __user *) arg;
6244
+ struct ctlr_info *h = sdev_to_hba(dev);
6245
+ IOCTL32_Command_struct __user *arg32 = arg;
61666246 IOCTL_Command_struct arg64;
6167
- IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64));
61686247 int err;
61696248 u32 cp;
61706249
6250
+ if (!arg)
6251
+ return -EINVAL;
6252
+
61716253 memset(&arg64, 0, sizeof(arg64));
6172
- err = 0;
6173
- err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
6174
- sizeof(arg64.LUN_info));
6175
- err |= copy_from_user(&arg64.Request, &arg32->Request,
6176
- sizeof(arg64.Request));
6177
- err |= copy_from_user(&arg64.error_info, &arg32->error_info,
6178
- sizeof(arg64.error_info));
6179
- err |= get_user(arg64.buf_size, &arg32->buf_size);
6180
- err |= get_user(cp, &arg32->buf);
6181
- arg64.buf = compat_ptr(cp);
6182
- err |= copy_to_user(p, &arg64, sizeof(arg64));
6183
-
6184
- if (err)
6254
+ if (copy_from_user(&arg64, arg32, offsetof(IOCTL_Command_struct, buf)))
61856255 return -EFAULT;
6256
+ if (get_user(cp, &arg32->buf))
6257
+ return -EFAULT;
6258
+ arg64.buf = compat_ptr(cp);
61866259
6187
- err = hpsa_ioctl(dev, CCISS_PASSTHRU, p);
6260
+ if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6261
+ return -EAGAIN;
6262
+ err = hpsa_passthru_ioctl(h, &arg64);
6263
+ atomic_inc(&h->passthru_cmds_avail);
61886264 if (err)
61896265 return err;
6190
- err |= copy_in_user(&arg32->error_info, &p->error_info,
6191
- sizeof(arg32->error_info));
6192
- if (err)
6266
+ if (copy_to_user(&arg32->error_info, &arg64.error_info,
6267
+ sizeof(arg32->error_info)))
61936268 return -EFAULT;
6194
- return err;
6269
+ return 0;
61956270 }
61966271
61976272 static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
6198
- int cmd, void __user *arg)
6273
+ unsigned int cmd, void __user *arg)
61996274 {
6200
- BIG_IOCTL32_Command_struct __user *arg32 =
6201
- (BIG_IOCTL32_Command_struct __user *) arg;
6275
+ struct ctlr_info *h = sdev_to_hba(dev);
6276
+ BIG_IOCTL32_Command_struct __user *arg32 = arg;
62026277 BIG_IOCTL_Command_struct arg64;
6203
- BIG_IOCTL_Command_struct __user *p =
6204
- compat_alloc_user_space(sizeof(arg64));
62056278 int err;
62066279 u32 cp;
62076280
6281
+ if (!arg)
6282
+ return -EINVAL;
62086283 memset(&arg64, 0, sizeof(arg64));
6209
- err = 0;
6210
- err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
6211
- sizeof(arg64.LUN_info));
6212
- err |= copy_from_user(&arg64.Request, &arg32->Request,
6213
- sizeof(arg64.Request));
6214
- err |= copy_from_user(&arg64.error_info, &arg32->error_info,
6215
- sizeof(arg64.error_info));
6216
- err |= get_user(arg64.buf_size, &arg32->buf_size);
6217
- err |= get_user(arg64.malloc_size, &arg32->malloc_size);
6218
- err |= get_user(cp, &arg32->buf);
6219
- arg64.buf = compat_ptr(cp);
6220
- err |= copy_to_user(p, &arg64, sizeof(arg64));
6221
-
6222
- if (err)
6284
+ if (copy_from_user(&arg64, arg32,
6285
+ offsetof(BIG_IOCTL32_Command_struct, buf)))
62236286 return -EFAULT;
6287
+ if (get_user(cp, &arg32->buf))
6288
+ return -EFAULT;
6289
+ arg64.buf = compat_ptr(cp);
62246290
6225
- err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, p);
6291
+ if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6292
+ return -EAGAIN;
6293
+ err = hpsa_big_passthru_ioctl(h, &arg64);
6294
+ atomic_inc(&h->passthru_cmds_avail);
62266295 if (err)
62276296 return err;
6228
- err |= copy_in_user(&arg32->error_info, &p->error_info,
6229
- sizeof(arg32->error_info));
6230
- if (err)
6297
+ if (copy_to_user(&arg32->error_info, &arg64.error_info,
6298
+ sizeof(arg32->error_info)))
62316299 return -EFAULT;
6232
- return err;
6300
+ return 0;
62336301 }
62346302
6235
-static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
6303
+static int hpsa_compat_ioctl(struct scsi_device *dev, unsigned int cmd,
6304
+ void __user *arg)
62366305 {
62376306 switch (cmd) {
62386307 case CCISS_GETPCIINFO:
....@@ -6301,37 +6370,33 @@
63016370 return 0;
63026371 }
63036372
6304
-static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6373
+static int hpsa_passthru_ioctl(struct ctlr_info *h,
6374
+ IOCTL_Command_struct *iocommand)
63056375 {
6306
- IOCTL_Command_struct iocommand;
63076376 struct CommandList *c;
63086377 char *buff = NULL;
63096378 u64 temp64;
63106379 int rc = 0;
63116380
6312
- if (!argp)
6313
- return -EINVAL;
63146381 if (!capable(CAP_SYS_RAWIO))
63156382 return -EPERM;
6316
- if (copy_from_user(&iocommand, argp, sizeof(iocommand)))
6317
- return -EFAULT;
6318
- if ((iocommand.buf_size < 1) &&
6319
- (iocommand.Request.Type.Direction != XFER_NONE)) {
6383
+ if ((iocommand->buf_size < 1) &&
6384
+ (iocommand->Request.Type.Direction != XFER_NONE)) {
63206385 return -EINVAL;
63216386 }
6322
- if (iocommand.buf_size > 0) {
6323
- buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
6387
+ if (iocommand->buf_size > 0) {
6388
+ buff = kmalloc(iocommand->buf_size, GFP_KERNEL);
63246389 if (buff == NULL)
63256390 return -ENOMEM;
6326
- if (iocommand.Request.Type.Direction & XFER_WRITE) {
6391
+ if (iocommand->Request.Type.Direction & XFER_WRITE) {
63276392 /* Copy the data into the buffer we created */
6328
- if (copy_from_user(buff, iocommand.buf,
6329
- iocommand.buf_size)) {
6393
+ if (copy_from_user(buff, iocommand->buf,
6394
+ iocommand->buf_size)) {
63306395 rc = -EFAULT;
63316396 goto out_kfree;
63326397 }
63336398 } else {
6334
- memset(buff, 0, iocommand.buf_size);
6399
+ memset(buff, 0, iocommand->buf_size);
63356400 }
63366401 }
63376402 c = cmd_alloc(h);
....@@ -6341,23 +6406,23 @@
63416406 c->scsi_cmd = SCSI_CMD_BUSY;
63426407 /* Fill in Command Header */
63436408 c->Header.ReplyQueue = 0; /* unused in simple mode */
6344
- if (iocommand.buf_size > 0) { /* buffer to fill */
6409
+ if (iocommand->buf_size > 0) { /* buffer to fill */
63456410 c->Header.SGList = 1;
63466411 c->Header.SGTotal = cpu_to_le16(1);
63476412 } else { /* no buffers to fill */
63486413 c->Header.SGList = 0;
63496414 c->Header.SGTotal = cpu_to_le16(0);
63506415 }
6351
- memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN));
6416
+ memcpy(&c->Header.LUN, &iocommand->LUN_info, sizeof(c->Header.LUN));
63526417
63536418 /* Fill in Request block */
6354
- memcpy(&c->Request, &iocommand.Request,
6419
+ memcpy(&c->Request, &iocommand->Request,
63556420 sizeof(c->Request));
63566421
63576422 /* Fill in the scatter gather information */
6358
- if (iocommand.buf_size > 0) {
6359
- temp64 = pci_map_single(h->pdev, buff,
6360
- iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
6423
+ if (iocommand->buf_size > 0) {
6424
+ temp64 = dma_map_single(&h->pdev->dev, buff,
6425
+ iocommand->buf_size, DMA_BIDIRECTIONAL);
63616426 if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) {
63626427 c->SG[0].Addr = cpu_to_le64(0);
63636428 c->SG[0].Len = cpu_to_le32(0);
....@@ -6365,13 +6430,13 @@
63656430 goto out;
63666431 }
63676432 c->SG[0].Addr = cpu_to_le64(temp64);
6368
- c->SG[0].Len = cpu_to_le32(iocommand.buf_size);
6433
+ c->SG[0].Len = cpu_to_le32(iocommand->buf_size);
63696434 c->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* not chaining */
63706435 }
63716436 rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
63726437 NO_TIMEOUT);
6373
- if (iocommand.buf_size > 0)
6374
- hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL);
6438
+ if (iocommand->buf_size > 0)
6439
+ hpsa_pci_unmap(h->pdev, c, 1, DMA_BIDIRECTIONAL);
63756440 check_ioctl_unit_attention(h, c);
63766441 if (rc) {
63776442 rc = -EIO;
....@@ -6379,16 +6444,12 @@
63796444 }
63806445
63816446 /* Copy the error information out */
6382
- memcpy(&iocommand.error_info, c->err_info,
6383
- sizeof(iocommand.error_info));
6384
- if (copy_to_user(argp, &iocommand, sizeof(iocommand))) {
6385
- rc = -EFAULT;
6386
- goto out;
6387
- }
6388
- if ((iocommand.Request.Type.Direction & XFER_READ) &&
6389
- iocommand.buf_size > 0) {
6447
+ memcpy(&iocommand->error_info, c->err_info,
6448
+ sizeof(iocommand->error_info));
6449
+ if ((iocommand->Request.Type.Direction & XFER_READ) &&
6450
+ iocommand->buf_size > 0) {
63906451 /* Copy the data out of the buffer we created */
6391
- if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) {
6452
+ if (copy_to_user(iocommand->buf, buff, iocommand->buf_size)) {
63926453 rc = -EFAULT;
63936454 goto out;
63946455 }
....@@ -6400,9 +6461,9 @@
64006461 return rc;
64016462 }
64026463
6403
-static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6464
+static int hpsa_big_passthru_ioctl(struct ctlr_info *h,
6465
+ BIG_IOCTL_Command_struct *ioc)
64046466 {
6405
- BIG_IOCTL_Command_struct *ioc;
64066467 struct CommandList *c;
64076468 unsigned char **buff = NULL;
64086469 int *buff_size = NULL;
....@@ -6413,33 +6474,17 @@
64136474 u32 sz;
64146475 BYTE __user *data_ptr;
64156476
6416
- if (!argp)
6417
- return -EINVAL;
64186477 if (!capable(CAP_SYS_RAWIO))
64196478 return -EPERM;
6420
- ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
6421
- if (!ioc) {
6422
- status = -ENOMEM;
6423
- goto cleanup1;
6424
- }
6425
- if (copy_from_user(ioc, argp, sizeof(*ioc))) {
6426
- status = -EFAULT;
6427
- goto cleanup1;
6428
- }
6479
+
64296480 if ((ioc->buf_size < 1) &&
6430
- (ioc->Request.Type.Direction != XFER_NONE)) {
6431
- status = -EINVAL;
6432
- goto cleanup1;
6433
- }
6481
+ (ioc->Request.Type.Direction != XFER_NONE))
6482
+ return -EINVAL;
64346483 /* Check kmalloc limits using all SGs */
6435
- if (ioc->malloc_size > MAX_KMALLOC_SIZE) {
6436
- status = -EINVAL;
6437
- goto cleanup1;
6438
- }
6439
- if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) {
6440
- status = -EINVAL;
6441
- goto cleanup1;
6442
- }
6484
+ if (ioc->malloc_size > MAX_KMALLOC_SIZE)
6485
+ return -EINVAL;
6486
+ if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD)
6487
+ return -EINVAL;
64436488 buff = kcalloc(SG_ENTRIES_IN_CMD, sizeof(char *), GFP_KERNEL);
64446489 if (!buff) {
64456490 status = -ENOMEM;
....@@ -6483,14 +6528,14 @@
64836528 if (ioc->buf_size > 0) {
64846529 int i;
64856530 for (i = 0; i < sg_used; i++) {
6486
- temp64 = pci_map_single(h->pdev, buff[i],
6487
- buff_size[i], PCI_DMA_BIDIRECTIONAL);
6531
+ temp64 = dma_map_single(&h->pdev->dev, buff[i],
6532
+ buff_size[i], DMA_BIDIRECTIONAL);
64886533 if (dma_mapping_error(&h->pdev->dev,
64896534 (dma_addr_t) temp64)) {
64906535 c->SG[i].Addr = cpu_to_le64(0);
64916536 c->SG[i].Len = cpu_to_le32(0);
64926537 hpsa_pci_unmap(h->pdev, c, i,
6493
- PCI_DMA_BIDIRECTIONAL);
6538
+ DMA_BIDIRECTIONAL);
64946539 status = -ENOMEM;
64956540 goto cleanup0;
64966541 }
....@@ -6503,7 +6548,7 @@
65036548 status = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
65046549 NO_TIMEOUT);
65056550 if (sg_used)
6506
- hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL);
6551
+ hpsa_pci_unmap(h->pdev, c, sg_used, DMA_BIDIRECTIONAL);
65076552 check_ioctl_unit_attention(h, c);
65086553 if (status) {
65096554 status = -EIO;
....@@ -6512,10 +6557,6 @@
65126557
65136558 /* Copy the error information out */
65146559 memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info));
6515
- if (copy_to_user(argp, ioc, sizeof(*ioc))) {
6516
- status = -EFAULT;
6517
- goto cleanup0;
6518
- }
65196560 if ((ioc->Request.Type.Direction & XFER_READ) && ioc->buf_size > 0) {
65206561 int i;
65216562
....@@ -6541,7 +6582,6 @@
65416582 kfree(buff);
65426583 }
65436584 kfree(buff_size);
6544
- kfree(ioc);
65456585 return status;
65466586 }
65476587
....@@ -6556,13 +6596,11 @@
65566596 /*
65576597 * ioctl
65586598 */
6559
-static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
6599
+static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd,
6600
+ void __user *argp)
65606601 {
6561
- struct ctlr_info *h;
6562
- void __user *argp = (void __user *)arg;
6602
+ struct ctlr_info *h = sdev_to_hba(dev);
65636603 int rc;
6564
-
6565
- h = sdev_to_hba(dev);
65666604
65676605 switch (cmd) {
65686606 case CCISS_DEREGDISK:
....@@ -6574,25 +6612,41 @@
65746612 return hpsa_getpciinfo_ioctl(h, argp);
65756613 case CCISS_GETDRIVVER:
65766614 return hpsa_getdrivver_ioctl(h, argp);
6577
- case CCISS_PASSTHRU:
6615
+ case CCISS_PASSTHRU: {
6616
+ IOCTL_Command_struct iocommand;
6617
+
6618
+ if (!argp)
6619
+ return -EINVAL;
6620
+ if (copy_from_user(&iocommand, argp, sizeof(iocommand)))
6621
+ return -EFAULT;
65786622 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
65796623 return -EAGAIN;
6580
- rc = hpsa_passthru_ioctl(h, argp);
6624
+ rc = hpsa_passthru_ioctl(h, &iocommand);
65816625 atomic_inc(&h->passthru_cmds_avail);
6626
+ if (!rc && copy_to_user(argp, &iocommand, sizeof(iocommand)))
6627
+ rc = -EFAULT;
65826628 return rc;
6583
- case CCISS_BIG_PASSTHRU:
6629
+ }
6630
+ case CCISS_BIG_PASSTHRU: {
6631
+ BIG_IOCTL_Command_struct ioc;
6632
+ if (!argp)
6633
+ return -EINVAL;
6634
+ if (copy_from_user(&ioc, argp, sizeof(ioc)))
6635
+ return -EFAULT;
65846636 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
65856637 return -EAGAIN;
6586
- rc = hpsa_big_passthru_ioctl(h, argp);
6638
+ rc = hpsa_big_passthru_ioctl(h, &ioc);
65876639 atomic_inc(&h->passthru_cmds_avail);
6640
+ if (!rc && copy_to_user(argp, &ioc, sizeof(ioc)))
6641
+ rc = -EFAULT;
65886642 return rc;
6643
+ }
65896644 default:
65906645 return -ENOTTY;
65916646 }
65926647 }
65936648
6594
-static void hpsa_send_host_reset(struct ctlr_info *h, unsigned char *scsi3addr,
6595
- u8 reset_type)
6649
+static void hpsa_send_host_reset(struct ctlr_info *h, u8 reset_type)
65966650 {
65976651 struct CommandList *c;
65986652
....@@ -6615,7 +6669,7 @@
66156669 void *buff, size_t size, u16 page_code, unsigned char *scsi3addr,
66166670 int cmd_type)
66176671 {
6618
- int pci_dir = XFER_NONE;
6672
+ enum dma_data_direction dir = DMA_NONE;
66196673
66206674 c->cmd_type = CMD_IOCTL_PEND;
66216675 c->scsi_cmd = SCSI_CMD_BUSY;
....@@ -6821,18 +6875,18 @@
68216875
68226876 switch (GET_DIR(c->Request.type_attr_dir)) {
68236877 case XFER_READ:
6824
- pci_dir = PCI_DMA_FROMDEVICE;
6878
+ dir = DMA_FROM_DEVICE;
68256879 break;
68266880 case XFER_WRITE:
6827
- pci_dir = PCI_DMA_TODEVICE;
6881
+ dir = DMA_TO_DEVICE;
68286882 break;
68296883 case XFER_NONE:
6830
- pci_dir = PCI_DMA_NONE;
6884
+ dir = DMA_NONE;
68316885 break;
68326886 default:
6833
- pci_dir = PCI_DMA_BIDIRECTIONAL;
6887
+ dir = DMA_BIDIRECTIONAL;
68346888 }
6835
- if (hpsa_map_one(h->pdev, c, buff, size, pci_dir))
6889
+ if (hpsa_map_one(h->pdev, c, buff, size, dir))
68366890 return -1;
68376891 return 0;
68386892 }
....@@ -6844,7 +6898,7 @@
68446898 {
68456899 ulong page_base = ((ulong) base) & PAGE_MASK;
68466900 ulong page_offs = ((ulong) base) - page_base;
6847
- void __iomem *page_remapped = ioremap_nocache(page_base,
6901
+ void __iomem *page_remapped = ioremap(page_base,
68486902 page_offs + size);
68496903
68506904 return page_remapped ? (page_remapped + page_offs) : NULL;
....@@ -7028,13 +7082,13 @@
70287082 * CCISS commands, so they must be allocated from the lower 4GiB of
70297083 * memory.
70307084 */
7031
- err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
7085
+ err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
70327086 if (err) {
70337087 iounmap(vaddr);
70347088 return err;
70357089 }
70367090
7037
- cmd = pci_alloc_consistent(pdev, cmd_sz, &paddr64);
7091
+ cmd = dma_alloc_coherent(&pdev->dev, cmd_sz, &paddr64, GFP_KERNEL);
70387092 if (cmd == NULL) {
70397093 iounmap(vaddr);
70407094 return -ENOMEM;
....@@ -7083,7 +7137,7 @@
70837137 return -ETIMEDOUT;
70847138 }
70857139
7086
- pci_free_consistent(pdev, cmd_sz, cmd, paddr64);
7140
+ dma_free_coherent(&pdev->dev, cmd_sz, cmd, paddr64);
70877141
70887142 if (tag & HPSA_ERROR_BIT) {
70897143 dev_err(&pdev->dev, "controller message %02x:%02x failed\n",
....@@ -7777,7 +7831,7 @@
77777831 hpsa_disable_interrupt_mode(h); /* pci_init 2 */
77787832 /*
77797833 * call pci_disable_device before pci_release_regions per
7780
- * Documentation/PCI/pci.txt
7834
+ * Documentation/driver-api/pci/pci.rst
77817835 */
77827836 pci_disable_device(h->pdev); /* pci_init 1 */
77837837 pci_release_regions(h->pdev); /* pci_init 2 */
....@@ -7860,7 +7914,7 @@
78607914 clean1:
78617915 /*
78627916 * call pci_disable_device before pci_release_regions per
7863
- * Documentation/PCI/pci.txt
7917
+ * Documentation/driver-api/pci/pci.rst
78647918 */
78657919 pci_disable_device(h->pdev);
78667920 pci_release_regions(h->pdev);
....@@ -7950,7 +8004,7 @@
79508004 kfree(h->cmd_pool_bits);
79518005 h->cmd_pool_bits = NULL;
79528006 if (h->cmd_pool) {
7953
- pci_free_consistent(h->pdev,
8007
+ dma_free_coherent(&h->pdev->dev,
79548008 h->nr_cmds * sizeof(struct CommandList),
79558009 h->cmd_pool,
79568010 h->cmd_pool_dhandle);
....@@ -7958,7 +8012,7 @@
79588012 h->cmd_pool_dhandle = 0;
79598013 }
79608014 if (h->errinfo_pool) {
7961
- pci_free_consistent(h->pdev,
8015
+ dma_free_coherent(&h->pdev->dev,
79628016 h->nr_cmds * sizeof(struct ErrorInfo),
79638017 h->errinfo_pool,
79648018 h->errinfo_pool_dhandle);
....@@ -7972,12 +8026,12 @@
79728026 h->cmd_pool_bits = kcalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG),
79738027 sizeof(unsigned long),
79748028 GFP_KERNEL);
7975
- h->cmd_pool = pci_alloc_consistent(h->pdev,
8029
+ h->cmd_pool = dma_alloc_coherent(&h->pdev->dev,
79768030 h->nr_cmds * sizeof(*h->cmd_pool),
7977
- &(h->cmd_pool_dhandle));
7978
- h->errinfo_pool = pci_alloc_consistent(h->pdev,
8031
+ &h->cmd_pool_dhandle, GFP_KERNEL);
8032
+ h->errinfo_pool = dma_alloc_coherent(&h->pdev->dev,
79798033 h->nr_cmds * sizeof(*h->errinfo_pool),
7980
- &(h->errinfo_pool_dhandle));
8034
+ &h->errinfo_pool_dhandle, GFP_KERNEL);
79818035 if ((h->cmd_pool_bits == NULL)
79828036 || (h->cmd_pool == NULL)
79838037 || (h->errinfo_pool == NULL)) {
....@@ -7995,10 +8049,15 @@
79958049 static void hpsa_free_irqs(struct ctlr_info *h)
79968050 {
79978051 int i;
8052
+ int irq_vector = 0;
8053
+
8054
+ if (hpsa_simple_mode)
8055
+ irq_vector = h->intr_mode;
79988056
79998057 if (!h->msix_vectors || h->intr_mode != PERF_MODE_INT) {
80008058 /* Single reply queue, only one irq to free */
8001
- free_irq(pci_irq_vector(h->pdev, 0), &h->q[h->intr_mode]);
8059
+ free_irq(pci_irq_vector(h->pdev, irq_vector),
8060
+ &h->q[h->intr_mode]);
80028061 h->q[h->intr_mode] = 0;
80038062 return;
80048063 }
....@@ -8017,6 +8076,10 @@
80178076 irqreturn_t (*intxhandler)(int, void *))
80188077 {
80198078 int rc, i;
8079
+ int irq_vector = 0;
8080
+
8081
+ if (hpsa_simple_mode)
8082
+ irq_vector = h->intr_mode;
80208083
80218084 /*
80228085 * initialize h->q[x] = x so that interrupt handlers know which
....@@ -8052,14 +8115,14 @@
80528115 if (h->msix_vectors > 0 || h->pdev->msi_enabled) {
80538116 sprintf(h->intrname[0], "%s-msi%s", h->devname,
80548117 h->msix_vectors ? "x" : "");
8055
- rc = request_irq(pci_irq_vector(h->pdev, 0),
8118
+ rc = request_irq(pci_irq_vector(h->pdev, irq_vector),
80568119 msixhandler, 0,
80578120 h->intrname[0],
80588121 &h->q[h->intr_mode]);
80598122 } else {
80608123 sprintf(h->intrname[h->intr_mode],
80618124 "%s-intx", h->devname);
8062
- rc = request_irq(pci_irq_vector(h->pdev, 0),
8125
+ rc = request_irq(pci_irq_vector(h->pdev, irq_vector),
80638126 intxhandler, IRQF_SHARED,
80648127 h->intrname[0],
80658128 &h->q[h->intr_mode]);
....@@ -8067,7 +8130,7 @@
80678130 }
80688131 if (rc) {
80698132 dev_err(&h->pdev->dev, "failed to get irq %d for %s\n",
8070
- pci_irq_vector(h->pdev, 0), h->devname);
8133
+ pci_irq_vector(h->pdev, irq_vector), h->devname);
80718134 hpsa_free_irqs(h);
80728135 return -ENODEV;
80738136 }
....@@ -8077,7 +8140,7 @@
80778140 static int hpsa_kdump_soft_reset(struct ctlr_info *h)
80788141 {
80798142 int rc;
8080
- hpsa_send_host_reset(h, RAID_CTLR_LUNID, HPSA_RESET_TYPE_CONTROLLER);
8143
+ hpsa_send_host_reset(h, HPSA_RESET_TYPE_CONTROLLER);
80818144
80828145 dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n");
80838146 rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY);
....@@ -8104,7 +8167,7 @@
81048167 for (i = 0; i < h->nreply_queues; i++) {
81058168 if (!h->reply_queue[i].head)
81068169 continue;
8107
- pci_free_consistent(h->pdev,
8170
+ dma_free_coherent(&h->pdev->dev,
81088171 h->reply_queue_size,
81098172 h->reply_queue[i].head,
81108173 h->reply_queue[i].busaddr);
....@@ -8133,6 +8196,11 @@
81338196 destroy_workqueue(h->rescan_ctlr_wq);
81348197 h->rescan_ctlr_wq = NULL;
81358198 }
8199
+ if (h->monitor_ctlr_wq) {
8200
+ destroy_workqueue(h->monitor_ctlr_wq);
8201
+ h->monitor_ctlr_wq = NULL;
8202
+ }
8203
+
81368204 kfree(h); /* init_one 1 */
81378205 }
81388206
....@@ -8481,8 +8549,8 @@
84818549
84828550 spin_lock_irqsave(&h->lock, flags);
84838551 if (!h->remove_in_progress)
8484
- schedule_delayed_work(&h->event_monitor_work,
8485
- HPSA_EVENT_MONITOR_INTERVAL);
8552
+ queue_delayed_work(h->monitor_ctlr_wq, &h->event_monitor_work,
8553
+ HPSA_EVENT_MONITOR_INTERVAL);
84868554 spin_unlock_irqrestore(&h->lock, flags);
84878555 }
84888556
....@@ -8527,7 +8595,7 @@
85278595
85288596 spin_lock_irqsave(&h->lock, flags);
85298597 if (!h->remove_in_progress)
8530
- schedule_delayed_work(&h->monitor_ctlr_work,
8598
+ queue_delayed_work(h->monitor_ctlr_wq, &h->monitor_ctlr_work,
85318599 h->heartbeat_sample_interval);
85328600 spin_unlock_irqrestore(&h->lock, flags);
85338601 }
....@@ -8643,11 +8711,11 @@
86438711 number_of_controllers++;
86448712
86458713 /* configure PCI DMA stuff */
8646
- rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
8714
+ rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
86478715 if (rc == 0) {
86488716 dac = 1;
86498717 } else {
8650
- rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8718
+ rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
86518719 if (rc == 0) {
86528720 dac = 0;
86538721 } else {
....@@ -8693,6 +8761,12 @@
86938761 if (!h->resubmit_wq) {
86948762 rc = -ENOMEM;
86958763 goto clean7; /* aer/h */
8764
+ }
8765
+
8766
+ h->monitor_ctlr_wq = hpsa_create_controller_wq(h, "monitor");
8767
+ if (!h->monitor_ctlr_wq) {
8768
+ rc = -ENOMEM;
8769
+ goto clean7;
86968770 }
86978771
86988772 /*
....@@ -8826,7 +8900,11 @@
88268900 destroy_workqueue(h->rescan_ctlr_wq);
88278901 h->rescan_ctlr_wq = NULL;
88288902 }
8829
- kfree(h);
8903
+ if (h->monitor_ctlr_wq) {
8904
+ destroy_workqueue(h->monitor_ctlr_wq);
8905
+ h->monitor_ctlr_wq = NULL;
8906
+ }
8907
+ hpda_free_ctlr_info(h);
88308908 return rc;
88318909 }
88328910
....@@ -8848,8 +8926,8 @@
88488926 RAID_CTLR_LUNID, TYPE_CMD)) {
88498927 goto out;
88508928 }
8851
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
8852
- PCI_DMA_TODEVICE, DEFAULT_TIMEOUT);
8929
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_TO_DEVICE,
8930
+ DEFAULT_TIMEOUT);
88538931 if (rc)
88548932 goto out;
88558933 if (c->err_info->CommandStatus != 0)
....@@ -8884,8 +8962,8 @@
88848962 RAID_CTLR_LUNID, TYPE_CMD))
88858963 goto errout;
88868964
8887
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
8888
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
8965
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
8966
+ NO_TIMEOUT);
88898967 if ((rc != 0) || (c->err_info->CommandStatus != 0))
88908968 goto errout;
88918969
....@@ -8896,8 +8974,8 @@
88968974 RAID_CTLR_LUNID, TYPE_CMD))
88978975 goto errout;
88988976
8899
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
8900
- PCI_DMA_TODEVICE, NO_TIMEOUT);
8977
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_TO_DEVICE,
8978
+ NO_TIMEOUT);
89018979 if ((rc != 0) || (c->err_info->CommandStatus != 0))
89028980 goto errout;
89038981
....@@ -8906,8 +8984,8 @@
89068984 RAID_CTLR_LUNID, TYPE_CMD))
89078985 goto errout;
89088986
8909
- rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
8910
- PCI_DMA_FROMDEVICE, NO_TIMEOUT);
8987
+ rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
8988
+ NO_TIMEOUT);
89118989 if ((rc != 0) || (c->err_info->CommandStatus != 0))
89128990 goto errout;
89138991
....@@ -8973,6 +9051,7 @@
89739051 cancel_delayed_work_sync(&h->event_monitor_work);
89749052 destroy_workqueue(h->rescan_ctlr_wq);
89759053 destroy_workqueue(h->resubmit_wq);
9054
+ destroy_workqueue(h->monitor_ctlr_wq);
89769055
89779056 hpsa_delete_sas_host(h);
89789057
....@@ -9253,10 +9332,10 @@
92539332 static void hpsa_free_ioaccel1_cmd_and_bft(struct ctlr_info *h)
92549333 {
92559334 if (h->ioaccel_cmd_pool) {
9256
- pci_free_consistent(h->pdev,
9257
- h->nr_cmds * sizeof(*h->ioaccel_cmd_pool),
9258
- h->ioaccel_cmd_pool,
9259
- h->ioaccel_cmd_pool_dhandle);
9335
+ dma_free_coherent(&h->pdev->dev,
9336
+ h->nr_cmds * sizeof(*h->ioaccel_cmd_pool),
9337
+ h->ioaccel_cmd_pool,
9338
+ h->ioaccel_cmd_pool_dhandle);
92609339 h->ioaccel_cmd_pool = NULL;
92619340 h->ioaccel_cmd_pool_dhandle = 0;
92629341 }
....@@ -9279,9 +9358,9 @@
92799358 BUILD_BUG_ON(sizeof(struct io_accel1_cmd) %
92809359 IOACCEL1_COMMANDLIST_ALIGNMENT);
92819360 h->ioaccel_cmd_pool =
9282
- pci_alloc_consistent(h->pdev,
9361
+ dma_alloc_coherent(&h->pdev->dev,
92839362 h->nr_cmds * sizeof(*h->ioaccel_cmd_pool),
9284
- &(h->ioaccel_cmd_pool_dhandle));
9363
+ &h->ioaccel_cmd_pool_dhandle, GFP_KERNEL);
92859364
92869365 h->ioaccel1_blockFetchTable =
92879366 kmalloc(((h->ioaccel_maxsg + 1) *
....@@ -9306,10 +9385,10 @@
93069385 hpsa_free_ioaccel2_sg_chain_blocks(h);
93079386
93089387 if (h->ioaccel2_cmd_pool) {
9309
- pci_free_consistent(h->pdev,
9310
- h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool),
9311
- h->ioaccel2_cmd_pool,
9312
- h->ioaccel2_cmd_pool_dhandle);
9388
+ dma_free_coherent(&h->pdev->dev,
9389
+ h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool),
9390
+ h->ioaccel2_cmd_pool,
9391
+ h->ioaccel2_cmd_pool_dhandle);
93139392 h->ioaccel2_cmd_pool = NULL;
93149393 h->ioaccel2_cmd_pool_dhandle = 0;
93159394 }
....@@ -9332,9 +9411,9 @@
93329411 BUILD_BUG_ON(sizeof(struct io_accel2_cmd) %
93339412 IOACCEL2_COMMANDLIST_ALIGNMENT);
93349413 h->ioaccel2_cmd_pool =
9335
- pci_alloc_consistent(h->pdev,
9414
+ dma_alloc_coherent(&h->pdev->dev,
93369415 h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool),
9337
- &(h->ioaccel2_cmd_pool_dhandle));
9416
+ &h->ioaccel2_cmd_pool_dhandle, GFP_KERNEL);
93389417
93399418 h->ioaccel2_blockFetchTable =
93409419 kmalloc(((h->ioaccel_maxsg + 1) *
....@@ -9407,9 +9486,10 @@
94079486 h->reply_queue_size = h->max_commands * sizeof(u64);
94089487
94099488 for (i = 0; i < h->nreply_queues; i++) {
9410
- h->reply_queue[i].head = pci_alloc_consistent(h->pdev,
9489
+ h->reply_queue[i].head = dma_alloc_coherent(&h->pdev->dev,
94119490 h->reply_queue_size,
9412
- &(h->reply_queue[i].busaddr));
9491
+ &h->reply_queue[i].busaddr,
9492
+ GFP_KERNEL);
94139493 if (!h->reply_queue[i].head) {
94149494 rc = -ENOMEM;
94159495 goto clean1; /* rq, ioaccel */
....@@ -9684,7 +9764,8 @@
96849764 return 0;
96859765
96869766 free_sas_phy:
9687
- hpsa_free_sas_phy(hpsa_sas_phy);
9767
+ sas_phy_free(hpsa_sas_phy->phy);
9768
+ kfree(hpsa_sas_phy);
96889769 free_sas_port:
96899770 hpsa_free_sas_port(hpsa_sas_port);
96909771 free_sas_node:
....@@ -9720,10 +9801,12 @@
97209801
97219802 rc = hpsa_sas_port_add_rphy(hpsa_sas_port, rphy);
97229803 if (rc)
9723
- goto free_sas_port;
9804
+ goto free_sas_rphy;
97249805
97259806 return 0;
97269807
9808
+free_sas_rphy:
9809
+ sas_rphy_free(rphy);
97279810 free_sas_port:
97289811 hpsa_free_sas_port(hpsa_sas_port);
97299812 device->sas_port = NULL;