aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2009-07-31 20:43:59 -0400
committerJames Bottomley <James.Bottomley@suse.de>2009-08-22 18:52:14 -0400
commit21fab1d0595eacf781705ec3509012a28f298245 (patch)
tree825d307407b1705d79dc72f5e50a1bd339f7e356 /drivers
parent43d8eb9cfd0aea93be32181c64e18191b69c211c (diff)
[SCSI] ses: update enclosure data on hot add
Now that hot add works correctly, if a new device is added, we're still operating on stale enclosure data, so fix that by updating the enclosure diagnostic pages when we get notified of a device hot add Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/misc/enclosure.c3
-rw-r--r--drivers/scsi/ses.c168
2 files changed, 100 insertions, 71 deletions
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 850706a5e553..7b039306037f 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -315,6 +315,9 @@ int enclosure_add_device(struct enclosure_device *edev, int component,
315 315
316 cdev = &edev->component[component]; 316 cdev = &edev->component[component];
317 317
318 if (cdev->dev == dev)
319 return -EEXIST;
320
318 if (cdev->dev) 321 if (cdev->dev)
319 enclosure_remove_links(cdev); 322 enclosure_remove_links(cdev);
320 323
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index be593c8525b5..55b034b72708 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -347,6 +347,97 @@ static int ses_enclosure_find_by_addr(struct enclosure_device *edev,
347 return 0; 347 return 0;
348} 348}
349 349
350#define INIT_ALLOC_SIZE 32
351
352static void ses_enclosure_data_process(struct enclosure_device *edev,
353 struct scsi_device *sdev,
354 int create)
355{
356 u32 result;
357 unsigned char *buf = NULL, *type_ptr, *desc_ptr, *addl_desc_ptr = NULL;
358 int i, j, page7_len, len, components;
359 struct ses_device *ses_dev = edev->scratch;
360 int types = ses_dev->page1[10];
361 unsigned char *hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL);
362
363 if (!hdr_buf)
364 goto simple_populate;
365
366 /* re-read page 10 */
367 if (ses_dev->page10)
368 ses_recv_diag(sdev, 10, ses_dev->page10, ses_dev->page10_len);
369 /* Page 7 for the descriptors is optional */
370 result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE);
371 if (result)
372 goto simple_populate;
373
374 page7_len = len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
375 /* add 1 for trailing '\0' we'll use */
376 buf = kzalloc(len + 1, GFP_KERNEL);
377 if (!buf)
378 goto simple_populate;
379 result = ses_recv_diag(sdev, 7, buf, len);
380 if (result) {
381 simple_populate:
382 kfree(buf);
383 buf = NULL;
384 desc_ptr = NULL;
385 len = 0;
386 page7_len = 0;
387 } else {
388 desc_ptr = buf + 8;
389 len = (desc_ptr[2] << 8) + desc_ptr[3];
390 /* skip past overall descriptor */
391 desc_ptr += len + 4;
392 if (ses_dev->page10)
393 addl_desc_ptr = ses_dev->page10 + 8;
394 }
395 type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
396 components = 0;
397 for (i = 0; i < types; i++, type_ptr += 4) {
398 for (j = 0; j < type_ptr[1]; j++) {
399 char *name = NULL;
400 struct enclosure_component *ecomp;
401
402 if (desc_ptr) {
403 if (desc_ptr >= buf + page7_len) {
404 desc_ptr = NULL;
405 } else {
406 len = (desc_ptr[2] << 8) + desc_ptr[3];
407 desc_ptr += 4;
408 /* Add trailing zero - pushes into
409 * reserved space */
410 desc_ptr[len] = '\0';
411 name = desc_ptr;
412 }
413 }
414 if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
415 type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) {
416
417 if (create)
418 ecomp = enclosure_component_register(edev,
419 components++,
420 type_ptr[0],
421 name);
422 else
423 ecomp = &edev->component[components++];
424
425 if (!IS_ERR(ecomp) && addl_desc_ptr)
426 ses_process_descriptor(ecomp,
427 addl_desc_ptr);
428 }
429 if (desc_ptr)
430 desc_ptr += len;
431
432 if (addl_desc_ptr)
433 addl_desc_ptr += addl_desc_ptr[1] + 2;
434
435 }
436 }
437 kfree(buf);
438 kfree(hdr_buf);
439}
440
350static void ses_match_to_enclosure(struct enclosure_device *edev, 441static void ses_match_to_enclosure(struct enclosure_device *edev,
351 struct scsi_device *sdev) 442 struct scsi_device *sdev)
352{ 443{
@@ -361,6 +452,8 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
361 if (!buf) 452 if (!buf)
362 return; 453 return;
363 454
455 ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0);
456
364 vpd_len = ((buf[2] << 8) | buf[3]) + 4; 457 vpd_len = ((buf[2] << 8) | buf[3]) + 4;
365 458
366 desc = buf + 4; 459 desc = buf + 4;
@@ -395,18 +488,15 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
395 kfree(buf); 488 kfree(buf);
396} 489}
397 490
398#define INIT_ALLOC_SIZE 32
399
400static int ses_intf_add(struct device *cdev, 491static int ses_intf_add(struct device *cdev,
401 struct class_interface *intf) 492 struct class_interface *intf)
402{ 493{
403 struct scsi_device *sdev = to_scsi_device(cdev->parent); 494 struct scsi_device *sdev = to_scsi_device(cdev->parent);
404 struct scsi_device *tmp_sdev; 495 struct scsi_device *tmp_sdev;
405 unsigned char *buf = NULL, *hdr_buf, *type_ptr, *desc_ptr = NULL, 496 unsigned char *buf = NULL, *hdr_buf, *type_ptr;
406 *addl_desc_ptr = NULL;
407 struct ses_device *ses_dev; 497 struct ses_device *ses_dev;
408 u32 result; 498 u32 result;
409 int i, j, types, len, page7_len = 0, components = 0; 499 int i, types, len, components = 0;
410 int err = -ENOMEM; 500 int err = -ENOMEM;
411 struct enclosure_device *edev; 501 struct enclosure_device *edev;
412 struct ses_component *scomp = NULL; 502 struct ses_component *scomp = NULL;
@@ -501,6 +591,7 @@ static int ses_intf_add(struct device *cdev,
501 ses_dev->page10_len = len; 591 ses_dev->page10_len = len;
502 buf = NULL; 592 buf = NULL;
503 } 593 }
594 kfree(hdr_buf);
504 595
505 scomp = kzalloc(sizeof(struct ses_component) * components, GFP_KERNEL); 596 scomp = kzalloc(sizeof(struct ses_component) * components, GFP_KERNEL);
506 if (!scomp) 597 if (!scomp)
@@ -517,72 +608,7 @@ static int ses_intf_add(struct device *cdev,
517 for (i = 0; i < components; i++) 608 for (i = 0; i < components; i++)
518 edev->component[i].scratch = scomp + i; 609 edev->component[i].scratch = scomp + i;
519 610
520 /* Page 7 for the descriptors is optional */ 611 ses_enclosure_data_process(edev, sdev, 1);
521 result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE);
522 if (result)
523 goto simple_populate;
524
525 page7_len = len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
526 /* add 1 for trailing '\0' we'll use */
527 buf = kzalloc(len + 1, GFP_KERNEL);
528 if (!buf)
529 goto simple_populate;
530 result = ses_recv_diag(sdev, 7, buf, len);
531 if (result) {
532 simple_populate:
533 kfree(buf);
534 buf = NULL;
535 desc_ptr = NULL;
536 addl_desc_ptr = NULL;
537 } else {
538 desc_ptr = buf + 8;
539 len = (desc_ptr[2] << 8) + desc_ptr[3];
540 /* skip past overall descriptor */
541 desc_ptr += len + 4;
542 if (ses_dev->page10)
543 addl_desc_ptr = ses_dev->page10 + 8;
544 }
545 type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
546 components = 0;
547 for (i = 0; i < types; i++, type_ptr += 4) {
548 for (j = 0; j < type_ptr[1]; j++) {
549 char *name = NULL;
550 struct enclosure_component *ecomp;
551
552 if (desc_ptr) {
553 if (desc_ptr >= buf + page7_len) {
554 desc_ptr = NULL;
555 } else {
556 len = (desc_ptr[2] << 8) + desc_ptr[3];
557 desc_ptr += 4;
558 /* Add trailing zero - pushes into
559 * reserved space */
560 desc_ptr[len] = '\0';
561 name = desc_ptr;
562 }
563 }
564 if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
565 type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) {
566
567 ecomp = enclosure_component_register(edev,
568 components++,
569 type_ptr[0],
570 name);
571
572 if (!IS_ERR(ecomp) && addl_desc_ptr)
573 ses_process_descriptor(ecomp,
574 addl_desc_ptr);
575 }
576 if (desc_ptr)
577 desc_ptr += len;
578
579 if (addl_desc_ptr)
580 addl_desc_ptr += addl_desc_ptr[1] + 2;
581
582 }
583 }
584 kfree(buf);
585 kfree(hdr_buf);
586 612
587 /* see if there are any devices matching before 613 /* see if there are any devices matching before
588 * we found the enclosure */ 614 * we found the enclosure */