24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
29 #include <scsi/scsi.h>
67 #define SES_TIMEOUT (30 * HZ)
73 unsigned char cmd[] = {
91 unsigned char cmd[] = {
121 for (j = 0; j < type_ptr[1]; j++) {
127 memcpy(desc_ptr, desc, 4);
136 return ses_send_diag(sdev, 2, ses_dev->
page2, ses_dev->
page2_len);
139 static unsigned char *ses_get_page2_descriptor(
struct enclosure_device *edev,
146 unsigned char *desc_ptr = ses_dev->
page2 + 8;
151 for (j = 0; j < type_ptr[1]; j++) {
172 desc = ses_get_page2_descriptor(edev, ecomp);
174 ecomp->
fault = (desc[3] & 0x60) >> 4;
181 unsigned char desc[4] = {0 };
195 return ses_set_page2_descriptor(edev, ecomp, desc);
203 desc = ses_get_page2_descriptor(edev, ecomp);
205 ecomp->
status = (desc[0] & 0x0f);
213 desc = ses_get_page2_descriptor(edev, ecomp);
215 ecomp->
locate = (desc[2] & 0x02) ? 1 : 0;
222 unsigned char desc[4] = {0 };
235 return ses_set_page2_descriptor(edev, ecomp, desc);
242 unsigned char desc[4] = {0 };
257 return ses_set_page2_descriptor(edev, ecomp, desc);
261 .get_fault = ses_get_fault,
262 .set_fault = ses_set_fault,
263 .get_status = ses_get_status,
264 .get_locate = ses_get_locate,
265 .set_locate = ses_set_locate,
266 .set_active = ses_set_active,
296 int eip = desc[0] & 0x10;
315 addr = (
u64)d[12] << 56 |
357 #define INIT_ALLOC_SIZE 32
364 unsigned char *buf =
NULL, *type_ptr, *desc_ptr, *addl_desc_ptr =
NULL;
365 int i,
j, page7_len,
len, components;
371 goto simple_populate;
379 goto simple_populate;
381 page7_len = len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
385 goto simple_populate;
386 result = ses_recv_diag(sdev, 7, buf, len);
396 len = (desc_ptr[2] << 8) + desc_ptr[3];
401 addl_desc_ptr = ses_dev->
page10 + 8;
404 for (i = 0; i < types; i++, type_ptr += 4) {
405 for (j = 0; j < type_ptr[1]; j++) {
410 if (desc_ptr >= buf + page7_len) {
413 len = (desc_ptr[2] << 8) + desc_ptr[3];
417 desc_ptr[len] =
'\0';
432 if (!IS_ERR(ecomp) && addl_desc_ptr)
433 ses_process_descriptor(ecomp,
440 addl_desc_ptr += addl_desc_ptr[1] + 2;
453 unsigned int vpd_len;
464 vpd_len = ((buf[2] << 8) | buf[3]) + 4;
471 while (desc < buf + vpd_len) {
473 u8 code_set = desc[0] & 0x0f;
474 u8 piv = desc[1] & 0x80;
475 u8 assoc = (desc[1] & 0x30) >> 4;
479 if (piv && code_set == 1 && assoc == 1
481 efd.
addr = (
u64)desc[4] << 56 |
495 efd.
dev = &sdev->sdev_gendev;
507 unsigned char *buf =
NULL, *hdr_buf, *type_ptr;
510 int i, types, len, components = 0;
516 if (!scsi_device_enclosure(sdev)) {
521 ses_match_to_enclosure(edev, sdev);
531 ses_dev = kzalloc(
sizeof(*ses_dev),
GFP_KERNEL);
533 if (!hdr_buf || !ses_dev)
540 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
545 result = ses_recv_diag(sdev, 1, buf, len);
553 num_enclosures = buf[1] + 1;
558 for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
559 types += type_ptr[2];
560 type_ptr += type_ptr[3] + 4;
566 for (i = 0; i < types && type_ptr < buf + len; i++, type_ptr += 4) {
569 components += type_ptr[1];
579 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
585 result = ses_recv_diag(sdev, 2, buf, len);
597 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
602 result = ses_recv_diag(sdev, 10, buf, len);
614 components, &ses_enclosure_callbacks);
626 ses_enclosure_data_process(edev, sdev, 1);
631 if (tmp_sdev->
lun != 0 || scsi_device_enclosure(tmp_sdev))
633 ses_match_to_enclosure(edev, tmp_sdev);
655 static int ses_remove(
struct device *
dev)
660 static void ses_intf_remove_component(
struct scsi_device *sdev)
673 static void ses_intf_remove_enclosure(
struct scsi_device *sdev)
697 static void ses_intf_remove(
struct device *cdev,
702 if (!scsi_device_enclosure(sdev))
703 ses_intf_remove_component(sdev);
705 ses_intf_remove_enclosure(sdev);
709 .add_dev = ses_intf_add,
710 .remove_dev = ses_intf_remove,
718 .remove = ses_remove,
722 static int __init ses_init(
void)
741 static void __exit ses_exit(
void)