James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 1 | /* |
| 2 | * SCSI Enclosure Services |
| 3 | * |
| 4 | * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com> |
| 5 | * |
| 6 | **----------------------------------------------------------------------------- |
| 7 | ** |
| 8 | ** This program is free software; you can redistribute it and/or |
| 9 | ** modify it under the terms of the GNU General Public License |
| 10 | ** version 2 as published by the Free Software Foundation. |
| 11 | ** |
| 12 | ** This program is distributed in the hope that it will be useful, |
| 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ** GNU General Public License for more details. |
| 16 | ** |
| 17 | ** You should have received a copy of the GNU General Public License |
| 18 | ** along with this program; if not, write to the Free Software |
| 19 | ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | ** |
| 21 | **----------------------------------------------------------------------------- |
| 22 | */ |
| 23 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/enclosure.h> |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 28 | #include <asm/unaligned.h> |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 29 | |
| 30 | #include <scsi/scsi.h> |
| 31 | #include <scsi/scsi_cmnd.h> |
| 32 | #include <scsi/scsi_dbg.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_driver.h> |
| 35 | #include <scsi/scsi_host.h> |
| 36 | |
| 37 | struct ses_device { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 38 | unsigned char *page1; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 39 | unsigned char *page1_types; |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 40 | unsigned char *page2; |
| 41 | unsigned char *page10; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 42 | short page1_len; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 43 | short page1_num_types; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 44 | short page2_len; |
| 45 | short page10_len; |
| 46 | }; |
| 47 | |
| 48 | struct ses_component { |
| 49 | u64 addr; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static int ses_probe(struct device *dev) |
| 53 | { |
| 54 | struct scsi_device *sdev = to_scsi_device(dev); |
| 55 | int err = -ENODEV; |
| 56 | |
| 57 | if (sdev->type != TYPE_ENCLOSURE) |
| 58 | goto out; |
| 59 | |
| 60 | err = 0; |
| 61 | sdev_printk(KERN_NOTICE, sdev, "Attached Enclosure device\n"); |
| 62 | |
| 63 | out: |
| 64 | return err; |
| 65 | } |
| 66 | |
Matthew Wilcox | c95e62c | 2008-06-23 09:14:31 -0600 | [diff] [blame] | 67 | #define SES_TIMEOUT (30 * HZ) |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 68 | #define SES_RETRIES 3 |
| 69 | |
| 70 | static int ses_recv_diag(struct scsi_device *sdev, int page_code, |
| 71 | void *buf, int bufflen) |
| 72 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 73 | unsigned char cmd[] = { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 74 | RECEIVE_DIAGNOSTIC, |
| 75 | 1, /* Set PCV bit */ |
| 76 | page_code, |
| 77 | bufflen >> 8, |
| 78 | bufflen & 0xff, |
| 79 | 0 |
| 80 | }; |
| 81 | |
| 82 | return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen, |
FUJITA Tomonori | f4f4e47 | 2008-12-04 14:24:39 +0900 | [diff] [blame] | 83 | NULL, SES_TIMEOUT, SES_RETRIES, NULL); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static int ses_send_diag(struct scsi_device *sdev, int page_code, |
| 87 | void *buf, int bufflen) |
| 88 | { |
| 89 | u32 result; |
| 90 | |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 91 | unsigned char cmd[] = { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 92 | SEND_DIAGNOSTIC, |
| 93 | 0x10, /* Set PF bit */ |
| 94 | 0, |
| 95 | bufflen >> 8, |
| 96 | bufflen & 0xff, |
| 97 | 0 |
| 98 | }; |
| 99 | |
| 100 | result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, buf, bufflen, |
FUJITA Tomonori | f4f4e47 | 2008-12-04 14:24:39 +0900 | [diff] [blame] | 101 | NULL, SES_TIMEOUT, SES_RETRIES, NULL); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 102 | if (result) |
| 103 | sdev_printk(KERN_ERR, sdev, "SEND DIAGNOSTIC result: %8x\n", |
| 104 | result); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | static int ses_set_page2_descriptor(struct enclosure_device *edev, |
| 109 | struct enclosure_component *ecomp, |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 110 | unsigned char *desc) |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 111 | { |
| 112 | int i, j, count = 0, descriptor = ecomp->number; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 113 | struct scsi_device *sdev = to_scsi_device(edev->edev.parent); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 114 | struct ses_device *ses_dev = edev->scratch; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 115 | unsigned char *type_ptr = ses_dev->page1_types; |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 116 | unsigned char *desc_ptr = ses_dev->page2 + 8; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 117 | |
| 118 | /* Clear everything */ |
| 119 | memset(desc_ptr, 0, ses_dev->page2_len - 8); |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 120 | for (i = 0; i < ses_dev->page1_num_types; i++, type_ptr += 4) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 121 | for (j = 0; j < type_ptr[1]; j++) { |
| 122 | desc_ptr += 4; |
| 123 | if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE && |
| 124 | type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE) |
| 125 | continue; |
| 126 | if (count++ == descriptor) { |
| 127 | memcpy(desc_ptr, desc, 4); |
| 128 | /* set select */ |
| 129 | desc_ptr[0] |= 0x80; |
| 130 | /* clear reserved, just in case */ |
| 131 | desc_ptr[0] &= 0xf0; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return ses_send_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len); |
| 137 | } |
| 138 | |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 139 | static unsigned char *ses_get_page2_descriptor(struct enclosure_device *edev, |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 140 | struct enclosure_component *ecomp) |
| 141 | { |
| 142 | int i, j, count = 0, descriptor = ecomp->number; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 143 | struct scsi_device *sdev = to_scsi_device(edev->edev.parent); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 144 | struct ses_device *ses_dev = edev->scratch; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 145 | unsigned char *type_ptr = ses_dev->page1_types; |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 146 | unsigned char *desc_ptr = ses_dev->page2 + 8; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 147 | |
| 148 | ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len); |
| 149 | |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 150 | for (i = 0; i < ses_dev->page1_num_types; i++, type_ptr += 4) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 151 | for (j = 0; j < type_ptr[1]; j++) { |
| 152 | desc_ptr += 4; |
| 153 | if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE && |
| 154 | type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE) |
| 155 | continue; |
| 156 | if (count++ == descriptor) |
| 157 | return desc_ptr; |
| 158 | } |
| 159 | } |
| 160 | return NULL; |
| 161 | } |
| 162 | |
Douglas Gilbert | 2a350ca | 2011-06-09 00:27:07 -0400 | [diff] [blame] | 163 | /* For device slot and array device slot elements, byte 3 bit 6 |
| 164 | * is "fault sensed" while byte 3 bit 5 is "fault reqstd". As this |
| 165 | * code stands these bits are shifted 4 positions right so in |
| 166 | * sysfs they will appear as bits 2 and 1 respectively. Strange. */ |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 167 | static void ses_get_fault(struct enclosure_device *edev, |
| 168 | struct enclosure_component *ecomp) |
| 169 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 170 | unsigned char *desc; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 171 | |
| 172 | desc = ses_get_page2_descriptor(edev, ecomp); |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 173 | if (desc) |
| 174 | ecomp->fault = (desc[3] & 0x60) >> 4; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static int ses_set_fault(struct enclosure_device *edev, |
| 178 | struct enclosure_component *ecomp, |
| 179 | enum enclosure_component_setting val) |
| 180 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 181 | unsigned char desc[4] = {0 }; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 182 | |
| 183 | switch (val) { |
| 184 | case ENCLOSURE_SETTING_DISABLED: |
| 185 | /* zero is disabled */ |
| 186 | break; |
| 187 | case ENCLOSURE_SETTING_ENABLED: |
Douglas Gilbert | 2a350ca | 2011-06-09 00:27:07 -0400 | [diff] [blame] | 188 | desc[3] = 0x20; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 189 | break; |
| 190 | default: |
| 191 | /* SES doesn't do the SGPIO blink settings */ |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | |
| 195 | return ses_set_page2_descriptor(edev, ecomp, desc); |
| 196 | } |
| 197 | |
| 198 | static void ses_get_status(struct enclosure_device *edev, |
| 199 | struct enclosure_component *ecomp) |
| 200 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 201 | unsigned char *desc; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 202 | |
| 203 | desc = ses_get_page2_descriptor(edev, ecomp); |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 204 | if (desc) |
| 205 | ecomp->status = (desc[0] & 0x0f); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void ses_get_locate(struct enclosure_device *edev, |
| 209 | struct enclosure_component *ecomp) |
| 210 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 211 | unsigned char *desc; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 212 | |
| 213 | desc = ses_get_page2_descriptor(edev, ecomp); |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 214 | if (desc) |
| 215 | ecomp->locate = (desc[2] & 0x02) ? 1 : 0; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static int ses_set_locate(struct enclosure_device *edev, |
| 219 | struct enclosure_component *ecomp, |
| 220 | enum enclosure_component_setting val) |
| 221 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 222 | unsigned char desc[4] = {0 }; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 223 | |
| 224 | switch (val) { |
| 225 | case ENCLOSURE_SETTING_DISABLED: |
| 226 | /* zero is disabled */ |
| 227 | break; |
| 228 | case ENCLOSURE_SETTING_ENABLED: |
| 229 | desc[2] = 0x02; |
| 230 | break; |
| 231 | default: |
| 232 | /* SES doesn't do the SGPIO blink settings */ |
| 233 | return -EINVAL; |
| 234 | } |
| 235 | return ses_set_page2_descriptor(edev, ecomp, desc); |
| 236 | } |
| 237 | |
| 238 | static int ses_set_active(struct enclosure_device *edev, |
| 239 | struct enclosure_component *ecomp, |
| 240 | enum enclosure_component_setting val) |
| 241 | { |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 242 | unsigned char desc[4] = {0 }; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 243 | |
| 244 | switch (val) { |
| 245 | case ENCLOSURE_SETTING_DISABLED: |
| 246 | /* zero is disabled */ |
| 247 | ecomp->active = 0; |
| 248 | break; |
| 249 | case ENCLOSURE_SETTING_ENABLED: |
| 250 | desc[2] = 0x80; |
| 251 | ecomp->active = 1; |
| 252 | break; |
| 253 | default: |
| 254 | /* SES doesn't do the SGPIO blink settings */ |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | return ses_set_page2_descriptor(edev, ecomp, desc); |
| 258 | } |
| 259 | |
Dan Williams | 967f7ba | 2014-12-30 14:46:16 -0800 | [diff] [blame] | 260 | static int ses_show_id(struct enclosure_device *edev, char *buf) |
| 261 | { |
| 262 | struct ses_device *ses_dev = edev->scratch; |
| 263 | unsigned long long id = get_unaligned_be64(ses_dev->page1+8+4); |
| 264 | |
| 265 | return sprintf(buf, "%#llx\n", id); |
| 266 | } |
| 267 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 268 | static struct enclosure_component_callbacks ses_enclosure_callbacks = { |
| 269 | .get_fault = ses_get_fault, |
| 270 | .set_fault = ses_set_fault, |
| 271 | .get_status = ses_get_status, |
| 272 | .get_locate = ses_get_locate, |
| 273 | .set_locate = ses_set_locate, |
| 274 | .set_active = ses_set_active, |
Dan Williams | 967f7ba | 2014-12-30 14:46:16 -0800 | [diff] [blame] | 275 | .show_id = ses_show_id, |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | struct ses_host_edev { |
| 279 | struct Scsi_Host *shost; |
| 280 | struct enclosure_device *edev; |
| 281 | }; |
| 282 | |
Adrian Bunk | e0aae1a | 2009-03-04 12:06:05 -0800 | [diff] [blame] | 283 | #if 0 |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 284 | int ses_match_host(struct enclosure_device *edev, void *data) |
| 285 | { |
| 286 | struct ses_host_edev *sed = data; |
| 287 | struct scsi_device *sdev; |
| 288 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 289 | if (!scsi_is_sdev_device(edev->edev.parent)) |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 290 | return 0; |
| 291 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 292 | sdev = to_scsi_device(edev->edev.parent); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 293 | |
| 294 | if (sdev->host != sed->shost) |
| 295 | return 0; |
| 296 | |
| 297 | sed->edev = edev; |
| 298 | return 1; |
| 299 | } |
Adrian Bunk | e0aae1a | 2009-03-04 12:06:05 -0800 | [diff] [blame] | 300 | #endif /* 0 */ |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 301 | |
| 302 | static void ses_process_descriptor(struct enclosure_component *ecomp, |
| 303 | unsigned char *desc) |
| 304 | { |
| 305 | int eip = desc[0] & 0x10; |
| 306 | int invalid = desc[0] & 0x80; |
| 307 | enum scsi_protocol proto = desc[0] & 0x0f; |
| 308 | u64 addr = 0; |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame^] | 309 | int slot = -1; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 310 | struct ses_component *scomp = ecomp->scratch; |
| 311 | unsigned char *d; |
| 312 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 313 | if (invalid) |
| 314 | return; |
| 315 | |
| 316 | switch (proto) { |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame^] | 317 | case SCSI_PROTOCOL_FCP: |
| 318 | if (eip) { |
| 319 | d = desc + 4; |
| 320 | slot = d[3]; |
| 321 | } |
| 322 | break; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 323 | case SCSI_PROTOCOL_SAS: |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame^] | 324 | if (eip) { |
| 325 | d = desc + 4; |
| 326 | slot = d[3]; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 327 | d = desc + 8; |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame^] | 328 | } else |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 329 | d = desc + 4; |
| 330 | /* only take the phy0 addr */ |
| 331 | addr = (u64)d[12] << 56 | |
| 332 | (u64)d[13] << 48 | |
| 333 | (u64)d[14] << 40 | |
| 334 | (u64)d[15] << 32 | |
| 335 | (u64)d[16] << 24 | |
| 336 | (u64)d[17] << 16 | |
| 337 | (u64)d[18] << 8 | |
| 338 | (u64)d[19]; |
| 339 | break; |
| 340 | default: |
| 341 | /* FIXME: Need to add more protocols than just SAS */ |
| 342 | break; |
| 343 | } |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame^] | 344 | ecomp->slot = slot; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 345 | scomp->addr = addr; |
| 346 | } |
| 347 | |
| 348 | struct efd { |
| 349 | u64 addr; |
| 350 | struct device *dev; |
| 351 | }; |
| 352 | |
| 353 | static int ses_enclosure_find_by_addr(struct enclosure_device *edev, |
| 354 | void *data) |
| 355 | { |
| 356 | struct efd *efd = data; |
| 357 | int i; |
| 358 | struct ses_component *scomp; |
| 359 | |
| 360 | if (!edev->component[0].scratch) |
| 361 | return 0; |
| 362 | |
| 363 | for (i = 0; i < edev->components; i++) { |
| 364 | scomp = edev->component[i].scratch; |
| 365 | if (scomp->addr != efd->addr) |
| 366 | continue; |
| 367 | |
Dan Williams | 15a0fbb | 2014-12-30 14:46:15 -0800 | [diff] [blame] | 368 | if (enclosure_add_device(edev, i, efd->dev) == 0) |
| 369 | kobject_uevent(&efd->dev->kobj, KOBJ_CHANGE); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 370 | return 1; |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 375 | #define INIT_ALLOC_SIZE 32 |
| 376 | |
| 377 | static void ses_enclosure_data_process(struct enclosure_device *edev, |
| 378 | struct scsi_device *sdev, |
| 379 | int create) |
| 380 | { |
| 381 | u32 result; |
| 382 | unsigned char *buf = NULL, *type_ptr, *desc_ptr, *addl_desc_ptr = NULL; |
| 383 | int i, j, page7_len, len, components; |
| 384 | struct ses_device *ses_dev = edev->scratch; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 385 | int types = ses_dev->page1_num_types; |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 386 | unsigned char *hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL); |
| 387 | |
| 388 | if (!hdr_buf) |
| 389 | goto simple_populate; |
| 390 | |
| 391 | /* re-read page 10 */ |
| 392 | if (ses_dev->page10) |
| 393 | ses_recv_diag(sdev, 10, ses_dev->page10, ses_dev->page10_len); |
| 394 | /* Page 7 for the descriptors is optional */ |
| 395 | result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE); |
| 396 | if (result) |
| 397 | goto simple_populate; |
| 398 | |
| 399 | page7_len = len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; |
| 400 | /* add 1 for trailing '\0' we'll use */ |
| 401 | buf = kzalloc(len + 1, GFP_KERNEL); |
| 402 | if (!buf) |
| 403 | goto simple_populate; |
| 404 | result = ses_recv_diag(sdev, 7, buf, len); |
| 405 | if (result) { |
| 406 | simple_populate: |
| 407 | kfree(buf); |
| 408 | buf = NULL; |
| 409 | desc_ptr = NULL; |
| 410 | len = 0; |
| 411 | page7_len = 0; |
| 412 | } else { |
| 413 | desc_ptr = buf + 8; |
| 414 | len = (desc_ptr[2] << 8) + desc_ptr[3]; |
| 415 | /* skip past overall descriptor */ |
| 416 | desc_ptr += len + 4; |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 417 | } |
John Hughes | 877a559 | 2009-11-04 19:01:22 +0100 | [diff] [blame] | 418 | if (ses_dev->page10) |
| 419 | addl_desc_ptr = ses_dev->page10 + 8; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 420 | type_ptr = ses_dev->page1_types; |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 421 | components = 0; |
| 422 | for (i = 0; i < types; i++, type_ptr += 4) { |
| 423 | for (j = 0; j < type_ptr[1]; j++) { |
| 424 | char *name = NULL; |
| 425 | struct enclosure_component *ecomp; |
| 426 | |
| 427 | if (desc_ptr) { |
| 428 | if (desc_ptr >= buf + page7_len) { |
| 429 | desc_ptr = NULL; |
| 430 | } else { |
| 431 | len = (desc_ptr[2] << 8) + desc_ptr[3]; |
| 432 | desc_ptr += 4; |
| 433 | /* Add trailing zero - pushes into |
| 434 | * reserved space */ |
| 435 | desc_ptr[len] = '\0'; |
| 436 | name = desc_ptr; |
| 437 | } |
| 438 | } |
| 439 | if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE || |
| 440 | type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) { |
| 441 | |
| 442 | if (create) |
Dan Williams | ed09dcc | 2014-12-30 14:46:14 -0800 | [diff] [blame] | 443 | ecomp = enclosure_component_alloc( |
| 444 | edev, |
| 445 | components++, |
| 446 | type_ptr[0], |
| 447 | name); |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 448 | else |
| 449 | ecomp = &edev->component[components++]; |
| 450 | |
Dan Williams | ed09dcc | 2014-12-30 14:46:14 -0800 | [diff] [blame] | 451 | if (!IS_ERR(ecomp)) { |
| 452 | if (addl_desc_ptr) |
| 453 | ses_process_descriptor( |
| 454 | ecomp, |
| 455 | addl_desc_ptr); |
| 456 | if (create) |
| 457 | enclosure_component_register( |
| 458 | ecomp); |
| 459 | } |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 460 | } |
| 461 | if (desc_ptr) |
| 462 | desc_ptr += len; |
| 463 | |
| 464 | if (addl_desc_ptr) |
| 465 | addl_desc_ptr += addl_desc_ptr[1] + 2; |
| 466 | |
| 467 | } |
| 468 | } |
| 469 | kfree(buf); |
| 470 | kfree(hdr_buf); |
| 471 | } |
| 472 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 473 | static void ses_match_to_enclosure(struct enclosure_device *edev, |
| 474 | struct scsi_device *sdev) |
| 475 | { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 476 | unsigned char *desc; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 477 | struct efd efd = { |
| 478 | .addr = 0, |
| 479 | }; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 480 | |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 481 | ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0); |
| 482 | |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 483 | if (!sdev->vpd_pg83_len) |
| 484 | return; |
James Bottomley | 671a99c | 2008-07-29 11:38:25 -0500 | [diff] [blame] | 485 | |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 486 | desc = sdev->vpd_pg83 + 4; |
| 487 | while (desc < sdev->vpd_pg83 + sdev->vpd_pg83_len) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 488 | enum scsi_protocol proto = desc[0] >> 4; |
| 489 | u8 code_set = desc[0] & 0x0f; |
| 490 | u8 piv = desc[1] & 0x80; |
| 491 | u8 assoc = (desc[1] & 0x30) >> 4; |
| 492 | u8 type = desc[1] & 0x0f; |
| 493 | u8 len = desc[3]; |
| 494 | |
Roel Kluin | b3f1f9a | 2009-02-17 16:59:24 +0100 | [diff] [blame] | 495 | if (piv && code_set == 1 && assoc == 1 |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 496 | && proto == SCSI_PROTOCOL_SAS && type == 3 && len == 8) |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 497 | efd.addr = get_unaligned_be64(&desc[4]); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 498 | |
| 499 | desc += len + 4; |
| 500 | } |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 501 | if (efd.addr) { |
| 502 | efd.dev = &sdev->sdev_gendev; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 503 | |
Hannes Reinecke | c38c007 | 2014-03-15 09:51:51 +0100 | [diff] [blame] | 504 | enclosure_for_each_device(ses_enclosure_find_by_addr, &efd); |
| 505 | } |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 506 | } |
| 507 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 508 | static int ses_intf_add(struct device *cdev, |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 509 | struct class_interface *intf) |
| 510 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 511 | struct scsi_device *sdev = to_scsi_device(cdev->parent); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 512 | struct scsi_device *tmp_sdev; |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 513 | unsigned char *buf = NULL, *hdr_buf, *type_ptr; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 514 | struct ses_device *ses_dev; |
| 515 | u32 result; |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 516 | int i, types, len, components = 0; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 517 | int err = -ENOMEM; |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 518 | int num_enclosures; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 519 | struct enclosure_device *edev; |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 520 | struct ses_component *scomp = NULL; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 521 | |
| 522 | if (!scsi_device_enclosure(sdev)) { |
| 523 | /* not an enclosure, but might be in one */ |
James Bottomley | 163f52b | 2009-08-01 00:39:36 +0000 | [diff] [blame] | 524 | struct enclosure_device *prev = NULL; |
| 525 | |
| 526 | while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 527 | ses_match_to_enclosure(edev, sdev); |
James Bottomley | 163f52b | 2009-08-01 00:39:36 +0000 | [diff] [blame] | 528 | prev = edev; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 529 | } |
| 530 | return -ENODEV; |
| 531 | } |
| 532 | |
| 533 | /* TYPE_ENCLOSURE prints a message in probe */ |
| 534 | if (sdev->type != TYPE_ENCLOSURE) |
| 535 | sdev_printk(KERN_NOTICE, sdev, "Embedded Enclosure Device\n"); |
| 536 | |
| 537 | ses_dev = kzalloc(sizeof(*ses_dev), GFP_KERNEL); |
| 538 | hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL); |
| 539 | if (!hdr_buf || !ses_dev) |
| 540 | goto err_init_free; |
| 541 | |
| 542 | result = ses_recv_diag(sdev, 1, hdr_buf, INIT_ALLOC_SIZE); |
| 543 | if (result) |
| 544 | goto recv_failed; |
| 545 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 546 | len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; |
| 547 | buf = kzalloc(len, GFP_KERNEL); |
| 548 | if (!buf) |
| 549 | goto err_free; |
| 550 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 551 | result = ses_recv_diag(sdev, 1, buf, len); |
| 552 | if (result) |
| 553 | goto recv_failed; |
| 554 | |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 555 | types = 0; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 556 | |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 557 | /* we always have one main enclosure and the rest are referred |
| 558 | * to as secondary subenclosures */ |
| 559 | num_enclosures = buf[1] + 1; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 560 | |
James Bottomley | 8c3adc7 | 2011-03-18 11:24:23 -0400 | [diff] [blame] | 561 | /* begin at the enclosure descriptor */ |
| 562 | type_ptr = buf + 8; |
| 563 | /* skip all the enclosure descriptors */ |
| 564 | for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) { |
| 565 | types += type_ptr[2]; |
| 566 | type_ptr += type_ptr[3] + 4; |
| 567 | } |
| 568 | |
| 569 | ses_dev->page1_types = type_ptr; |
| 570 | ses_dev->page1_num_types = types; |
| 571 | |
| 572 | for (i = 0; i < types && type_ptr < buf + len; i++, type_ptr += 4) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 573 | if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE || |
| 574 | type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) |
| 575 | components += type_ptr[1]; |
| 576 | } |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 577 | ses_dev->page1 = buf; |
| 578 | ses_dev->page1_len = len; |
| 579 | buf = NULL; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 580 | |
| 581 | result = ses_recv_diag(sdev, 2, hdr_buf, INIT_ALLOC_SIZE); |
| 582 | if (result) |
| 583 | goto recv_failed; |
| 584 | |
| 585 | len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; |
| 586 | buf = kzalloc(len, GFP_KERNEL); |
| 587 | if (!buf) |
| 588 | goto err_free; |
| 589 | |
| 590 | /* make sure getting page 2 actually works */ |
| 591 | result = ses_recv_diag(sdev, 2, buf, len); |
| 592 | if (result) |
| 593 | goto recv_failed; |
| 594 | ses_dev->page2 = buf; |
| 595 | ses_dev->page2_len = len; |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 596 | buf = NULL; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 597 | |
| 598 | /* The additional information page --- allows us |
| 599 | * to match up the devices */ |
| 600 | result = ses_recv_diag(sdev, 10, hdr_buf, INIT_ALLOC_SIZE); |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 601 | if (!result) { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 602 | |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 603 | len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; |
| 604 | buf = kzalloc(len, GFP_KERNEL); |
| 605 | if (!buf) |
| 606 | goto err_free; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 607 | |
Yinghai Lu | 691b477 | 2008-02-13 16:25:16 -0800 | [diff] [blame] | 608 | result = ses_recv_diag(sdev, 10, buf, len); |
| 609 | if (result) |
| 610 | goto recv_failed; |
| 611 | ses_dev->page10 = buf; |
| 612 | ses_dev->page10_len = len; |
| 613 | buf = NULL; |
| 614 | } |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 615 | scomp = kzalloc(sizeof(struct ses_component) * components, GFP_KERNEL); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 616 | if (!scomp) |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 617 | goto err_free; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 618 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 619 | edev = enclosure_register(cdev->parent, dev_name(&sdev->sdev_gendev), |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 620 | components, &ses_enclosure_callbacks); |
| 621 | if (IS_ERR(edev)) { |
| 622 | err = PTR_ERR(edev); |
| 623 | goto err_free; |
| 624 | } |
| 625 | |
Julia Lawall | 9b3a654 | 2010-03-10 15:20:42 -0800 | [diff] [blame] | 626 | kfree(hdr_buf); |
| 627 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 628 | edev->scratch = ses_dev; |
| 629 | for (i = 0; i < components; i++) |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 630 | edev->component[i].scratch = scomp + i; |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 631 | |
James Bottomley | 21fab1d | 2009-08-01 00:43:59 +0000 | [diff] [blame] | 632 | ses_enclosure_data_process(edev, sdev, 1); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 633 | |
| 634 | /* see if there are any devices matching before |
| 635 | * we found the enclosure */ |
| 636 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 637 | if (tmp_sdev->lun != 0 || scsi_device_enclosure(tmp_sdev)) |
| 638 | continue; |
| 639 | ses_match_to_enclosure(edev, tmp_sdev); |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | |
| 644 | recv_failed: |
| 645 | sdev_printk(KERN_ERR, sdev, "Failed to get diagnostic page 0x%x\n", |
| 646 | result); |
| 647 | err = -ENODEV; |
| 648 | err_free: |
| 649 | kfree(buf); |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 650 | kfree(scomp); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 651 | kfree(ses_dev->page10); |
| 652 | kfree(ses_dev->page2); |
| 653 | kfree(ses_dev->page1); |
| 654 | err_init_free: |
| 655 | kfree(ses_dev); |
| 656 | kfree(hdr_buf); |
| 657 | sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n", err); |
| 658 | return err; |
| 659 | } |
| 660 | |
| 661 | static int ses_remove(struct device *dev) |
| 662 | { |
| 663 | return 0; |
| 664 | } |
| 665 | |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 666 | static void ses_intf_remove_component(struct scsi_device *sdev) |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 667 | { |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 668 | struct enclosure_device *edev, *prev = NULL; |
| 669 | |
| 670 | while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) { |
| 671 | prev = edev; |
| 672 | if (!enclosure_remove_device(edev, &sdev->sdev_gendev)) |
| 673 | break; |
| 674 | } |
| 675 | if (edev) |
| 676 | put_device(&edev->edev); |
| 677 | } |
| 678 | |
| 679 | static void ses_intf_remove_enclosure(struct scsi_device *sdev) |
| 680 | { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 681 | struct enclosure_device *edev; |
| 682 | struct ses_device *ses_dev; |
| 683 | |
James Bottomley | 163f52b | 2009-08-01 00:39:36 +0000 | [diff] [blame] | 684 | /* exact match to this enclosure */ |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 685 | edev = enclosure_find(&sdev->sdev_gendev, NULL); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 686 | if (!edev) |
| 687 | return; |
| 688 | |
| 689 | ses_dev = edev->scratch; |
| 690 | edev->scratch = NULL; |
| 691 | |
Yinghai Lu | 7c46c20a | 2008-02-10 23:25:25 -0800 | [diff] [blame] | 692 | kfree(ses_dev->page10); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 693 | kfree(ses_dev->page1); |
| 694 | kfree(ses_dev->page2); |
| 695 | kfree(ses_dev); |
| 696 | |
| 697 | kfree(edev->component[0].scratch); |
| 698 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 699 | put_device(&edev->edev); |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 700 | enclosure_unregister(edev); |
| 701 | } |
| 702 | |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 703 | static void ses_intf_remove(struct device *cdev, |
| 704 | struct class_interface *intf) |
| 705 | { |
| 706 | struct scsi_device *sdev = to_scsi_device(cdev->parent); |
| 707 | |
| 708 | if (!scsi_device_enclosure(sdev)) |
| 709 | ses_intf_remove_component(sdev); |
| 710 | else |
| 711 | ses_intf_remove_enclosure(sdev); |
| 712 | } |
| 713 | |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 714 | static struct class_interface ses_interface = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 715 | .add_dev = ses_intf_add, |
| 716 | .remove_dev = ses_intf_remove, |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | static struct scsi_driver ses_template = { |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 720 | .gendrv = { |
| 721 | .name = "ses", |
Christoph Hellwig | 3af6b35 | 2014-11-12 18:34:51 +0100 | [diff] [blame] | 722 | .owner = THIS_MODULE, |
James Bottomley | 9927c68 | 2008-02-03 15:48:56 -0600 | [diff] [blame] | 723 | .probe = ses_probe, |
| 724 | .remove = ses_remove, |
| 725 | }, |
| 726 | }; |
| 727 | |
| 728 | static int __init ses_init(void) |
| 729 | { |
| 730 | int err; |
| 731 | |
| 732 | err = scsi_register_interface(&ses_interface); |
| 733 | if (err) |
| 734 | return err; |
| 735 | |
| 736 | err = scsi_register_driver(&ses_template.gendrv); |
| 737 | if (err) |
| 738 | goto out_unreg; |
| 739 | |
| 740 | return 0; |
| 741 | |
| 742 | out_unreg: |
| 743 | scsi_unregister_interface(&ses_interface); |
| 744 | return err; |
| 745 | } |
| 746 | |
| 747 | static void __exit ses_exit(void) |
| 748 | { |
| 749 | scsi_unregister_driver(&ses_template.gendrv); |
| 750 | scsi_unregister_interface(&ses_interface); |
| 751 | } |
| 752 | |
| 753 | module_init(ses_init); |
| 754 | module_exit(ses_exit); |
| 755 | |
| 756 | MODULE_ALIAS_SCSI_DEVICE(TYPE_ENCLOSURE); |
| 757 | |
| 758 | MODULE_AUTHOR("James Bottomley"); |
| 759 | MODULE_DESCRIPTION("SCSI Enclosure Services (ses) driver"); |
| 760 | MODULE_LICENSE("GPL v2"); |