hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/scsi/pm8001/pm8001_init.c
....@@ -41,10 +41,24 @@
4141 #include <linux/slab.h>
4242 #include "pm8001_sas.h"
4343 #include "pm8001_chips.h"
44
+#include "pm80xx_hwi.h"
45
+
46
+static ulong logging_level = PM8001_FAIL_LOGGING | PM8001_IOERR_LOGGING;
47
+module_param(logging_level, ulong, 0644);
48
+MODULE_PARM_DESC(logging_level, " bits for enabling logging info.");
49
+
50
+static ulong link_rate = LINKRATE_15 | LINKRATE_30 | LINKRATE_60 | LINKRATE_120;
51
+module_param(link_rate, ulong, 0644);
52
+MODULE_PARM_DESC(link_rate, "Enable link rate.\n"
53
+ " 1: Link rate 1.5G\n"
54
+ " 2: Link rate 3.0G\n"
55
+ " 4: Link rate 6.0G\n"
56
+ " 8: Link rate 12.0G\n");
4457
4558 static struct scsi_transport_template *pm8001_stt;
59
+static int pm8001_init_ccb_tag(struct pm8001_hba_info *, struct Scsi_Host *, struct pci_dev *);
4660
47
-/**
61
+/*
4862 * chip info structure to identify chip key functionality as
4963 * encryption available/not, no of ports, hw specific function ref
5064 */
....@@ -67,13 +81,14 @@
6781
6882 struct workqueue_struct *pm8001_wq;
6983
70
-/**
84
+/*
7185 * The main structure which LLDD must register for scsi core.
7286 */
7387 static struct scsi_host_template pm8001_sht = {
7488 .module = THIS_MODULE,
7589 .name = DRV_NAME,
7690 .queuecommand = sas_queuecommand,
91
+ .dma_need_drain = ata_scsi_dma_need_drain,
7792 .target_alloc = sas_target_alloc,
7893 .slave_configure = sas_slave_configure,
7994 .scan_finished = pm8001_scan_finished,
....@@ -82,19 +97,21 @@
8297 .bios_param = sas_bios_param,
8398 .can_queue = 1,
8499 .this_id = -1,
85
- .sg_tablesize = SG_ALL,
100
+ .sg_tablesize = PM8001_MAX_DMA_SG,
86101 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
87
- .use_clustering = ENABLE_CLUSTERING,
88102 .eh_device_reset_handler = sas_eh_device_reset_handler,
89103 .eh_target_reset_handler = sas_eh_target_reset_handler,
90104 .slave_alloc = sas_slave_alloc,
91105 .target_destroy = sas_target_destroy,
92106 .ioctl = sas_ioctl,
107
+#ifdef CONFIG_COMPAT
108
+ .compat_ioctl = sas_ioctl,
109
+#endif
93110 .shost_attrs = pm8001_host_attrs,
94111 .track_queue_depth = 1,
95112 };
96113
97
-/**
114
+/*
98115 * Sas layer call this function to execute specific task.
99116 */
100117 static struct sas_domain_function_template pm8001_transport_ops = {
....@@ -114,15 +131,15 @@
114131 };
115132
116133 /**
117
- *pm8001_phy_init - initiate our adapter phys
118
- *@pm8001_ha: our hba structure.
119
- *@phy_id: phy id.
134
+ * pm8001_phy_init - initiate our adapter phys
135
+ * @pm8001_ha: our hba structure.
136
+ * @phy_id: phy id.
120137 */
121138 static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
122139 {
123140 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
124141 struct asd_sas_phy *sas_phy = &phy->sas_phy;
125
- phy->phy_state = 0;
142
+ phy->phy_state = PHY_LINK_DISABLE;
126143 phy->pm8001_ha = pm8001_ha;
127144 sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
128145 sas_phy->class = SAS;
....@@ -140,9 +157,8 @@
140157 }
141158
142159 /**
143
- *pm8001_free - free hba
144
- *@pm8001_ha: our hba structure.
145
- *
160
+ * pm8001_free - free hba
161
+ * @pm8001_ha: our hba structure.
146162 */
147163 static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
148164 {
....@@ -153,7 +169,7 @@
153169
154170 for (i = 0; i < USI_MAX_MEMCNT; i++) {
155171 if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
156
- pci_free_consistent(pm8001_ha->pdev,
172
+ dma_free_coherent(&pm8001_ha->pdev->dev,
157173 (pm8001_ha->memoryMap.region[i].total_len +
158174 pm8001_ha->memoryMap.region[i].alignment),
159175 pm8001_ha->memoryMap.region[i].virt_ptr,
....@@ -190,6 +206,7 @@
190206 * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
191207 * It obtains the vector number and calls the equivalent bottom
192208 * half or services directly.
209
+ * @irq: interrupt number
193210 * @opaque: the passed outbound queue/vector. Host structure is
194211 * retrieved from the same.
195212 */
....@@ -203,7 +220,7 @@
203220
204221 if (unlikely(!pm8001_ha))
205222 return IRQ_NONE;
206
- if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
223
+ if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
207224 return IRQ_NONE;
208225 #ifdef PM8001_USE_TASKLET
209226 tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
....@@ -215,6 +232,7 @@
215232
216233 /**
217234 * pm8001_interrupt_handler_intx - main INTx interrupt handler.
235
+ * @irq: interrupt number
218236 * @dev_id: sas_ha structure. The HBA is retrieved from sas_has structure.
219237 */
220238
....@@ -226,7 +244,7 @@
226244 pm8001_ha = sha->lldd_ha;
227245 if (unlikely(!pm8001_ha))
228246 return IRQ_NONE;
229
- if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
247
+ if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
230248 return IRQ_NONE;
231249
232250 #ifdef PM8001_USE_TASKLET
....@@ -237,20 +255,38 @@
237255 return ret;
238256 }
239257
258
+static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha);
259
+
240260 /**
241261 * pm8001_alloc - initiate our hba structure and 6 DMAs area.
242
- * @pm8001_ha:our hba structure.
243
- *
262
+ * @pm8001_ha: our hba structure.
263
+ * @ent: PCI device ID structure to match on
244264 */
245265 static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
246266 const struct pci_device_id *ent)
247267 {
248
- int i;
268
+ int i, count = 0, rc = 0;
269
+ u32 ci_offset, ib_offset, ob_offset, pi_offset;
270
+ struct inbound_queue_table *circularQ;
271
+
249272 spin_lock_init(&pm8001_ha->lock);
250273 spin_lock_init(&pm8001_ha->bitmap_lock);
251
- PM8001_INIT_DBG(pm8001_ha,
252
- pm8001_printk("pm8001_alloc: PHY:%x\n",
253
- pm8001_ha->chip->n_phy));
274
+ pm8001_dbg(pm8001_ha, INIT, "pm8001_alloc: PHY:%x\n",
275
+ pm8001_ha->chip->n_phy);
276
+
277
+ /* Request Interrupt */
278
+ rc = pm8001_request_irq(pm8001_ha);
279
+ if (rc)
280
+ goto err_out;
281
+
282
+ count = pm8001_ha->max_q_num;
283
+ /* Queues are chosen based on the number of cores/msix availability */
284
+ ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE;
285
+ ci_offset = pm8001_ha->ci_offset = ib_offset + count;
286
+ ob_offset = pm8001_ha->ob_offset = ci_offset + count;
287
+ pi_offset = pm8001_ha->pi_offset = ob_offset + count;
288
+ pm8001_ha->max_memcnt = pi_offset + count;
289
+
254290 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
255291 pm8001_phy_init(pm8001_ha, i);
256292 pm8001_ha->port[i].wide_port_phymap = 0;
....@@ -259,9 +295,6 @@
259295 INIT_LIST_HEAD(&pm8001_ha->port[i].list);
260296 }
261297
262
- pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL);
263
- if (!pm8001_ha->tags)
264
- goto err_out;
265298 /* MPI Memory region 1 for AAP Event Log for fw */
266299 pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
267300 pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
....@@ -274,54 +307,62 @@
274307 pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
275308 pm8001_ha->memoryMap.region[IOP].alignment = 32;
276309
277
- for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
310
+ for (i = 0; i < count; i++) {
311
+ circularQ = &pm8001_ha->inbnd_q_tbl[i];
312
+ spin_lock_init(&circularQ->iq_lock);
278313 /* MPI Memory region 3 for consumer Index of inbound queues */
279
- pm8001_ha->memoryMap.region[CI+i].num_elements = 1;
280
- pm8001_ha->memoryMap.region[CI+i].element_size = 4;
281
- pm8001_ha->memoryMap.region[CI+i].total_len = 4;
282
- pm8001_ha->memoryMap.region[CI+i].alignment = 4;
314
+ pm8001_ha->memoryMap.region[ci_offset+i].num_elements = 1;
315
+ pm8001_ha->memoryMap.region[ci_offset+i].element_size = 4;
316
+ pm8001_ha->memoryMap.region[ci_offset+i].total_len = 4;
317
+ pm8001_ha->memoryMap.region[ci_offset+i].alignment = 4;
283318
284319 if ((ent->driver_data) != chip_8001) {
285320 /* MPI Memory region 5 inbound queues */
286
- pm8001_ha->memoryMap.region[IB+i].num_elements =
321
+ pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
287322 PM8001_MPI_QUEUE;
288
- pm8001_ha->memoryMap.region[IB+i].element_size = 128;
289
- pm8001_ha->memoryMap.region[IB+i].total_len =
323
+ pm8001_ha->memoryMap.region[ib_offset+i].element_size
324
+ = 128;
325
+ pm8001_ha->memoryMap.region[ib_offset+i].total_len =
290326 PM8001_MPI_QUEUE * 128;
291
- pm8001_ha->memoryMap.region[IB+i].alignment = 128;
327
+ pm8001_ha->memoryMap.region[ib_offset+i].alignment
328
+ = 128;
292329 } else {
293
- pm8001_ha->memoryMap.region[IB+i].num_elements =
330
+ pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
294331 PM8001_MPI_QUEUE;
295
- pm8001_ha->memoryMap.region[IB+i].element_size = 64;
296
- pm8001_ha->memoryMap.region[IB+i].total_len =
332
+ pm8001_ha->memoryMap.region[ib_offset+i].element_size
333
+ = 64;
334
+ pm8001_ha->memoryMap.region[ib_offset+i].total_len =
297335 PM8001_MPI_QUEUE * 64;
298
- pm8001_ha->memoryMap.region[IB+i].alignment = 64;
336
+ pm8001_ha->memoryMap.region[ib_offset+i].alignment = 64;
299337 }
300338 }
301339
302
- for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
340
+ for (i = 0; i < count; i++) {
303341 /* MPI Memory region 4 for producer Index of outbound queues */
304
- pm8001_ha->memoryMap.region[PI+i].num_elements = 1;
305
- pm8001_ha->memoryMap.region[PI+i].element_size = 4;
306
- pm8001_ha->memoryMap.region[PI+i].total_len = 4;
307
- pm8001_ha->memoryMap.region[PI+i].alignment = 4;
342
+ pm8001_ha->memoryMap.region[pi_offset+i].num_elements = 1;
343
+ pm8001_ha->memoryMap.region[pi_offset+i].element_size = 4;
344
+ pm8001_ha->memoryMap.region[pi_offset+i].total_len = 4;
345
+ pm8001_ha->memoryMap.region[pi_offset+i].alignment = 4;
308346
309347 if (ent->driver_data != chip_8001) {
310348 /* MPI Memory region 6 Outbound queues */
311
- pm8001_ha->memoryMap.region[OB+i].num_elements =
349
+ pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
312350 PM8001_MPI_QUEUE;
313
- pm8001_ha->memoryMap.region[OB+i].element_size = 128;
314
- pm8001_ha->memoryMap.region[OB+i].total_len =
351
+ pm8001_ha->memoryMap.region[ob_offset+i].element_size
352
+ = 128;
353
+ pm8001_ha->memoryMap.region[ob_offset+i].total_len =
315354 PM8001_MPI_QUEUE * 128;
316
- pm8001_ha->memoryMap.region[OB+i].alignment = 128;
355
+ pm8001_ha->memoryMap.region[ob_offset+i].alignment
356
+ = 128;
317357 } else {
318358 /* MPI Memory region 6 Outbound queues */
319
- pm8001_ha->memoryMap.region[OB+i].num_elements =
359
+ pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
320360 PM8001_MPI_QUEUE;
321
- pm8001_ha->memoryMap.region[OB+i].element_size = 64;
322
- pm8001_ha->memoryMap.region[OB+i].total_len =
361
+ pm8001_ha->memoryMap.region[ob_offset+i].element_size
362
+ = 64;
363
+ pm8001_ha->memoryMap.region[ob_offset+i].total_len =
323364 PM8001_MPI_QUEUE * 64;
324
- pm8001_ha->memoryMap.region[OB+i].alignment = 64;
365
+ pm8001_ha->memoryMap.region[ob_offset+i].alignment = 64;
325366 }
326367
327368 }
....@@ -329,19 +370,6 @@
329370 pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
330371 pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
331372 pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
332
- /* Memory region for devices*/
333
- pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1;
334
- pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES *
335
- sizeof(struct pm8001_device);
336
- pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES *
337
- sizeof(struct pm8001_device);
338
-
339
- /* Memory region for ccb_info*/
340
- pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1;
341
- pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB *
342
- sizeof(struct pm8001_ccb_info);
343
- pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB *
344
- sizeof(struct pm8001_ccb_info);
345373
346374 /* Memory region for fw flash */
347375 pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
....@@ -350,7 +378,7 @@
350378 pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
351379 pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
352380 pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
353
- for (i = 0; i < USI_MAX_MEMCNT; i++) {
381
+ for (i = 0; i < pm8001_ha->max_memcnt; i++) {
354382 if (pm8001_mem_alloc(pm8001_ha->pdev,
355383 &pm8001_ha->memoryMap.region[i].virt_ptr,
356384 &pm8001_ha->memoryMap.region[i].phys_addr,
....@@ -358,34 +386,41 @@
358386 &pm8001_ha->memoryMap.region[i].phys_addr_lo,
359387 pm8001_ha->memoryMap.region[i].total_len,
360388 pm8001_ha->memoryMap.region[i].alignment) != 0) {
361
- PM8001_FAIL_DBG(pm8001_ha,
362
- pm8001_printk("Mem%d alloc failed\n",
363
- i));
389
+ pm8001_dbg(pm8001_ha, FAIL,
390
+ "Mem%d alloc failed\n",
391
+ i);
364392 goto err_out;
365393 }
366394 }
367395
368
- pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
396
+ /* Memory region for devices*/
397
+ pm8001_ha->devices = kzalloc(PM8001_MAX_DEVICES
398
+ * sizeof(struct pm8001_device), GFP_KERNEL);
399
+ if (!pm8001_ha->devices) {
400
+ rc = -ENOMEM;
401
+ goto err_out_nodev;
402
+ }
369403 for (i = 0; i < PM8001_MAX_DEVICES; i++) {
370404 pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
371405 pm8001_ha->devices[i].id = i;
372406 pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
373
- pm8001_ha->devices[i].running_req = 0;
374
- }
375
- pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
376
- for (i = 0; i < PM8001_MAX_CCB; i++) {
377
- pm8001_ha->ccb_info[i].ccb_dma_handle =
378
- pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
379
- i * sizeof(struct pm8001_ccb_info);
380
- pm8001_ha->ccb_info[i].task = NULL;
381
- pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
382
- pm8001_ha->ccb_info[i].device = NULL;
383
- ++pm8001_ha->tags_num;
407
+ atomic_set(&pm8001_ha->devices[i].running_req, 0);
384408 }
385409 pm8001_ha->flags = PM8001F_INIT_TIME;
386410 /* Initialize tags */
387411 pm8001_tag_init(pm8001_ha);
388412 return 0;
413
+
414
+err_out_nodev:
415
+ for (i = 0; i < pm8001_ha->max_memcnt; i++) {
416
+ if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
417
+ pci_free_consistent(pm8001_ha->pdev,
418
+ (pm8001_ha->memoryMap.region[i].total_len +
419
+ pm8001_ha->memoryMap.region[i].alignment),
420
+ pm8001_ha->memoryMap.region[i].virt_ptr,
421
+ pm8001_ha->memoryMap.region[i].phys_addr);
422
+ }
423
+ }
389424 err_out:
390425 return 1;
391426 }
....@@ -403,7 +438,7 @@
403438
404439 pdev = pm8001_ha->pdev;
405440 /* map pci mem (PMC pci base 0-3)*/
406
- for (bar = 0; bar < 6; bar++) {
441
+ for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
407442 /*
408443 ** logical BARs for SPC:
409444 ** bar 0 and 1 - logical BAR0
....@@ -422,19 +457,19 @@
422457 pm8001_ha->io_mem[logicalBar].memvirtaddr =
423458 ioremap(pm8001_ha->io_mem[logicalBar].membase,
424459 pm8001_ha->io_mem[logicalBar].memsize);
425
- PM8001_INIT_DBG(pm8001_ha,
426
- pm8001_printk("PCI: bar %d, logicalBar %d ",
427
- bar, logicalBar));
428
- PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
429
- "base addr %llx virt_addr=%llx len=%d\n",
430
- (u64)pm8001_ha->io_mem[logicalBar].membase,
431
- (u64)(unsigned long)
432
- pm8001_ha->io_mem[logicalBar].memvirtaddr,
433
- pm8001_ha->io_mem[logicalBar].memsize));
460
+ pm8001_dbg(pm8001_ha, INIT,
461
+ "PCI: bar %d, logicalBar %d\n",
462
+ bar, logicalBar);
463
+ pm8001_dbg(pm8001_ha, INIT,
464
+ "base addr %llx virt_addr=%llx len=%d\n",
465
+ (u64)pm8001_ha->io_mem[logicalBar].membase,
466
+ (u64)(unsigned long)
467
+ pm8001_ha->io_mem[logicalBar].memvirtaddr,
468
+ pm8001_ha->io_mem[logicalBar].memsize);
434469 } else {
435470 pm8001_ha->io_mem[logicalBar].membase = 0;
436471 pm8001_ha->io_mem[logicalBar].memsize = 0;
437
- pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
472
+ pm8001_ha->io_mem[logicalBar].memvirtaddr = NULL;
438473 }
439474 logicalBar++;
440475 }
....@@ -468,7 +503,16 @@
468503 pm8001_ha->sas = sha;
469504 pm8001_ha->shost = shost;
470505 pm8001_ha->id = pm8001_id++;
471
- pm8001_ha->logging_level = 0x01;
506
+ pm8001_ha->logging_level = logging_level;
507
+ pm8001_ha->non_fatal_count = 0;
508
+ if (link_rate >= 1 && link_rate <= 15)
509
+ pm8001_ha->link_rate = (link_rate << 8);
510
+ else {
511
+ pm8001_ha->link_rate = LINKRATE_15 | LINKRATE_30 |
512
+ LINKRATE_60 | LINKRATE_120;
513
+ pm8001_dbg(pm8001_ha, FAIL,
514
+ "Setting link rate to default value\n");
515
+ }
472516 sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
473517 /* IOMB size is 128 for 8088/89 controllers */
474518 if (pm8001_ha->chip_id != chip_8001)
....@@ -502,30 +546,12 @@
502546 {
503547 int rc;
504548
505
- if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
506
- rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
507
- if (rc) {
508
- rc = pci_set_consistent_dma_mask(pdev,
509
- DMA_BIT_MASK(32));
510
- if (rc) {
511
- dev_printk(KERN_ERR, &pdev->dev,
512
- "44-bit DMA enable failed\n");
513
- return rc;
514
- }
515
- }
516
- } else {
517
- rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
518
- if (rc) {
549
+ rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
550
+ if (rc) {
551
+ rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
552
+ if (rc)
519553 dev_printk(KERN_ERR, &pdev->dev,
520554 "32-bit DMA enable failed\n");
521
- return rc;
522
- }
523
- rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
524
- if (rc) {
525
- dev_printk(KERN_ERR, &pdev->dev,
526
- "32-bit consistent DMA enable failed\n");
527
- return rc;
528
- }
529555 }
530556 return rc;
531557 }
....@@ -606,7 +632,7 @@
606632
607633 /**
608634 * pm8001_init_sas_add - initialize sas address
609
- * @chip_info: our ha struct.
635
+ * @pm8001_ha: our ha struct.
610636 *
611637 * Currently we just set the fixed SAS address to our HBA,for manufacture,
612638 * it should read from the EEPROM
....@@ -631,30 +657,30 @@
631657 if (pm8001_ha->chip_id == chip_8001) {
632658 if (deviceid == 0x8081 || deviceid == 0x0042) {
633659 payload.minor_function = 4;
634
- payload.length = 4096;
660
+ payload.rd_length = 4096;
635661 } else {
636662 payload.minor_function = 0;
637
- payload.length = 128;
663
+ payload.rd_length = 128;
638664 }
639665 } else if ((pm8001_ha->chip_id == chip_8070 ||
640666 pm8001_ha->chip_id == chip_8072) &&
641667 pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
642668 payload.minor_function = 4;
643
- payload.length = 4096;
669
+ payload.rd_length = 4096;
644670 } else {
645671 payload.minor_function = 1;
646
- payload.length = 4096;
672
+ payload.rd_length = 4096;
647673 }
648674 payload.offset = 0;
649
- payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
675
+ payload.func_specific = kzalloc(payload.rd_length, GFP_KERNEL);
650676 if (!payload.func_specific) {
651
- PM8001_INIT_DBG(pm8001_ha, pm8001_printk("mem alloc fail\n"));
677
+ pm8001_dbg(pm8001_ha, INIT, "mem alloc fail\n");
652678 return;
653679 }
654680 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
655681 if (rc) {
656682 kfree(payload.func_specific);
657
- PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
683
+ pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
658684 return;
659685 }
660686 wait_for_completion(&completion);
....@@ -682,9 +708,8 @@
682708 sas_add[7] = sas_add[7] + 4;
683709 memcpy(&pm8001_ha->phy[i].dev_sas_addr,
684710 sas_add, SAS_ADDR_SIZE);
685
- PM8001_INIT_DBG(pm8001_ha,
686
- pm8001_printk("phy %d sas_addr = %016llx\n", i,
687
- pm8001_ha->phy[i].dev_sas_addr));
711
+ pm8001_dbg(pm8001_ha, INIT, "phy %d sas_addr = %016llx\n", i,
712
+ pm8001_ha->phy[i].dev_sas_addr);
688713 }
689714 kfree(payload.func_specific);
690715 #else
....@@ -716,7 +741,7 @@
716741 /* SAS ADDRESS read from flash / EEPROM */
717742 payload.minor_function = 6;
718743 payload.offset = 0;
719
- payload.length = 4096;
744
+ payload.rd_length = 4096;
720745 payload.func_specific = kzalloc(4096, GFP_KERNEL);
721746 if (!payload.func_specific)
722747 return -ENOMEM;
....@@ -724,7 +749,7 @@
724749 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
725750 if (rc) {
726751 kfree(payload.func_specific);
727
- PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
752
+ pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
728753 return -ENOMEM;
729754 }
730755 wait_for_completion(&completion);
....@@ -818,9 +843,9 @@
818843 break;
819844
820845 default:
821
- PM8001_INIT_DBG(pm8001_ha,
822
- pm8001_printk("Unknown subsystem device=0x%.04x",
823
- pm8001_ha->pdev->subsystem_device));
846
+ pm8001_dbg(pm8001_ha, INIT,
847
+ "Unknown subsystem device=0x%.04x\n",
848
+ pm8001_ha->pdev->subsystem_device);
824849 }
825850 }
826851
....@@ -884,44 +909,65 @@
884909 #ifdef PM8001_USE_MSIX
885910 /**
886911 * pm8001_setup_msix - enable MSI-X interrupt
887
- * @chip_info: our ha struct.
888
- * @irq_handler: irq_handler
912
+ * @pm8001_ha: our ha struct.
889913 */
890914 static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
891915 {
892
- u32 i = 0, j = 0;
893916 u32 number_of_intr;
894
- int flag = 0;
895
- int rc;
896
- static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
917
+ int rc, cpu_online_count;
918
+ unsigned int allocated_irq_vectors;
897919
898920 /* SPCv controllers supports 64 msi-x */
899921 if (pm8001_ha->chip_id == chip_8001) {
900922 number_of_intr = 1;
901923 } else {
902924 number_of_intr = PM8001_MAX_MSIX_VEC;
903
- flag &= ~IRQF_SHARED;
904925 }
905926
927
+ cpu_online_count = num_online_cpus();
928
+ number_of_intr = min_t(int, cpu_online_count, number_of_intr);
906929 rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr,
907930 number_of_intr, PCI_IRQ_MSIX);
931
+ allocated_irq_vectors = rc;
908932 if (rc < 0)
909933 return rc;
934
+
935
+ /* Assigns the number of interrupts */
936
+ number_of_intr = min_t(int, allocated_irq_vectors, number_of_intr);
910937 pm8001_ha->number_of_intr = number_of_intr;
911938
912
- PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
913
- "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
914
- rc, pm8001_ha->number_of_intr));
939
+ /* Maximum queue number updating in HBA structure */
940
+ pm8001_ha->max_q_num = number_of_intr;
915941
916
- for (i = 0; i < number_of_intr; i++) {
917
- snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
918
- DRV_NAME"%d", i);
942
+ pm8001_dbg(pm8001_ha, INIT,
943
+ "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
944
+ rc, pm8001_ha->number_of_intr);
945
+ return 0;
946
+}
947
+
948
+static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
949
+{
950
+ u32 i = 0, j = 0;
951
+ int flag = 0, rc = 0;
952
+
953
+ if (pm8001_ha->chip_id != chip_8001)
954
+ flag &= ~IRQF_SHARED;
955
+
956
+ pm8001_dbg(pm8001_ha, INIT,
957
+ "pci_enable_msix request number of intr %d\n",
958
+ pm8001_ha->number_of_intr);
959
+
960
+ for (i = 0; i < pm8001_ha->number_of_intr; i++) {
961
+ snprintf(pm8001_ha->intr_drvname[i],
962
+ sizeof(pm8001_ha->intr_drvname[0]),
963
+ "%s-%d", pm8001_ha->name, i);
919964 pm8001_ha->irq_vector[i].irq_id = i;
920965 pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
921966
922967 rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
923968 pm8001_interrupt_handler_msix, flag,
924
- intr_drvname[i], &(pm8001_ha->irq_vector[i]));
969
+ pm8001_ha->intr_drvname[i],
970
+ &(pm8001_ha->irq_vector[i]));
925971 if (rc) {
926972 for (j = 0; j < i; j++) {
927973 free_irq(pci_irq_vector(pm8001_ha->pdev, i),
....@@ -938,32 +984,36 @@
938984
939985 /**
940986 * pm8001_request_irq - register interrupt
941
- * @chip_info: our ha struct.
987
+ * @pm8001_ha: our ha struct.
942988 */
943989 static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
944990 {
945
- struct pci_dev *pdev;
991
+ struct pci_dev *pdev = pm8001_ha->pdev;
992
+#ifdef PM8001_USE_MSIX
946993 int rc;
947994
948
- pdev = pm8001_ha->pdev;
995
+ if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) {
996
+ rc = pm8001_setup_msix(pm8001_ha);
997
+ if (rc) {
998
+ pm8001_dbg(pm8001_ha, FAIL,
999
+ "pm8001_setup_irq failed [ret: %d]\n", rc);
1000
+ return rc;
1001
+ }
9491002
950
-#ifdef PM8001_USE_MSIX
951
- if (pdev->msix_cap && pci_msi_enabled())
952
- return pm8001_setup_msix(pm8001_ha);
953
- else {
954
- PM8001_INIT_DBG(pm8001_ha,
955
- pm8001_printk("MSIX not supported!!!\n"));
956
- goto intx;
1003
+ if (pdev->msix_cap && pci_msi_enabled())
1004
+ return pm8001_request_msix(pm8001_ha);
9571005 }
1006
+
1007
+ pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
9581008 #endif
9591009
960
-intx:
9611010 /* initialize the INT-X interrupt */
9621011 pm8001_ha->irq_vector[0].irq_id = 0;
9631012 pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
964
- rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
965
- DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
966
- return rc;
1013
+
1014
+ return request_irq(pdev->irq, pm8001_interrupt_handler_intx,
1015
+ IRQF_SHARED, pm8001_ha->name,
1016
+ SHOST_TO_SAS_HA(pm8001_ha->shost));
9671017 }
9681018
9691019 /**
....@@ -984,6 +1034,7 @@
9841034 struct pm8001_hba_info *pm8001_ha;
9851035 struct Scsi_Host *shost = NULL;
9861036 const struct pm8001_chip_info *chip;
1037
+ struct sas_ha_struct *sha;
9871038
9881039 dev_printk(KERN_INFO, &pdev->dev,
9891040 "pm80xx: driver version %s\n", DRV_VERSION);
....@@ -1012,12 +1063,12 @@
10121063 goto err_out_regions;
10131064 }
10141065 chip = &pm8001_chips[ent->driver_data];
1015
- SHOST_TO_SAS_HA(shost) =
1016
- kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
1017
- if (!SHOST_TO_SAS_HA(shost)) {
1066
+ sha = kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
1067
+ if (!sha) {
10181068 rc = -ENOMEM;
10191069 goto err_out_free_host;
10201070 }
1071
+ SHOST_TO_SAS_HA(shost) = sha;
10211072
10221073 rc = pm8001_prep_sas_ha_init(shost, chip);
10231074 if (rc) {
....@@ -1031,24 +1082,22 @@
10311082 rc = -ENOMEM;
10321083 goto err_out_free;
10331084 }
1034
- list_add_tail(&pm8001_ha->list, &hba_list);
1085
+
10351086 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
10361087 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
10371088 if (rc) {
1038
- PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
1039
- "chip_init failed [ret: %d]\n", rc));
1089
+ pm8001_dbg(pm8001_ha, FAIL,
1090
+ "chip_init failed [ret: %d]\n", rc);
10401091 goto err_out_ha_free;
10411092 }
1093
+
1094
+ rc = pm8001_init_ccb_tag(pm8001_ha, shost, pdev);
1095
+ if (rc)
1096
+ goto err_out_enable;
10421097
10431098 rc = scsi_add_host(shost, &pdev->dev);
10441099 if (rc)
10451100 goto err_out_ha_free;
1046
- rc = pm8001_request_irq(pm8001_ha);
1047
- if (rc) {
1048
- PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
1049
- "pm8001_request_irq failed [ret: %d]\n", rc));
1050
- goto err_out_shost;
1051
- }
10521101
10531102 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
10541103 if (pm8001_ha->chip_id != chip_8001) {
....@@ -1066,8 +1115,13 @@
10661115
10671116 pm8001_post_sas_ha_init(shost, chip);
10681117 rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
1069
- if (rc)
1118
+ if (rc) {
1119
+ pm8001_dbg(pm8001_ha, FAIL,
1120
+ "sas_register_ha failed [ret: %d]\n", rc);
10701121 goto err_out_shost;
1122
+ }
1123
+ list_add_tail(&pm8001_ha->list, &hba_list);
1124
+ pm8001_ha->flags = PM8001F_RUN_TIME;
10711125 scsi_scan_host(pm8001_ha->shost);
10721126 return 0;
10731127
....@@ -1076,7 +1130,7 @@
10761130 err_out_ha_free:
10771131 pm8001_free(pm8001_ha);
10781132 err_out_free:
1079
- kfree(SHOST_TO_SAS_HA(shost));
1133
+ kfree(sha);
10801134 err_out_free_host:
10811135 scsi_host_put(shost);
10821136 err_out_regions:
....@@ -1085,6 +1139,60 @@
10851139 pci_disable_device(pdev);
10861140 err_out_enable:
10871141 return rc;
1142
+}
1143
+
1144
+/*
1145
+ * pm8001_init_ccb_tag - allocate memory to CCB and tag.
1146
+ * @pm8001_ha: our hba card information.
1147
+ * @shost: scsi host which has been allocated outside.
1148
+ */
1149
+static int
1150
+pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost,
1151
+ struct pci_dev *pdev)
1152
+{
1153
+ int i = 0;
1154
+ u32 max_out_io, ccb_count;
1155
+ u32 can_queue;
1156
+
1157
+ max_out_io = pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io;
1158
+ ccb_count = min_t(int, PM8001_MAX_CCB, max_out_io);
1159
+
1160
+ /* Update to the scsi host*/
1161
+ can_queue = ccb_count - PM8001_RESERVE_SLOT;
1162
+ shost->can_queue = can_queue;
1163
+
1164
+ pm8001_ha->tags = kzalloc(ccb_count, GFP_KERNEL);
1165
+ if (!pm8001_ha->tags)
1166
+ goto err_out;
1167
+
1168
+ /* Memory region for ccb_info*/
1169
+ pm8001_ha->ccb_info = (struct pm8001_ccb_info *)
1170
+ kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL);
1171
+ if (!pm8001_ha->ccb_info) {
1172
+ pm8001_dbg(pm8001_ha, FAIL,
1173
+ "Unable to allocate memory for ccb\n");
1174
+ goto err_out_noccb;
1175
+ }
1176
+ for (i = 0; i < ccb_count; i++) {
1177
+ pm8001_ha->ccb_info[i].buf_prd = pci_alloc_consistent(pdev,
1178
+ sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
1179
+ &pm8001_ha->ccb_info[i].ccb_dma_handle);
1180
+ if (!pm8001_ha->ccb_info[i].buf_prd) {
1181
+ pm8001_dbg(pm8001_ha, FAIL,
1182
+ "pm80xx: ccb prd memory allocation error\n");
1183
+ goto err_out;
1184
+ }
1185
+ pm8001_ha->ccb_info[i].task = NULL;
1186
+ pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
1187
+ pm8001_ha->ccb_info[i].device = NULL;
1188
+ ++pm8001_ha->tags_num;
1189
+ }
1190
+ return 0;
1191
+
1192
+err_out_noccb:
1193
+ kfree(pm8001_ha->devices);
1194
+err_out:
1195
+ return -ENOMEM;
10881196 }
10891197
10901198 static void pm8001_pci_remove(struct pci_dev *pdev)
....@@ -1215,8 +1323,7 @@
12151323 /* chip soft rst only for spc */
12161324 if (pm8001_ha->chip_id == chip_8001) {
12171325 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
1218
- PM8001_INIT_DBG(pm8001_ha,
1219
- pm8001_printk("chip soft reset successful\n"));
1326
+ pm8001_dbg(pm8001_ha, INIT, "chip soft reset successful\n");
12201327 }
12211328 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
12221329 if (rc)