Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1 | /* |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 2 | * Copyright (C) 2005-2006 Dell Inc. |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 3 | * Released under GPL v2. |
| 4 | * |
| 5 | * Serial Attached SCSI (SAS) transport class. |
| 6 | * |
| 7 | * The SAS transport class contains common code to deal with SAS HBAs, |
| 8 | * an aproximated representation of SAS topologies in the driver model, |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 9 | * and various sysfs attributes to expose these topologies and management |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 10 | * interfaces to userspace. |
| 11 | * |
| 12 | * In addition to the basic SCSI core objects this transport class |
| 13 | * introduces two additional intermediate objects: The SAS PHY |
| 14 | * as represented by struct sas_phy defines an "outgoing" PHY on |
| 15 | * a SAS HBA or Expander, and the SAS remote PHY represented by |
| 16 | * struct sas_rphy defines an "incoming" PHY on a SAS Expander or |
| 17 | * end device. Note that this is purely a software concept, the |
| 18 | * underlying hardware for a PHY and a remote PHY is the exactly |
| 19 | * the same. |
| 20 | * |
| 21 | * There is no concept of a SAS port in this code, users can see |
| 22 | * what PHYs form a wide port based on the port_identifier attribute, |
| 23 | * which is the same for all PHYs in a port. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/module.h> |
Al Viro | f6a5703 | 2006-10-18 01:47:25 -0400 | [diff] [blame] | 28 | #include <linux/jiffies.h> |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 29 | #include <linux/err.h> |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 30 | #include <linux/slab.h> |
| 31 | #include <linux/string.h> |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 32 | #include <linux/blkdev.h> |
| 33 | #include <linux/bsg.h> |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 34 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 35 | #include <scsi/scsi.h> |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 36 | #include <scsi/scsi_request.h> |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 37 | #include <scsi/scsi_device.h> |
| 38 | #include <scsi/scsi_host.h> |
| 39 | #include <scsi/scsi_transport.h> |
| 40 | #include <scsi/scsi_transport_sas.h> |
| 41 | |
James Bottomley | d6159c1 | 2006-03-27 16:45:34 -0600 | [diff] [blame] | 42 | #include "scsi_sas_internal.h" |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 43 | struct sas_host_attrs { |
| 44 | struct list_head rphy_list; |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 45 | struct mutex lock; |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 46 | struct request_queue *q; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 47 | u32 next_target_id; |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 48 | u32 next_expander_id; |
James Bottomley | c9fefeb | 2006-07-02 11:10:18 -0500 | [diff] [blame] | 49 | int next_port_id; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 50 | }; |
| 51 | #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data) |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | * Hack to allow attributes of the same name in different objects. |
| 56 | */ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 57 | #define SAS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 58 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 59 | __ATTR(_name,_mode,_show,_store) |
| 60 | |
| 61 | |
| 62 | /* |
| 63 | * Pretty printing helpers |
| 64 | */ |
| 65 | |
| 66 | #define sas_bitfield_name_match(title, table) \ |
| 67 | static ssize_t \ |
| 68 | get_sas_##title##_names(u32 table_key, char *buf) \ |
| 69 | { \ |
| 70 | char *prefix = ""; \ |
| 71 | ssize_t len = 0; \ |
| 72 | int i; \ |
| 73 | \ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 74 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 75 | if (table[i].value & table_key) { \ |
| 76 | len += sprintf(buf + len, "%s%s", \ |
| 77 | prefix, table[i].name); \ |
| 78 | prefix = ", "; \ |
| 79 | } \ |
| 80 | } \ |
| 81 | len += sprintf(buf + len, "\n"); \ |
| 82 | return len; \ |
| 83 | } |
| 84 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 85 | #define sas_bitfield_name_set(title, table) \ |
| 86 | static ssize_t \ |
| 87 | set_sas_##title##_names(u32 *table_key, const char *buf) \ |
| 88 | { \ |
| 89 | ssize_t len = 0; \ |
| 90 | int i; \ |
| 91 | \ |
| 92 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
| 93 | len = strlen(table[i].name); \ |
| 94 | if (strncmp(buf, table[i].name, len) == 0 && \ |
| 95 | (buf[len] == '\n' || buf[len] == '\0')) { \ |
| 96 | *table_key = table[i].value; \ |
| 97 | return 0; \ |
| 98 | } \ |
| 99 | } \ |
| 100 | return -EINVAL; \ |
| 101 | } |
| 102 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 103 | #define sas_bitfield_name_search(title, table) \ |
| 104 | static ssize_t \ |
| 105 | get_sas_##title##_names(u32 table_key, char *buf) \ |
| 106 | { \ |
| 107 | ssize_t len = 0; \ |
| 108 | int i; \ |
| 109 | \ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 110 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 111 | if (table[i].value == table_key) { \ |
| 112 | len += sprintf(buf + len, "%s", \ |
| 113 | table[i].name); \ |
| 114 | break; \ |
| 115 | } \ |
| 116 | } \ |
| 117 | len += sprintf(buf + len, "\n"); \ |
| 118 | return len; \ |
| 119 | } |
| 120 | |
| 121 | static struct { |
| 122 | u32 value; |
| 123 | char *name; |
| 124 | } sas_device_type_names[] = { |
| 125 | { SAS_PHY_UNUSED, "unused" }, |
| 126 | { SAS_END_DEVICE, "end device" }, |
| 127 | { SAS_EDGE_EXPANDER_DEVICE, "edge expander" }, |
| 128 | { SAS_FANOUT_EXPANDER_DEVICE, "fanout expander" }, |
| 129 | }; |
| 130 | sas_bitfield_name_search(device_type, sas_device_type_names) |
| 131 | |
| 132 | |
| 133 | static struct { |
| 134 | u32 value; |
| 135 | char *name; |
| 136 | } sas_protocol_names[] = { |
| 137 | { SAS_PROTOCOL_SATA, "sata" }, |
| 138 | { SAS_PROTOCOL_SMP, "smp" }, |
| 139 | { SAS_PROTOCOL_STP, "stp" }, |
| 140 | { SAS_PROTOCOL_SSP, "ssp" }, |
| 141 | }; |
| 142 | sas_bitfield_name_match(protocol, sas_protocol_names) |
| 143 | |
| 144 | static struct { |
| 145 | u32 value; |
| 146 | char *name; |
| 147 | } sas_linkspeed_names[] = { |
| 148 | { SAS_LINK_RATE_UNKNOWN, "Unknown" }, |
| 149 | { SAS_PHY_DISABLED, "Phy disabled" }, |
| 150 | { SAS_LINK_RATE_FAILED, "Link Rate failed" }, |
| 151 | { SAS_SATA_SPINUP_HOLD, "Spin-up hold" }, |
| 152 | { SAS_LINK_RATE_1_5_GBPS, "1.5 Gbit" }, |
| 153 | { SAS_LINK_RATE_3_0_GBPS, "3.0 Gbit" }, |
James Bottomley | 7e6dff6 | 2006-03-02 14:12:56 -0600 | [diff] [blame] | 154 | { SAS_LINK_RATE_6_0_GBPS, "6.0 Gbit" }, |
Sreekanth Reddy | d84fd39 | 2012-11-30 07:43:11 +0530 | [diff] [blame] | 155 | { SAS_LINK_RATE_12_0_GBPS, "12.0 Gbit" }, |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 156 | }; |
| 157 | sas_bitfield_name_search(linkspeed, sas_linkspeed_names) |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 158 | sas_bitfield_name_set(linkspeed, sas_linkspeed_names) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 159 | |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 160 | static struct sas_end_device *sas_sdev_to_rdev(struct scsi_device *sdev) |
| 161 | { |
| 162 | struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target); |
| 163 | struct sas_end_device *rdev; |
| 164 | |
| 165 | BUG_ON(rphy->identify.device_type != SAS_END_DEVICE); |
| 166 | |
| 167 | rdev = rphy_to_end_device(rphy); |
| 168 | return rdev; |
| 169 | } |
| 170 | |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 171 | static void sas_smp_request(struct request_queue *q, struct Scsi_Host *shost, |
| 172 | struct sas_rphy *rphy) |
| 173 | { |
| 174 | struct request *req; |
| 175 | int ret; |
| 176 | int (*handler)(struct Scsi_Host *, struct sas_rphy *, struct request *); |
| 177 | |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 178 | while ((req = blk_fetch_request(q)) != NULL) { |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 179 | spin_unlock_irq(q->queue_lock); |
| 180 | |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 181 | scsi_req(req)->resid_len = blk_rq_bytes(req); |
| 182 | if (req->next_rq) |
| 183 | scsi_req(req->next_rq)->resid_len = |
| 184 | blk_rq_bytes(req->next_rq); |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 185 | handler = to_sas_internal(shost->transportt)->f->smp_handler; |
| 186 | ret = handler(shost, rphy, req); |
James Bottomley | 2d507a0 | 2007-12-29 10:59:53 -0600 | [diff] [blame] | 187 | req->errors = ret; |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 188 | |
FUJITA Tomonori | 93bdcba | 2009-06-17 15:10:10 +0900 | [diff] [blame] | 189 | blk_end_request_all(req, ret); |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 190 | |
FUJITA Tomonori | 93bdcba | 2009-06-17 15:10:10 +0900 | [diff] [blame] | 191 | spin_lock_irq(q->queue_lock); |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
| 195 | static void sas_host_smp_request(struct request_queue *q) |
| 196 | { |
| 197 | sas_smp_request(q, (struct Scsi_Host *)q->queuedata, NULL); |
| 198 | } |
| 199 | |
| 200 | static void sas_non_host_smp_request(struct request_queue *q) |
| 201 | { |
| 202 | struct sas_rphy *rphy = q->queuedata; |
| 203 | sas_smp_request(q, rphy_to_shost(rphy), rphy); |
| 204 | } |
| 205 | |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 206 | static void sas_host_release(struct device *dev) |
| 207 | { |
| 208 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 209 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 210 | struct request_queue *q = sas_host->q; |
| 211 | |
| 212 | if (q) |
| 213 | blk_cleanup_queue(q); |
| 214 | } |
| 215 | |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 216 | static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy) |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 217 | { |
| 218 | struct request_queue *q; |
| 219 | int error; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 220 | struct device *dev; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 221 | char namebuf[20]; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 222 | const char *name; |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 223 | void (*release)(struct device *); |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 224 | |
| 225 | if (!to_sas_internal(shost->transportt)->f->smp_handler) { |
| 226 | printk("%s can't handle SMP requests\n", shost->hostt->name); |
| 227 | return 0; |
| 228 | } |
| 229 | |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 230 | q = blk_alloc_queue(GFP_KERNEL); |
| 231 | if (!q) |
| 232 | return -ENOMEM; |
| 233 | q->cmd_size = sizeof(struct scsi_request); |
| 234 | |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 235 | if (rphy) { |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 236 | q->request_fn = sas_non_host_smp_request; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 237 | dev = &rphy->dev; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 238 | name = dev_name(dev); |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 239 | release = NULL; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 240 | } else { |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 241 | q->request_fn = sas_host_smp_request; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 242 | dev = &shost->shost_gendev; |
| 243 | snprintf(namebuf, sizeof(namebuf), |
| 244 | "sas_host%d", shost->host_no); |
| 245 | name = namebuf; |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 246 | release = sas_host_release; |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 247 | } |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 248 | error = blk_init_allocated_queue(q); |
| 249 | if (error) |
| 250 | goto out_cleanup_queue; |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 251 | |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 252 | error = bsg_register_queue(q, dev, name, release); |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 253 | if (error) |
| 254 | goto out_cleanup_queue; |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 255 | |
| 256 | if (rphy) |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 257 | rphy->q = q; |
| 258 | else |
| 259 | to_sas_host_attrs(shost)->q = q; |
| 260 | |
| 261 | if (rphy) |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 262 | q->queuedata = rphy; |
| 263 | else |
| 264 | q->queuedata = shost; |
| 265 | |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 266 | queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 267 | return 0; |
Omar Sandoval | bd1599d | 2017-02-21 10:03:50 -0800 | [diff] [blame] | 268 | |
| 269 | out_cleanup_queue: |
| 270 | blk_cleanup_queue(q); |
| 271 | return error; |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 272 | } |
| 273 | |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 274 | static void sas_bsg_remove(struct Scsi_Host *shost, struct sas_rphy *rphy) |
| 275 | { |
| 276 | struct request_queue *q; |
| 277 | |
| 278 | if (rphy) |
| 279 | q = rphy->q; |
| 280 | else |
| 281 | q = to_sas_host_attrs(shost)->q; |
| 282 | |
| 283 | if (!q) |
| 284 | return; |
| 285 | |
| 286 | bsg_unregister_queue(q); |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 289 | /* |
| 290 | * SAS host attributes |
| 291 | */ |
| 292 | |
James Bottomley | 37be6ee | 2005-09-09 18:38:27 -0500 | [diff] [blame] | 293 | static int sas_host_setup(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 294 | struct device *cdev) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 295 | { |
| 296 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 297 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 298 | |
| 299 | INIT_LIST_HEAD(&sas_host->rphy_list); |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 300 | mutex_init(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 301 | sas_host->next_target_id = 0; |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 302 | sas_host->next_expander_id = 0; |
James Bottomley | c9fefeb | 2006-07-02 11:10:18 -0500 | [diff] [blame] | 303 | sas_host->next_port_id = 0; |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 304 | |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 305 | if (sas_bsg_initialize(shost, NULL)) |
FUJITA Tomonori | 7aa68e8 | 2007-07-09 12:52:06 +0900 | [diff] [blame] | 306 | dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n", |
| 307 | shost->host_no); |
| 308 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 312 | static int sas_host_remove(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 313 | struct device *cdev) |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 314 | { |
| 315 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 316 | |
| 317 | sas_bsg_remove(shost, NULL); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 322 | static DECLARE_TRANSPORT_CLASS(sas_host_class, |
James Bottomley | b6aff66 | 2007-07-20 11:10:05 -0500 | [diff] [blame] | 323 | "sas_host", sas_host_setup, sas_host_remove, NULL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 324 | |
| 325 | static int sas_host_match(struct attribute_container *cont, |
| 326 | struct device *dev) |
| 327 | { |
| 328 | struct Scsi_Host *shost; |
| 329 | struct sas_internal *i; |
| 330 | |
| 331 | if (!scsi_is_host_device(dev)) |
| 332 | return 0; |
| 333 | shost = dev_to_shost(dev); |
| 334 | |
| 335 | if (!shost->transportt) |
| 336 | return 0; |
| 337 | if (shost->transportt->host_attrs.ac.class != |
| 338 | &sas_host_class.class) |
| 339 | return 0; |
| 340 | |
| 341 | i = to_sas_internal(shost->transportt); |
| 342 | return &i->t.host_attrs.ac == cont; |
| 343 | } |
| 344 | |
| 345 | static int do_sas_phy_delete(struct device *dev, void *data) |
| 346 | { |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 347 | int pass = (int)(unsigned long)data; |
| 348 | |
| 349 | if (pass == 0 && scsi_is_sas_port(dev)) |
| 350 | sas_port_delete(dev_to_sas_port(dev)); |
| 351 | else if (pass == 1 && scsi_is_sas_phy(dev)) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 352 | sas_phy_delete(dev_to_phy(dev)); |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 357 | * sas_remove_children - tear down a devices SAS data structures |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 358 | * @dev: device belonging to the sas object |
| 359 | * |
| 360 | * Removes all SAS PHYs and remote PHYs for a given object |
| 361 | */ |
| 362 | void sas_remove_children(struct device *dev) |
| 363 | { |
| 364 | device_for_each_child(dev, (void *)0, do_sas_phy_delete); |
| 365 | device_for_each_child(dev, (void *)1, do_sas_phy_delete); |
| 366 | } |
| 367 | EXPORT_SYMBOL(sas_remove_children); |
| 368 | |
| 369 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 370 | * sas_remove_host - tear down a Scsi_Host's SAS data structures |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 371 | * @shost: Scsi Host that is torn down |
| 372 | * |
Johannes Thumshirn | c5ce0ab | 2017-04-21 14:11:41 +0200 | [diff] [blame^] | 373 | * Removes all SAS PHYs and remote PHYs for a given Scsi_Host and remove the |
| 374 | * Scsi_Host as well. |
| 375 | * |
| 376 | * Note: Do not call scsi_remove_host() on the Scsi_Host any more, as it is |
| 377 | * already removed. |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 378 | */ |
| 379 | void sas_remove_host(struct Scsi_Host *shost) |
| 380 | { |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 381 | sas_remove_children(&shost->shost_gendev); |
Johannes Thumshirn | c5ce0ab | 2017-04-21 14:11:41 +0200 | [diff] [blame^] | 382 | scsi_remove_host(shost); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 383 | } |
| 384 | EXPORT_SYMBOL(sas_remove_host); |
| 385 | |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 386 | /** |
James Bottomley | bcf508c | 2015-12-09 11:13:35 -0800 | [diff] [blame] | 387 | * sas_get_address - return the SAS address of the device |
| 388 | * @sdev: scsi device |
| 389 | * |
| 390 | * Returns the SAS address of the scsi device |
| 391 | */ |
| 392 | u64 sas_get_address(struct scsi_device *sdev) |
| 393 | { |
| 394 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
| 395 | |
| 396 | return rdev->rphy.identify.sas_address; |
| 397 | } |
| 398 | EXPORT_SYMBOL(sas_get_address); |
| 399 | |
| 400 | /** |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 401 | * sas_tlr_supported - checking TLR bit in vpd 0x90 |
| 402 | * @sdev: scsi device struct |
| 403 | * |
| 404 | * Check Transport Layer Retries are supported or not. |
| 405 | * If vpd page 0x90 is present, TRL is supported. |
| 406 | * |
| 407 | */ |
| 408 | unsigned int |
| 409 | sas_tlr_supported(struct scsi_device *sdev) |
| 410 | { |
| 411 | const int vpd_len = 32; |
| 412 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
| 413 | char *buffer = kzalloc(vpd_len, GFP_KERNEL); |
| 414 | int ret = 0; |
| 415 | |
| 416 | if (scsi_get_vpd_page(sdev, 0x90, buffer, vpd_len)) |
| 417 | goto out; |
| 418 | |
| 419 | /* |
| 420 | * Magic numbers: the VPD Protocol page (0x90) |
| 421 | * has a 4 byte header and then one entry per device port |
| 422 | * the TLR bit is at offset 8 on each port entry |
| 423 | * if we take the first port, that's at total offset 12 |
| 424 | */ |
| 425 | ret = buffer[12] & 0x01; |
| 426 | |
| 427 | out: |
| 428 | kfree(buffer); |
| 429 | rdev->tlr_supported = ret; |
| 430 | return ret; |
| 431 | |
| 432 | } |
| 433 | EXPORT_SYMBOL_GPL(sas_tlr_supported); |
| 434 | |
| 435 | /** |
| 436 | * sas_disable_tlr - setting TLR flags |
| 437 | * @sdev: scsi device struct |
| 438 | * |
| 439 | * Seting tlr_enabled flag to 0. |
| 440 | * |
| 441 | */ |
| 442 | void |
| 443 | sas_disable_tlr(struct scsi_device *sdev) |
| 444 | { |
| 445 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
| 446 | |
| 447 | rdev->tlr_enabled = 0; |
| 448 | } |
| 449 | EXPORT_SYMBOL_GPL(sas_disable_tlr); |
| 450 | |
| 451 | /** |
| 452 | * sas_enable_tlr - setting TLR flags |
| 453 | * @sdev: scsi device struct |
| 454 | * |
| 455 | * Seting tlr_enabled flag 1. |
| 456 | * |
| 457 | */ |
| 458 | void sas_enable_tlr(struct scsi_device *sdev) |
| 459 | { |
| 460 | unsigned int tlr_supported = 0; |
| 461 | tlr_supported = sas_tlr_supported(sdev); |
| 462 | |
| 463 | if (tlr_supported) { |
| 464 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
| 465 | |
| 466 | rdev->tlr_enabled = 1; |
| 467 | } |
| 468 | |
| 469 | return; |
| 470 | } |
| 471 | EXPORT_SYMBOL_GPL(sas_enable_tlr); |
| 472 | |
| 473 | unsigned int sas_is_tlr_enabled(struct scsi_device *sdev) |
| 474 | { |
| 475 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
| 476 | return rdev->tlr_enabled; |
| 477 | } |
| 478 | EXPORT_SYMBOL_GPL(sas_is_tlr_enabled); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 479 | |
| 480 | /* |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 481 | * SAS Phy attributes |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 482 | */ |
| 483 | |
| 484 | #define sas_phy_show_simple(field, name, format_string, cast) \ |
| 485 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 486 | show_sas_phy_##name(struct device *dev, \ |
| 487 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 488 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 489 | struct sas_phy *phy = transport_class_to_phy(dev); \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 490 | \ |
| 491 | return snprintf(buf, 20, format_string, cast phy->field); \ |
| 492 | } |
| 493 | |
| 494 | #define sas_phy_simple_attr(field, name, format_string, type) \ |
| 495 | sas_phy_show_simple(field, name, format_string, (type)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 496 | static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 497 | |
| 498 | #define sas_phy_show_protocol(field, name) \ |
| 499 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 500 | show_sas_phy_##name(struct device *dev, \ |
| 501 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 502 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 503 | struct sas_phy *phy = transport_class_to_phy(dev); \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 504 | \ |
| 505 | if (!phy->field) \ |
| 506 | return snprintf(buf, 20, "none\n"); \ |
| 507 | return get_sas_protocol_names(phy->field, buf); \ |
| 508 | } |
| 509 | |
| 510 | #define sas_phy_protocol_attr(field, name) \ |
| 511 | sas_phy_show_protocol(field, name) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 512 | static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 513 | |
| 514 | #define sas_phy_show_linkspeed(field) \ |
| 515 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 516 | show_sas_phy_##field(struct device *dev, \ |
| 517 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 518 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 519 | struct sas_phy *phy = transport_class_to_phy(dev); \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 520 | \ |
| 521 | return get_sas_linkspeed_names(phy->field, buf); \ |
| 522 | } |
| 523 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 524 | /* Fudge to tell if we're minimum or maximum */ |
| 525 | #define sas_phy_store_linkspeed(field) \ |
| 526 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 527 | store_sas_phy_##field(struct device *dev, \ |
| 528 | struct device_attribute *attr, \ |
| 529 | const char *buf, size_t count) \ |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 530 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 531 | struct sas_phy *phy = transport_class_to_phy(dev); \ |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 532 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \ |
| 533 | struct sas_internal *i = to_sas_internal(shost->transportt); \ |
| 534 | u32 value; \ |
| 535 | struct sas_phy_linkrates rates = {0}; \ |
| 536 | int error; \ |
| 537 | \ |
| 538 | error = set_sas_linkspeed_names(&value, buf); \ |
| 539 | if (error) \ |
| 540 | return error; \ |
| 541 | rates.field = value; \ |
| 542 | error = i->f->set_phy_speed(phy, &rates); \ |
| 543 | \ |
| 544 | return error ? error : count; \ |
| 545 | } |
| 546 | |
| 547 | #define sas_phy_linkspeed_rw_attr(field) \ |
| 548 | sas_phy_show_linkspeed(field) \ |
| 549 | sas_phy_store_linkspeed(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 550 | static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, \ |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 551 | store_sas_phy_##field) |
| 552 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 553 | #define sas_phy_linkspeed_attr(field) \ |
| 554 | sas_phy_show_linkspeed(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 555 | static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 556 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 557 | |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 558 | #define sas_phy_show_linkerror(field) \ |
| 559 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 560 | show_sas_phy_##field(struct device *dev, \ |
| 561 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 562 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 563 | struct sas_phy *phy = transport_class_to_phy(dev); \ |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 564 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \ |
| 565 | struct sas_internal *i = to_sas_internal(shost->transportt); \ |
| 566 | int error; \ |
| 567 | \ |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 568 | error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \ |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 569 | if (error) \ |
| 570 | return error; \ |
| 571 | return snprintf(buf, 20, "%u\n", phy->field); \ |
| 572 | } |
| 573 | |
| 574 | #define sas_phy_linkerror_attr(field) \ |
| 575 | sas_phy_show_linkerror(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 576 | static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL) |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 577 | |
| 578 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 579 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 580 | show_sas_device_type(struct device *dev, |
| 581 | struct device_attribute *attr, char *buf) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 582 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 583 | struct sas_phy *phy = transport_class_to_phy(dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 584 | |
| 585 | if (!phy->identify.device_type) |
| 586 | return snprintf(buf, 20, "none\n"); |
| 587 | return get_sas_device_type_names(phy->identify.device_type, buf); |
| 588 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 589 | static DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 590 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 591 | static ssize_t do_sas_phy_enable(struct device *dev, |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 592 | size_t count, int enable) |
| 593 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 594 | struct sas_phy *phy = transport_class_to_phy(dev); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 595 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 596 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 597 | int error; |
| 598 | |
| 599 | error = i->f->phy_enable(phy, enable); |
| 600 | if (error) |
| 601 | return error; |
| 602 | phy->enabled = enable; |
| 603 | return count; |
| 604 | }; |
| 605 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 606 | static ssize_t |
| 607 | store_sas_phy_enable(struct device *dev, struct device_attribute *attr, |
| 608 | const char *buf, size_t count) |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 609 | { |
| 610 | if (count < 1) |
| 611 | return -EINVAL; |
| 612 | |
| 613 | switch (buf[0]) { |
| 614 | case '0': |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 615 | do_sas_phy_enable(dev, count, 0); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 616 | break; |
| 617 | case '1': |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 618 | do_sas_phy_enable(dev, count, 1); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 619 | break; |
| 620 | default: |
| 621 | return -EINVAL; |
| 622 | } |
| 623 | |
| 624 | return count; |
| 625 | } |
| 626 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 627 | static ssize_t |
| 628 | show_sas_phy_enable(struct device *dev, struct device_attribute *attr, |
| 629 | char *buf) |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 630 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 631 | struct sas_phy *phy = transport_class_to_phy(dev); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 632 | |
| 633 | return snprintf(buf, 20, "%d", phy->enabled); |
| 634 | } |
| 635 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 636 | static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, show_sas_phy_enable, |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 637 | store_sas_phy_enable); |
| 638 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 639 | static ssize_t |
| 640 | do_sas_phy_reset(struct device *dev, size_t count, int hard_reset) |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 641 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 642 | struct sas_phy *phy = transport_class_to_phy(dev); |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 643 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 644 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 645 | int error; |
| 646 | |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 647 | error = i->f->phy_reset(phy, hard_reset); |
| 648 | if (error) |
| 649 | return error; |
Dan Williams | 16d3db1 | 2012-01-30 22:53:51 -0800 | [diff] [blame] | 650 | phy->enabled = 1; |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 651 | return count; |
| 652 | }; |
| 653 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 654 | static ssize_t |
| 655 | store_sas_link_reset(struct device *dev, struct device_attribute *attr, |
| 656 | const char *buf, size_t count) |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 657 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 658 | return do_sas_phy_reset(dev, count, 0); |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 659 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 660 | static DEVICE_ATTR(link_reset, S_IWUSR, NULL, store_sas_link_reset); |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 661 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 662 | static ssize_t |
| 663 | store_sas_hard_reset(struct device *dev, struct device_attribute *attr, |
| 664 | const char *buf, size_t count) |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 665 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 666 | return do_sas_phy_reset(dev, count, 1); |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 667 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 668 | static DEVICE_ATTR(hard_reset, S_IWUSR, NULL, store_sas_hard_reset); |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 669 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 670 | sas_phy_protocol_attr(identify.initiator_port_protocols, |
| 671 | initiator_port_protocols); |
| 672 | sas_phy_protocol_attr(identify.target_port_protocols, |
| 673 | target_port_protocols); |
| 674 | sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n", |
| 675 | unsigned long long); |
| 676 | sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8); |
James Bottomley | c9fefeb | 2006-07-02 11:10:18 -0500 | [diff] [blame] | 677 | //sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", int); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 678 | sas_phy_linkspeed_attr(negotiated_linkrate); |
| 679 | sas_phy_linkspeed_attr(minimum_linkrate_hw); |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 680 | sas_phy_linkspeed_rw_attr(minimum_linkrate); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 681 | sas_phy_linkspeed_attr(maximum_linkrate_hw); |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 682 | sas_phy_linkspeed_rw_attr(maximum_linkrate); |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 683 | sas_phy_linkerror_attr(invalid_dword_count); |
| 684 | sas_phy_linkerror_attr(running_disparity_error_count); |
| 685 | sas_phy_linkerror_attr(loss_of_dword_sync_count); |
| 686 | sas_phy_linkerror_attr(phy_reset_problem_count); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 687 | |
Dan Williams | 0b3e09d | 2011-12-20 01:03:48 -0800 | [diff] [blame] | 688 | static int sas_phy_setup(struct transport_container *tc, struct device *dev, |
| 689 | struct device *cdev) |
| 690 | { |
| 691 | struct sas_phy *phy = dev_to_phy(dev); |
| 692 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 693 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 694 | |
| 695 | if (i->f->phy_setup) |
| 696 | i->f->phy_setup(phy); |
| 697 | |
| 698 | return 0; |
| 699 | } |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 700 | |
| 701 | static DECLARE_TRANSPORT_CLASS(sas_phy_class, |
Dan Williams | 0b3e09d | 2011-12-20 01:03:48 -0800 | [diff] [blame] | 702 | "sas_phy", sas_phy_setup, NULL, NULL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 703 | |
| 704 | static int sas_phy_match(struct attribute_container *cont, struct device *dev) |
| 705 | { |
| 706 | struct Scsi_Host *shost; |
| 707 | struct sas_internal *i; |
| 708 | |
| 709 | if (!scsi_is_sas_phy(dev)) |
| 710 | return 0; |
| 711 | shost = dev_to_shost(dev->parent); |
| 712 | |
| 713 | if (!shost->transportt) |
| 714 | return 0; |
| 715 | if (shost->transportt->host_attrs.ac.class != |
| 716 | &sas_host_class.class) |
| 717 | return 0; |
| 718 | |
| 719 | i = to_sas_internal(shost->transportt); |
| 720 | return &i->phy_attr_cont.ac == cont; |
| 721 | } |
| 722 | |
| 723 | static void sas_phy_release(struct device *dev) |
| 724 | { |
| 725 | struct sas_phy *phy = dev_to_phy(dev); |
Dan Williams | 0b3e09d | 2011-12-20 01:03:48 -0800 | [diff] [blame] | 726 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 727 | struct sas_internal *i = to_sas_internal(shost->transportt); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 728 | |
Dan Williams | 0b3e09d | 2011-12-20 01:03:48 -0800 | [diff] [blame] | 729 | if (i->f->phy_release) |
| 730 | i->f->phy_release(phy); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 731 | put_device(dev->parent); |
| 732 | kfree(phy); |
| 733 | } |
| 734 | |
| 735 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 736 | * sas_phy_alloc - allocates and initialize a SAS PHY structure |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 737 | * @parent: Parent device |
Moore, Eric | d99ca41 | 2006-01-26 16:20:02 -0700 | [diff] [blame] | 738 | * @number: Phy index |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 739 | * |
| 740 | * Allocates an SAS PHY structure. It will be added in the device tree |
| 741 | * below the device specified by @parent, which has to be either a Scsi_Host |
| 742 | * or sas_rphy. |
| 743 | * |
| 744 | * Returns: |
| 745 | * SAS PHY allocated or %NULL if the allocation failed. |
| 746 | */ |
| 747 | struct sas_phy *sas_phy_alloc(struct device *parent, int number) |
| 748 | { |
| 749 | struct Scsi_Host *shost = dev_to_shost(parent); |
| 750 | struct sas_phy *phy; |
| 751 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 752 | phy = kzalloc(sizeof(*phy), GFP_KERNEL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 753 | if (!phy) |
| 754 | return NULL; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 755 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 756 | phy->number = number; |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 757 | phy->enabled = 1; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 758 | |
| 759 | device_initialize(&phy->dev); |
| 760 | phy->dev.parent = get_device(parent); |
| 761 | phy->dev.release = sas_phy_release; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 762 | INIT_LIST_HEAD(&phy->port_siblings); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 763 | if (scsi_is_sas_expander_device(parent)) { |
| 764 | struct sas_rphy *rphy = dev_to_rphy(parent); |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 765 | dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no, |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 766 | rphy->scsi_target_id, number); |
| 767 | } else |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 768 | dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 769 | |
| 770 | transport_setup_device(&phy->dev); |
| 771 | |
| 772 | return phy; |
| 773 | } |
| 774 | EXPORT_SYMBOL(sas_phy_alloc); |
| 775 | |
| 776 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 777 | * sas_phy_add - add a SAS PHY to the device hierarchy |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 778 | * @phy: The PHY to be added |
| 779 | * |
| 780 | * Publishes a SAS PHY to the rest of the system. |
| 781 | */ |
| 782 | int sas_phy_add(struct sas_phy *phy) |
| 783 | { |
| 784 | int error; |
| 785 | |
| 786 | error = device_add(&phy->dev); |
| 787 | if (!error) { |
| 788 | transport_add_device(&phy->dev); |
| 789 | transport_configure_device(&phy->dev); |
| 790 | } |
| 791 | |
| 792 | return error; |
| 793 | } |
| 794 | EXPORT_SYMBOL(sas_phy_add); |
| 795 | |
| 796 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 797 | * sas_phy_free - free a SAS PHY |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 798 | * @phy: SAS PHY to free |
| 799 | * |
| 800 | * Frees the specified SAS PHY. |
| 801 | * |
| 802 | * Note: |
| 803 | * This function must only be called on a PHY that has not |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 804 | * successfully been added using sas_phy_add(). |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 805 | */ |
| 806 | void sas_phy_free(struct sas_phy *phy) |
| 807 | { |
| 808 | transport_destroy_device(&phy->dev); |
Mike Anderson | 92aab64 | 2006-03-27 09:37:28 -0800 | [diff] [blame] | 809 | put_device(&phy->dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 810 | } |
| 811 | EXPORT_SYMBOL(sas_phy_free); |
| 812 | |
| 813 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 814 | * sas_phy_delete - remove SAS PHY |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 815 | * @phy: SAS PHY to remove |
| 816 | * |
| 817 | * Removes the specified SAS PHY. If the SAS PHY has an |
| 818 | * associated remote PHY it is removed before. |
| 819 | */ |
| 820 | void |
| 821 | sas_phy_delete(struct sas_phy *phy) |
| 822 | { |
| 823 | struct device *dev = &phy->dev; |
| 824 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 825 | /* this happens if the phy is still part of a port when deleted */ |
| 826 | BUG_ON(!list_empty(&phy->port_siblings)); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 827 | |
| 828 | transport_remove_device(dev); |
| 829 | device_del(dev); |
| 830 | transport_destroy_device(dev); |
Mike Anderson | 92aab64 | 2006-03-27 09:37:28 -0800 | [diff] [blame] | 831 | put_device(dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 832 | } |
| 833 | EXPORT_SYMBOL(sas_phy_delete); |
| 834 | |
| 835 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 836 | * scsi_is_sas_phy - check if a struct device represents a SAS PHY |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 837 | * @dev: device to check |
| 838 | * |
| 839 | * Returns: |
| 840 | * %1 if the device represents a SAS PHY, %0 else |
| 841 | */ |
| 842 | int scsi_is_sas_phy(const struct device *dev) |
| 843 | { |
| 844 | return dev->release == sas_phy_release; |
| 845 | } |
| 846 | EXPORT_SYMBOL(scsi_is_sas_phy); |
| 847 | |
| 848 | /* |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 849 | * SAS Port attributes |
| 850 | */ |
| 851 | #define sas_port_show_simple(field, name, format_string, cast) \ |
| 852 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 853 | show_sas_port_##name(struct device *dev, \ |
| 854 | struct device_attribute *attr, char *buf) \ |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 855 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 856 | struct sas_port *port = transport_class_to_sas_port(dev); \ |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 857 | \ |
| 858 | return snprintf(buf, 20, format_string, cast port->field); \ |
| 859 | } |
| 860 | |
| 861 | #define sas_port_simple_attr(field, name, format_string, type) \ |
| 862 | sas_port_show_simple(field, name, format_string, (type)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 863 | static DEVICE_ATTR(name, S_IRUGO, show_sas_port_##name, NULL) |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 864 | |
| 865 | sas_port_simple_attr(num_phys, num_phys, "%d\n", int); |
| 866 | |
| 867 | static DECLARE_TRANSPORT_CLASS(sas_port_class, |
| 868 | "sas_port", NULL, NULL, NULL); |
| 869 | |
| 870 | static int sas_port_match(struct attribute_container *cont, struct device *dev) |
| 871 | { |
| 872 | struct Scsi_Host *shost; |
| 873 | struct sas_internal *i; |
| 874 | |
| 875 | if (!scsi_is_sas_port(dev)) |
| 876 | return 0; |
| 877 | shost = dev_to_shost(dev->parent); |
| 878 | |
| 879 | if (!shost->transportt) |
| 880 | return 0; |
| 881 | if (shost->transportt->host_attrs.ac.class != |
| 882 | &sas_host_class.class) |
| 883 | return 0; |
| 884 | |
| 885 | i = to_sas_internal(shost->transportt); |
| 886 | return &i->port_attr_cont.ac == cont; |
| 887 | } |
| 888 | |
| 889 | |
| 890 | static void sas_port_release(struct device *dev) |
| 891 | { |
| 892 | struct sas_port *port = dev_to_sas_port(dev); |
| 893 | |
| 894 | BUG_ON(!list_empty(&port->phy_list)); |
| 895 | |
| 896 | put_device(dev->parent); |
| 897 | kfree(port); |
| 898 | } |
| 899 | |
| 900 | static void sas_port_create_link(struct sas_port *port, |
| 901 | struct sas_phy *phy) |
| 902 | { |
Darrick J. Wong | 2143496 | 2007-01-26 14:08:46 -0800 | [diff] [blame] | 903 | int res; |
| 904 | |
| 905 | res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 906 | dev_name(&phy->dev)); |
Darrick J. Wong | 2143496 | 2007-01-26 14:08:46 -0800 | [diff] [blame] | 907 | if (res) |
| 908 | goto err; |
| 909 | res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port"); |
| 910 | if (res) |
| 911 | goto err; |
| 912 | return; |
| 913 | err: |
| 914 | printk(KERN_ERR "%s: Cannot create port links, err=%d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 915 | __func__, res); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static void sas_port_delete_link(struct sas_port *port, |
| 919 | struct sas_phy *phy) |
| 920 | { |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 921 | sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev)); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 922 | sysfs_remove_link(&phy->dev.kobj, "port"); |
| 923 | } |
| 924 | |
| 925 | /** sas_port_alloc - allocate and initialize a SAS port structure |
| 926 | * |
| 927 | * @parent: parent device |
| 928 | * @port_id: port number |
| 929 | * |
| 930 | * Allocates a SAS port structure. It will be added to the device tree |
| 931 | * below the device specified by @parent which must be either a Scsi_Host |
| 932 | * or a sas_expander_device. |
| 933 | * |
| 934 | * Returns %NULL on error |
| 935 | */ |
| 936 | struct sas_port *sas_port_alloc(struct device *parent, int port_id) |
| 937 | { |
| 938 | struct Scsi_Host *shost = dev_to_shost(parent); |
| 939 | struct sas_port *port; |
| 940 | |
| 941 | port = kzalloc(sizeof(*port), GFP_KERNEL); |
| 942 | if (!port) |
| 943 | return NULL; |
| 944 | |
| 945 | port->port_identifier = port_id; |
| 946 | |
| 947 | device_initialize(&port->dev); |
| 948 | |
| 949 | port->dev.parent = get_device(parent); |
| 950 | port->dev.release = sas_port_release; |
| 951 | |
| 952 | mutex_init(&port->phy_list_mutex); |
| 953 | INIT_LIST_HEAD(&port->phy_list); |
| 954 | |
| 955 | if (scsi_is_sas_expander_device(parent)) { |
| 956 | struct sas_rphy *rphy = dev_to_rphy(parent); |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 957 | dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no, |
| 958 | rphy->scsi_target_id, port->port_identifier); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 959 | } else |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 960 | dev_set_name(&port->dev, "port-%d:%d", shost->host_no, |
| 961 | port->port_identifier); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 962 | |
| 963 | transport_setup_device(&port->dev); |
| 964 | |
| 965 | return port; |
| 966 | } |
| 967 | EXPORT_SYMBOL(sas_port_alloc); |
| 968 | |
James Bottomley | c9fefeb | 2006-07-02 11:10:18 -0500 | [diff] [blame] | 969 | /** sas_port_alloc_num - allocate and initialize a SAS port structure |
| 970 | * |
| 971 | * @parent: parent device |
| 972 | * |
| 973 | * Allocates a SAS port structure and a number to go with it. This |
| 974 | * interface is really for adapters where the port number has no |
| 975 | * meansing, so the sas class should manage them. It will be added to |
| 976 | * the device tree below the device specified by @parent which must be |
| 977 | * either a Scsi_Host or a sas_expander_device. |
| 978 | * |
| 979 | * Returns %NULL on error |
| 980 | */ |
| 981 | struct sas_port *sas_port_alloc_num(struct device *parent) |
| 982 | { |
| 983 | int index; |
| 984 | struct Scsi_Host *shost = dev_to_shost(parent); |
| 985 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 986 | |
| 987 | /* FIXME: use idr for this eventually */ |
| 988 | mutex_lock(&sas_host->lock); |
| 989 | if (scsi_is_sas_expander_device(parent)) { |
| 990 | struct sas_rphy *rphy = dev_to_rphy(parent); |
| 991 | struct sas_expander_device *exp = rphy_to_expander_device(rphy); |
| 992 | |
| 993 | index = exp->next_port_id++; |
| 994 | } else |
| 995 | index = sas_host->next_port_id++; |
| 996 | mutex_unlock(&sas_host->lock); |
| 997 | return sas_port_alloc(parent, index); |
| 998 | } |
| 999 | EXPORT_SYMBOL(sas_port_alloc_num); |
| 1000 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1001 | /** |
| 1002 | * sas_port_add - add a SAS port to the device hierarchy |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1003 | * @port: port to be added |
| 1004 | * |
| 1005 | * publishes a port to the rest of the system |
| 1006 | */ |
| 1007 | int sas_port_add(struct sas_port *port) |
| 1008 | { |
| 1009 | int error; |
| 1010 | |
| 1011 | /* No phys should be added until this is made visible */ |
| 1012 | BUG_ON(!list_empty(&port->phy_list)); |
| 1013 | |
| 1014 | error = device_add(&port->dev); |
| 1015 | |
| 1016 | if (error) |
| 1017 | return error; |
| 1018 | |
| 1019 | transport_add_device(&port->dev); |
| 1020 | transport_configure_device(&port->dev); |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | EXPORT_SYMBOL(sas_port_add); |
| 1025 | |
| 1026 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1027 | * sas_port_free - free a SAS PORT |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1028 | * @port: SAS PORT to free |
| 1029 | * |
| 1030 | * Frees the specified SAS PORT. |
| 1031 | * |
| 1032 | * Note: |
| 1033 | * This function must only be called on a PORT that has not |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1034 | * successfully been added using sas_port_add(). |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1035 | */ |
| 1036 | void sas_port_free(struct sas_port *port) |
| 1037 | { |
| 1038 | transport_destroy_device(&port->dev); |
| 1039 | put_device(&port->dev); |
| 1040 | } |
| 1041 | EXPORT_SYMBOL(sas_port_free); |
| 1042 | |
| 1043 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1044 | * sas_port_delete - remove SAS PORT |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1045 | * @port: SAS PORT to remove |
| 1046 | * |
| 1047 | * Removes the specified SAS PORT. If the SAS PORT has an |
| 1048 | * associated phys, unlink them from the port as well. |
| 1049 | */ |
| 1050 | void sas_port_delete(struct sas_port *port) |
| 1051 | { |
| 1052 | struct device *dev = &port->dev; |
| 1053 | struct sas_phy *phy, *tmp_phy; |
| 1054 | |
| 1055 | if (port->rphy) { |
| 1056 | sas_rphy_delete(port->rphy); |
| 1057 | port->rphy = NULL; |
| 1058 | } |
| 1059 | |
| 1060 | mutex_lock(&port->phy_list_mutex); |
| 1061 | list_for_each_entry_safe(phy, tmp_phy, &port->phy_list, |
| 1062 | port_siblings) { |
| 1063 | sas_port_delete_link(port, phy); |
| 1064 | list_del_init(&phy->port_siblings); |
| 1065 | } |
| 1066 | mutex_unlock(&port->phy_list_mutex); |
| 1067 | |
James Bottomley | a0e1b6e | 2006-07-09 12:38:19 -0500 | [diff] [blame] | 1068 | if (port->is_backlink) { |
| 1069 | struct device *parent = port->dev.parent; |
| 1070 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1071 | sysfs_remove_link(&port->dev.kobj, dev_name(parent)); |
James Bottomley | a0e1b6e | 2006-07-09 12:38:19 -0500 | [diff] [blame] | 1072 | port->is_backlink = 0; |
| 1073 | } |
| 1074 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1075 | transport_remove_device(dev); |
| 1076 | device_del(dev); |
| 1077 | transport_destroy_device(dev); |
| 1078 | put_device(dev); |
| 1079 | } |
| 1080 | EXPORT_SYMBOL(sas_port_delete); |
| 1081 | |
| 1082 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1083 | * scsi_is_sas_port - check if a struct device represents a SAS port |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1084 | * @dev: device to check |
| 1085 | * |
| 1086 | * Returns: |
| 1087 | * %1 if the device represents a SAS Port, %0 else |
| 1088 | */ |
| 1089 | int scsi_is_sas_port(const struct device *dev) |
| 1090 | { |
| 1091 | return dev->release == sas_port_release; |
| 1092 | } |
| 1093 | EXPORT_SYMBOL(scsi_is_sas_port); |
| 1094 | |
| 1095 | /** |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1096 | * sas_port_get_phy - try to take a reference on a port member |
| 1097 | * @port: port to check |
| 1098 | */ |
| 1099 | struct sas_phy *sas_port_get_phy(struct sas_port *port) |
| 1100 | { |
| 1101 | struct sas_phy *phy; |
| 1102 | |
| 1103 | mutex_lock(&port->phy_list_mutex); |
| 1104 | if (list_empty(&port->phy_list)) |
| 1105 | phy = NULL; |
| 1106 | else { |
| 1107 | struct list_head *ent = port->phy_list.next; |
| 1108 | |
| 1109 | phy = list_entry(ent, typeof(*phy), port_siblings); |
| 1110 | get_device(&phy->dev); |
| 1111 | } |
| 1112 | mutex_unlock(&port->phy_list_mutex); |
| 1113 | |
| 1114 | return phy; |
| 1115 | } |
| 1116 | EXPORT_SYMBOL(sas_port_get_phy); |
| 1117 | |
| 1118 | /** |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1119 | * sas_port_add_phy - add another phy to a port to form a wide port |
| 1120 | * @port: port to add the phy to |
| 1121 | * @phy: phy to add |
| 1122 | * |
| 1123 | * When a port is initially created, it is empty (has no phys). All |
| 1124 | * ports must have at least one phy to operated, and all wide ports |
| 1125 | * must have at least two. The current code makes no difference |
| 1126 | * between ports and wide ports, but the only object that can be |
| 1127 | * connected to a remote device is a port, so ports must be formed on |
| 1128 | * all devices with phys if they're connected to anything. |
| 1129 | */ |
| 1130 | void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy) |
| 1131 | { |
| 1132 | mutex_lock(&port->phy_list_mutex); |
| 1133 | if (unlikely(!list_empty(&phy->port_siblings))) { |
| 1134 | /* make sure we're already on this port */ |
| 1135 | struct sas_phy *tmp; |
| 1136 | |
| 1137 | list_for_each_entry(tmp, &port->phy_list, port_siblings) |
| 1138 | if (tmp == phy) |
| 1139 | break; |
| 1140 | /* If this trips, you added a phy that was already |
| 1141 | * part of a different port */ |
| 1142 | if (unlikely(tmp != phy)) { |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1143 | dev_printk(KERN_ERR, &port->dev, "trying to add phy %s fails: it's already part of another port\n", |
| 1144 | dev_name(&phy->dev)); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1145 | BUG(); |
| 1146 | } |
| 1147 | } else { |
| 1148 | sas_port_create_link(port, phy); |
| 1149 | list_add_tail(&phy->port_siblings, &port->phy_list); |
| 1150 | port->num_phys++; |
| 1151 | } |
| 1152 | mutex_unlock(&port->phy_list_mutex); |
| 1153 | } |
| 1154 | EXPORT_SYMBOL(sas_port_add_phy); |
| 1155 | |
| 1156 | /** |
| 1157 | * sas_port_delete_phy - remove a phy from a port or wide port |
| 1158 | * @port: port to remove the phy from |
| 1159 | * @phy: phy to remove |
| 1160 | * |
| 1161 | * This operation is used for tearing down ports again. It must be |
| 1162 | * done to every port or wide port before calling sas_port_delete. |
| 1163 | */ |
| 1164 | void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy) |
| 1165 | { |
| 1166 | mutex_lock(&port->phy_list_mutex); |
| 1167 | sas_port_delete_link(port, phy); |
| 1168 | list_del_init(&phy->port_siblings); |
| 1169 | port->num_phys--; |
| 1170 | mutex_unlock(&port->phy_list_mutex); |
| 1171 | } |
| 1172 | EXPORT_SYMBOL(sas_port_delete_phy); |
| 1173 | |
James Bottomley | a0e1b6e | 2006-07-09 12:38:19 -0500 | [diff] [blame] | 1174 | void sas_port_mark_backlink(struct sas_port *port) |
| 1175 | { |
Darrick J. Wong | 2143496 | 2007-01-26 14:08:46 -0800 | [diff] [blame] | 1176 | int res; |
James Bottomley | a0e1b6e | 2006-07-09 12:38:19 -0500 | [diff] [blame] | 1177 | struct device *parent = port->dev.parent->parent->parent; |
| 1178 | |
| 1179 | if (port->is_backlink) |
| 1180 | return; |
| 1181 | port->is_backlink = 1; |
Darrick J. Wong | 2143496 | 2007-01-26 14:08:46 -0800 | [diff] [blame] | 1182 | res = sysfs_create_link(&port->dev.kobj, &parent->kobj, |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1183 | dev_name(parent)); |
Darrick J. Wong | 2143496 | 2007-01-26 14:08:46 -0800 | [diff] [blame] | 1184 | if (res) |
| 1185 | goto err; |
| 1186 | return; |
| 1187 | err: |
| 1188 | printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1189 | __func__, res); |
James Bottomley | a0e1b6e | 2006-07-09 12:38:19 -0500 | [diff] [blame] | 1190 | |
| 1191 | } |
| 1192 | EXPORT_SYMBOL(sas_port_mark_backlink); |
| 1193 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1194 | /* |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1195 | * SAS remote PHY attributes. |
| 1196 | */ |
| 1197 | |
| 1198 | #define sas_rphy_show_simple(field, name, format_string, cast) \ |
| 1199 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1200 | show_sas_rphy_##name(struct device *dev, \ |
| 1201 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1202 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1203 | struct sas_rphy *rphy = transport_class_to_rphy(dev); \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1204 | \ |
| 1205 | return snprintf(buf, 20, format_string, cast rphy->field); \ |
| 1206 | } |
| 1207 | |
| 1208 | #define sas_rphy_simple_attr(field, name, format_string, type) \ |
| 1209 | sas_rphy_show_simple(field, name, format_string, (type)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1210 | static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1211 | show_sas_rphy_##name, NULL) |
| 1212 | |
| 1213 | #define sas_rphy_show_protocol(field, name) \ |
| 1214 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1215 | show_sas_rphy_##name(struct device *dev, \ |
| 1216 | struct device_attribute *attr, char *buf) \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1217 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1218 | struct sas_rphy *rphy = transport_class_to_rphy(dev); \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1219 | \ |
| 1220 | if (!rphy->field) \ |
| 1221 | return snprintf(buf, 20, "none\n"); \ |
| 1222 | return get_sas_protocol_names(rphy->field, buf); \ |
| 1223 | } |
| 1224 | |
| 1225 | #define sas_rphy_protocol_attr(field, name) \ |
| 1226 | sas_rphy_show_protocol(field, name) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1227 | static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \ |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1228 | show_sas_rphy_##name, NULL) |
| 1229 | |
| 1230 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1231 | show_sas_rphy_device_type(struct device *dev, |
| 1232 | struct device_attribute *attr, char *buf) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1233 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1234 | struct sas_rphy *rphy = transport_class_to_rphy(dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1235 | |
| 1236 | if (!rphy->identify.device_type) |
| 1237 | return snprintf(buf, 20, "none\n"); |
| 1238 | return get_sas_device_type_names( |
| 1239 | rphy->identify.device_type, buf); |
| 1240 | } |
| 1241 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1242 | static SAS_DEVICE_ATTR(rphy, device_type, S_IRUGO, |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1243 | show_sas_rphy_device_type, NULL); |
| 1244 | |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1245 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1246 | show_sas_rphy_enclosure_identifier(struct device *dev, |
| 1247 | struct device_attribute *attr, char *buf) |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1248 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1249 | struct sas_rphy *rphy = transport_class_to_rphy(dev); |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1250 | struct sas_phy *phy = dev_to_phy(rphy->dev.parent); |
| 1251 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 1252 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 1253 | u64 identifier; |
| 1254 | int error; |
| 1255 | |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1256 | error = i->f->get_enclosure_identifier(rphy, &identifier); |
| 1257 | if (error) |
| 1258 | return error; |
| 1259 | return sprintf(buf, "0x%llx\n", (unsigned long long)identifier); |
| 1260 | } |
| 1261 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1262 | static SAS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO, |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1263 | show_sas_rphy_enclosure_identifier, NULL); |
| 1264 | |
| 1265 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1266 | show_sas_rphy_bay_identifier(struct device *dev, |
| 1267 | struct device_attribute *attr, char *buf) |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1268 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1269 | struct sas_rphy *rphy = transport_class_to_rphy(dev); |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1270 | struct sas_phy *phy = dev_to_phy(rphy->dev.parent); |
| 1271 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 1272 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 1273 | int val; |
| 1274 | |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1275 | val = i->f->get_bay_identifier(rphy); |
| 1276 | if (val < 0) |
| 1277 | return val; |
| 1278 | return sprintf(buf, "%d\n", val); |
| 1279 | } |
| 1280 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1281 | static SAS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO, |
Christoph Hellwig | a012564 | 2006-02-16 13:31:47 +0100 | [diff] [blame] | 1282 | show_sas_rphy_bay_identifier, NULL); |
| 1283 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1284 | sas_rphy_protocol_attr(identify.initiator_port_protocols, |
| 1285 | initiator_port_protocols); |
| 1286 | sas_rphy_protocol_attr(identify.target_port_protocols, target_port_protocols); |
| 1287 | sas_rphy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n", |
| 1288 | unsigned long long); |
| 1289 | sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8); |
Hannes Reinecke | cdc43ae | 2016-03-14 10:43:08 +0100 | [diff] [blame] | 1290 | sas_rphy_simple_attr(scsi_target_id, scsi_target_id, "%d\n", u32); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1291 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1292 | /* only need 8 bytes of data plus header (4 or 8) */ |
| 1293 | #define BUF_SIZE 64 |
| 1294 | |
| 1295 | int sas_read_port_mode_page(struct scsi_device *sdev) |
| 1296 | { |
| 1297 | char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata; |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 1298 | struct sas_end_device *rdev = sas_sdev_to_rdev(sdev); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1299 | struct scsi_mode_data mode_data; |
| 1300 | int res, error; |
| 1301 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1302 | if (!buffer) |
| 1303 | return -ENOMEM; |
| 1304 | |
| 1305 | res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3, |
| 1306 | &mode_data, NULL); |
| 1307 | |
| 1308 | error = -EINVAL; |
| 1309 | if (!scsi_status_is_good(res)) |
| 1310 | goto out; |
| 1311 | |
| 1312 | msdata = buffer + mode_data.header_length + |
| 1313 | mode_data.block_descriptor_length; |
| 1314 | |
| 1315 | if (msdata - buffer > BUF_SIZE - 8) |
| 1316 | goto out; |
| 1317 | |
| 1318 | error = 0; |
| 1319 | |
| 1320 | rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0; |
| 1321 | rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5]; |
| 1322 | rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7]; |
| 1323 | |
| 1324 | out: |
| 1325 | kfree(buffer); |
| 1326 | return error; |
| 1327 | } |
| 1328 | EXPORT_SYMBOL(sas_read_port_mode_page); |
| 1329 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1330 | static DECLARE_TRANSPORT_CLASS(sas_end_dev_class, |
| 1331 | "sas_end_device", NULL, NULL, NULL); |
| 1332 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1333 | #define sas_end_dev_show_simple(field, name, format_string, cast) \ |
| 1334 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1335 | show_sas_end_dev_##name(struct device *dev, \ |
| 1336 | struct device_attribute *attr, char *buf) \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1337 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1338 | struct sas_rphy *rphy = transport_class_to_rphy(dev); \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1339 | struct sas_end_device *rdev = rphy_to_end_device(rphy); \ |
| 1340 | \ |
| 1341 | return snprintf(buf, 20, format_string, cast rdev->field); \ |
| 1342 | } |
| 1343 | |
| 1344 | #define sas_end_dev_simple_attr(field, name, format_string, type) \ |
| 1345 | sas_end_dev_show_simple(field, name, format_string, (type)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1346 | static SAS_DEVICE_ATTR(end_dev, name, S_IRUGO, \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1347 | show_sas_end_dev_##name, NULL) |
| 1348 | |
| 1349 | sas_end_dev_simple_attr(ready_led_meaning, ready_led_meaning, "%d\n", int); |
| 1350 | sas_end_dev_simple_attr(I_T_nexus_loss_timeout, I_T_nexus_loss_timeout, |
| 1351 | "%d\n", int); |
| 1352 | sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout, |
| 1353 | "%d\n", int); |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 1354 | sas_end_dev_simple_attr(tlr_supported, tlr_supported, |
| 1355 | "%d\n", int); |
| 1356 | sas_end_dev_simple_attr(tlr_enabled, tlr_enabled, |
| 1357 | "%d\n", int); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1358 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1359 | static DECLARE_TRANSPORT_CLASS(sas_expander_class, |
| 1360 | "sas_expander", NULL, NULL, NULL); |
| 1361 | |
| 1362 | #define sas_expander_show_simple(field, name, format_string, cast) \ |
| 1363 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1364 | show_sas_expander_##name(struct device *dev, \ |
| 1365 | struct device_attribute *attr, char *buf) \ |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1366 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1367 | struct sas_rphy *rphy = transport_class_to_rphy(dev); \ |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1368 | struct sas_expander_device *edev = rphy_to_expander_device(rphy); \ |
| 1369 | \ |
| 1370 | return snprintf(buf, 20, format_string, cast edev->field); \ |
| 1371 | } |
| 1372 | |
| 1373 | #define sas_expander_simple_attr(field, name, format_string, type) \ |
| 1374 | sas_expander_show_simple(field, name, format_string, (type)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1375 | static SAS_DEVICE_ATTR(expander, name, S_IRUGO, \ |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1376 | show_sas_expander_##name, NULL) |
| 1377 | |
| 1378 | sas_expander_simple_attr(vendor_id, vendor_id, "%s\n", char *); |
| 1379 | sas_expander_simple_attr(product_id, product_id, "%s\n", char *); |
| 1380 | sas_expander_simple_attr(product_rev, product_rev, "%s\n", char *); |
| 1381 | sas_expander_simple_attr(component_vendor_id, component_vendor_id, |
| 1382 | "%s\n", char *); |
| 1383 | sas_expander_simple_attr(component_id, component_id, "%u\n", unsigned int); |
| 1384 | sas_expander_simple_attr(component_revision_id, component_revision_id, "%u\n", |
| 1385 | unsigned int); |
| 1386 | sas_expander_simple_attr(level, level, "%d\n", int); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1387 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1388 | static DECLARE_TRANSPORT_CLASS(sas_rphy_class, |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1389 | "sas_device", NULL, NULL, NULL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1390 | |
| 1391 | static int sas_rphy_match(struct attribute_container *cont, struct device *dev) |
| 1392 | { |
| 1393 | struct Scsi_Host *shost; |
| 1394 | struct sas_internal *i; |
| 1395 | |
| 1396 | if (!scsi_is_sas_rphy(dev)) |
| 1397 | return 0; |
| 1398 | shost = dev_to_shost(dev->parent->parent); |
| 1399 | |
| 1400 | if (!shost->transportt) |
| 1401 | return 0; |
| 1402 | if (shost->transportt->host_attrs.ac.class != |
| 1403 | &sas_host_class.class) |
| 1404 | return 0; |
| 1405 | |
| 1406 | i = to_sas_internal(shost->transportt); |
| 1407 | return &i->rphy_attr_cont.ac == cont; |
| 1408 | } |
| 1409 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1410 | static int sas_end_dev_match(struct attribute_container *cont, |
| 1411 | struct device *dev) |
| 1412 | { |
| 1413 | struct Scsi_Host *shost; |
| 1414 | struct sas_internal *i; |
| 1415 | struct sas_rphy *rphy; |
| 1416 | |
| 1417 | if (!scsi_is_sas_rphy(dev)) |
| 1418 | return 0; |
| 1419 | shost = dev_to_shost(dev->parent->parent); |
| 1420 | rphy = dev_to_rphy(dev); |
| 1421 | |
| 1422 | if (!shost->transportt) |
| 1423 | return 0; |
| 1424 | if (shost->transportt->host_attrs.ac.class != |
| 1425 | &sas_host_class.class) |
| 1426 | return 0; |
| 1427 | |
| 1428 | i = to_sas_internal(shost->transportt); |
| 1429 | return &i->end_dev_attr_cont.ac == cont && |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1430 | rphy->identify.device_type == SAS_END_DEVICE; |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1431 | } |
| 1432 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1433 | static int sas_expander_match(struct attribute_container *cont, |
| 1434 | struct device *dev) |
| 1435 | { |
| 1436 | struct Scsi_Host *shost; |
| 1437 | struct sas_internal *i; |
| 1438 | struct sas_rphy *rphy; |
| 1439 | |
| 1440 | if (!scsi_is_sas_rphy(dev)) |
| 1441 | return 0; |
| 1442 | shost = dev_to_shost(dev->parent->parent); |
| 1443 | rphy = dev_to_rphy(dev); |
| 1444 | |
| 1445 | if (!shost->transportt) |
| 1446 | return 0; |
| 1447 | if (shost->transportt->host_attrs.ac.class != |
| 1448 | &sas_host_class.class) |
| 1449 | return 0; |
| 1450 | |
| 1451 | i = to_sas_internal(shost->transportt); |
| 1452 | return &i->expander_attr_cont.ac == cont && |
| 1453 | (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE || |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1454 | rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1455 | } |
| 1456 | |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1457 | static void sas_expander_release(struct device *dev) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1458 | { |
| 1459 | struct sas_rphy *rphy = dev_to_rphy(dev); |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1460 | struct sas_expander_device *edev = rphy_to_expander_device(rphy); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1461 | |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 1462 | if (rphy->q) |
| 1463 | blk_cleanup_queue(rphy->q); |
| 1464 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1465 | put_device(dev->parent); |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1466 | kfree(edev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1469 | static void sas_end_device_release(struct device *dev) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1470 | { |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1471 | struct sas_rphy *rphy = dev_to_rphy(dev); |
| 1472 | struct sas_end_device *edev = rphy_to_end_device(rphy); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1473 | |
FUJITA Tomonori | 93c20a5 | 2008-04-19 00:43:15 +0900 | [diff] [blame] | 1474 | if (rphy->q) |
| 1475 | blk_cleanup_queue(rphy->q); |
| 1476 | |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1477 | put_device(dev->parent); |
| 1478 | kfree(edev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1479 | } |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1480 | |
| 1481 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 1482 | * sas_rphy_initialize - common rphy initialization |
James Bottomley | c5943d3 | 2006-06-12 09:09:18 -0500 | [diff] [blame] | 1483 | * @rphy: rphy to initialise |
| 1484 | * |
| 1485 | * Used by both sas_end_device_alloc() and sas_expander_alloc() to |
| 1486 | * initialise the common rphy component of each. |
| 1487 | */ |
| 1488 | static void sas_rphy_initialize(struct sas_rphy *rphy) |
| 1489 | { |
| 1490 | INIT_LIST_HEAD(&rphy->list); |
| 1491 | } |
| 1492 | |
| 1493 | /** |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1494 | * sas_end_device_alloc - allocate an rphy for an end device |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1495 | * @parent: which port |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1496 | * |
| 1497 | * Allocates an SAS remote PHY structure, connected to @parent. |
| 1498 | * |
| 1499 | * Returns: |
| 1500 | * SAS PHY allocated or %NULL if the allocation failed. |
| 1501 | */ |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1502 | struct sas_rphy *sas_end_device_alloc(struct sas_port *parent) |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1503 | { |
| 1504 | struct Scsi_Host *shost = dev_to_shost(&parent->dev); |
| 1505 | struct sas_end_device *rdev; |
| 1506 | |
| 1507 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
| 1508 | if (!rdev) { |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1509 | return NULL; |
| 1510 | } |
| 1511 | |
| 1512 | device_initialize(&rdev->rphy.dev); |
| 1513 | rdev->rphy.dev.parent = get_device(&parent->dev); |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1514 | rdev->rphy.dev.release = sas_end_device_release; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1515 | if (scsi_is_sas_expander_device(parent->dev.parent)) { |
| 1516 | struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent); |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1517 | dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d", |
| 1518 | shost->host_no, rphy->scsi_target_id, |
| 1519 | parent->port_identifier); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1520 | } else |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1521 | dev_set_name(&rdev->rphy.dev, "end_device-%d:%d", |
| 1522 | shost->host_no, parent->port_identifier); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1523 | rdev->rphy.identify.device_type = SAS_END_DEVICE; |
James Bottomley | c5943d3 | 2006-06-12 09:09:18 -0500 | [diff] [blame] | 1524 | sas_rphy_initialize(&rdev->rphy); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1525 | transport_setup_device(&rdev->rphy.dev); |
| 1526 | |
| 1527 | return &rdev->rphy; |
| 1528 | } |
| 1529 | EXPORT_SYMBOL(sas_end_device_alloc); |
| 1530 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1531 | /** |
| 1532 | * sas_expander_alloc - allocate an rphy for an end device |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1533 | * @parent: which port |
| 1534 | * @type: SAS_EDGE_EXPANDER_DEVICE or SAS_FANOUT_EXPANDER_DEVICE |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1535 | * |
| 1536 | * Allocates an SAS remote PHY structure, connected to @parent. |
| 1537 | * |
| 1538 | * Returns: |
| 1539 | * SAS PHY allocated or %NULL if the allocation failed. |
| 1540 | */ |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1541 | struct sas_rphy *sas_expander_alloc(struct sas_port *parent, |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1542 | enum sas_device_type type) |
| 1543 | { |
| 1544 | struct Scsi_Host *shost = dev_to_shost(&parent->dev); |
| 1545 | struct sas_expander_device *rdev; |
| 1546 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 1547 | |
| 1548 | BUG_ON(type != SAS_EDGE_EXPANDER_DEVICE && |
| 1549 | type != SAS_FANOUT_EXPANDER_DEVICE); |
| 1550 | |
| 1551 | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); |
| 1552 | if (!rdev) { |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1553 | return NULL; |
| 1554 | } |
| 1555 | |
| 1556 | device_initialize(&rdev->rphy.dev); |
| 1557 | rdev->rphy.dev.parent = get_device(&parent->dev); |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1558 | rdev->rphy.dev.release = sas_expander_release; |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1559 | mutex_lock(&sas_host->lock); |
| 1560 | rdev->rphy.scsi_target_id = sas_host->next_expander_id++; |
| 1561 | mutex_unlock(&sas_host->lock); |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1562 | dev_set_name(&rdev->rphy.dev, "expander-%d:%d", |
| 1563 | shost->host_no, rdev->rphy.scsi_target_id); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1564 | rdev->rphy.identify.device_type = type; |
James Bottomley | c5943d3 | 2006-06-12 09:09:18 -0500 | [diff] [blame] | 1565 | sas_rphy_initialize(&rdev->rphy); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1566 | transport_setup_device(&rdev->rphy.dev); |
| 1567 | |
| 1568 | return &rdev->rphy; |
| 1569 | } |
| 1570 | EXPORT_SYMBOL(sas_expander_alloc); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1571 | |
| 1572 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1573 | * sas_rphy_add - add a SAS remote PHY to the device hierarchy |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1574 | * @rphy: The remote PHY to be added |
| 1575 | * |
| 1576 | * Publishes a SAS remote PHY to the rest of the system. |
| 1577 | */ |
| 1578 | int sas_rphy_add(struct sas_rphy *rphy) |
| 1579 | { |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1580 | struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1581 | struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); |
| 1582 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 1583 | struct sas_identify *identify = &rphy->identify; |
| 1584 | int error; |
| 1585 | |
| 1586 | if (parent->rphy) |
| 1587 | return -ENXIO; |
| 1588 | parent->rphy = rphy; |
| 1589 | |
| 1590 | error = device_add(&rphy->dev); |
| 1591 | if (error) |
| 1592 | return error; |
| 1593 | transport_add_device(&rphy->dev); |
| 1594 | transport_configure_device(&rphy->dev); |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 1595 | if (sas_bsg_initialize(shost, rphy)) |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1596 | printk("fail to a bsg device %s\n", dev_name(&rphy->dev)); |
James Bottomley | 39dca55 | 2007-07-20 18:22:17 -0500 | [diff] [blame] | 1597 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1598 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1599 | mutex_lock(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1600 | list_add_tail(&rphy->list, &sas_host->rphy_list); |
| 1601 | if (identify->device_type == SAS_END_DEVICE && |
| 1602 | (identify->target_port_protocols & |
| 1603 | (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))) |
| 1604 | rphy->scsi_target_id = sas_host->next_target_id++; |
James Bottomley | 7676f83 | 2006-04-14 09:47:59 -0500 | [diff] [blame] | 1605 | else if (identify->device_type == SAS_END_DEVICE) |
| 1606 | rphy->scsi_target_id = -1; |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1607 | mutex_unlock(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1608 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1609 | if (identify->device_type == SAS_END_DEVICE && |
| 1610 | rphy->scsi_target_id != -1) { |
Dan Williams | 2fc62e2 | 2011-09-20 15:10:19 -0700 | [diff] [blame] | 1611 | int lun; |
| 1612 | |
| 1613 | if (identify->target_port_protocols & SAS_PROTOCOL_SSP) |
| 1614 | lun = SCAN_WILD_CARD; |
| 1615 | else |
| 1616 | lun = 0; |
| 1617 | |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1618 | scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, lun, |
| 1619 | SCSI_SCAN_INITIAL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | return 0; |
| 1623 | } |
| 1624 | EXPORT_SYMBOL(sas_rphy_add); |
| 1625 | |
| 1626 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1627 | * sas_rphy_free - free a SAS remote PHY |
| 1628 | * @rphy: SAS remote PHY to free |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1629 | * |
| 1630 | * Frees the specified SAS remote PHY. |
| 1631 | * |
| 1632 | * Note: |
| 1633 | * This function must only be called on a remote |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1634 | * PHY that has not successfully been added using |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1635 | * sas_rphy_add() (or has been sas_rphy_remove()'d) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1636 | */ |
| 1637 | void sas_rphy_free(struct sas_rphy *rphy) |
| 1638 | { |
Mike Anderson | 92aab64 | 2006-03-27 09:37:28 -0800 | [diff] [blame] | 1639 | struct device *dev = &rphy->dev; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1640 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); |
| 1641 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 1642 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1643 | mutex_lock(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1644 | list_del(&rphy->list); |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1645 | mutex_unlock(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1646 | |
Mike Anderson | 92aab64 | 2006-03-27 09:37:28 -0800 | [diff] [blame] | 1647 | transport_destroy_device(dev); |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1648 | |
Mike Anderson | 92aab64 | 2006-03-27 09:37:28 -0800 | [diff] [blame] | 1649 | put_device(dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1650 | } |
| 1651 | EXPORT_SYMBOL(sas_rphy_free); |
| 1652 | |
| 1653 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1654 | * sas_rphy_delete - remove and free SAS remote PHY |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1655 | * @rphy: SAS remote PHY to remove and free |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1656 | * |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1657 | * Removes the specified SAS remote PHY and frees it. |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1658 | */ |
| 1659 | void |
| 1660 | sas_rphy_delete(struct sas_rphy *rphy) |
| 1661 | { |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1662 | sas_rphy_remove(rphy); |
| 1663 | sas_rphy_free(rphy); |
| 1664 | } |
| 1665 | EXPORT_SYMBOL(sas_rphy_delete); |
| 1666 | |
| 1667 | /** |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 1668 | * sas_rphy_unlink - unlink SAS remote PHY |
| 1669 | * @rphy: SAS remote phy to unlink from its parent port |
| 1670 | * |
| 1671 | * Removes port reference to an rphy |
| 1672 | */ |
| 1673 | void sas_rphy_unlink(struct sas_rphy *rphy) |
| 1674 | { |
| 1675 | struct sas_port *parent = dev_to_sas_port(rphy->dev.parent); |
| 1676 | |
| 1677 | parent->rphy = NULL; |
| 1678 | } |
| 1679 | EXPORT_SYMBOL(sas_rphy_unlink); |
| 1680 | |
| 1681 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1682 | * sas_rphy_remove - remove SAS remote PHY |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1683 | * @rphy: SAS remote phy to remove |
| 1684 | * |
| 1685 | * Removes the specified SAS remote PHY. |
| 1686 | */ |
| 1687 | void |
| 1688 | sas_rphy_remove(struct sas_rphy *rphy) |
| 1689 | { |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1690 | struct device *dev = &rphy->dev; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1691 | |
Christoph Hellwig | d405423 | 2006-01-04 13:45:20 +0100 | [diff] [blame] | 1692 | switch (rphy->identify.device_type) { |
| 1693 | case SAS_END_DEVICE: |
| 1694 | scsi_remove_target(dev); |
| 1695 | break; |
| 1696 | case SAS_EDGE_EXPANDER_DEVICE: |
| 1697 | case SAS_FANOUT_EXPANDER_DEVICE: |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1698 | sas_remove_children(dev); |
Christoph Hellwig | d405423 | 2006-01-04 13:45:20 +0100 | [diff] [blame] | 1699 | break; |
| 1700 | default: |
| 1701 | break; |
| 1702 | } |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1703 | |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 1704 | sas_rphy_unlink(rphy); |
Joe Lawrence | 6aa6caf | 2014-05-22 17:30:54 -0400 | [diff] [blame] | 1705 | sas_bsg_remove(NULL, rphy); |
Christoph Hellwig | fe8b230 | 2005-09-25 23:10:33 +0200 | [diff] [blame] | 1706 | transport_remove_device(dev); |
| 1707 | device_del(dev); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1708 | } |
Darrick J. Wong | 6f63caa | 2007-01-26 14:08:43 -0800 | [diff] [blame] | 1709 | EXPORT_SYMBOL(sas_rphy_remove); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1710 | |
| 1711 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1712 | * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1713 | * @dev: device to check |
| 1714 | * |
| 1715 | * Returns: |
| 1716 | * %1 if the device represents a SAS remote PHY, %0 else |
| 1717 | */ |
| 1718 | int scsi_is_sas_rphy(const struct device *dev) |
| 1719 | { |
James Bottomley | 2f8600d | 2006-03-18 15:00:50 -0600 | [diff] [blame] | 1720 | return dev->release == sas_end_device_release || |
| 1721 | dev->release == sas_expander_release; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1722 | } |
| 1723 | EXPORT_SYMBOL(scsi_is_sas_rphy); |
| 1724 | |
| 1725 | |
| 1726 | /* |
| 1727 | * SCSI scan helper |
| 1728 | */ |
| 1729 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1730 | static int sas_user_scan(struct Scsi_Host *shost, uint channel, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1731 | uint id, u64 lun) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1732 | { |
| 1733 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
| 1734 | struct sas_rphy *rphy; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1735 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1736 | mutex_lock(&sas_host->lock); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1737 | list_for_each_entry(rphy, &sas_host->rphy_list, list) { |
James Bottomley | 6d99a3f | 2006-05-19 10:49:37 -0500 | [diff] [blame] | 1738 | if (rphy->identify.device_type != SAS_END_DEVICE || |
| 1739 | rphy->scsi_target_id == -1) |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1740 | continue; |
| 1741 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1742 | if ((channel == SCAN_WILD_CARD || channel == 0) && |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1743 | (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1744 | scsi_scan_target(&rphy->dev, 0, rphy->scsi_target_id, |
| 1745 | lun, SCSI_SCAN_MANUAL); |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | mutex_unlock(&sas_host->lock); |
| 1749 | |
| 1750 | return 0; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | |
| 1754 | /* |
| 1755 | * Setup / Teardown code |
| 1756 | */ |
| 1757 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1758 | #define SETUP_TEMPLATE(attrb, field, perm, test) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1759 | i->private_##attrb[count] = dev_attr_##field; \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1760 | i->private_##attrb[count].attr.mode = perm; \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1761 | i->attrb[count] = &i->private_##attrb[count]; \ |
| 1762 | if (test) \ |
| 1763 | count++ |
| 1764 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1765 | #define SETUP_TEMPLATE_RW(attrb, field, perm, test, ro_test, ro_perm) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1766 | i->private_##attrb[count] = dev_attr_##field; \ |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1767 | i->private_##attrb[count].attr.mode = perm; \ |
| 1768 | if (ro_test) { \ |
| 1769 | i->private_##attrb[count].attr.mode = ro_perm; \ |
| 1770 | i->private_##attrb[count].store = NULL; \ |
| 1771 | } \ |
| 1772 | i->attrb[count] = &i->private_##attrb[count]; \ |
| 1773 | if (test) \ |
| 1774 | count++ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1775 | |
| 1776 | #define SETUP_RPORT_ATTRIBUTE(field) \ |
| 1777 | SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, 1) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1778 | |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 1779 | #define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1780 | SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func) |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 1781 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1782 | #define SETUP_PHY_ATTRIBUTE(field) \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1783 | SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1784 | |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1785 | #define SETUP_PHY_ATTRIBUTE_RW(field) \ |
| 1786 | SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \ |
| 1787 | !i->f->set_phy_speed, S_IRUGO) |
| 1788 | |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 1789 | #define SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(field, func) \ |
| 1790 | SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \ |
| 1791 | !i->f->func, S_IRUGO) |
| 1792 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1793 | #define SETUP_PORT_ATTRIBUTE(field) \ |
| 1794 | SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1) |
| 1795 | |
| 1796 | #define SETUP_OPTIONAL_PHY_ATTRIBUTE(field, func) \ |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1797 | SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func) |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 1798 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1799 | #define SETUP_PHY_ATTRIBUTE_WRONLY(field) \ |
Darrick J. Wong | fe3b5bf | 2007-01-11 14:15:35 -0800 | [diff] [blame] | 1800 | SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, 1) |
Christoph Hellwig | 07ba3a9 | 2005-10-19 20:01:31 +0200 | [diff] [blame] | 1801 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1802 | #define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \ |
Darrick J. Wong | fe3b5bf | 2007-01-11 14:15:35 -0800 | [diff] [blame] | 1803 | SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func) |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 1804 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1805 | #define SETUP_END_DEV_ATTRIBUTE(field) \ |
| 1806 | SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1) |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1807 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1808 | #define SETUP_EXPANDER_ATTRIBUTE(field) \ |
| 1809 | SETUP_TEMPLATE(expander_attrs, expander_##field, S_IRUGO, 1) |
| 1810 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1811 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1812 | * sas_attach_transport - instantiate SAS transport template |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1813 | * @ft: SAS transport class function template |
| 1814 | */ |
| 1815 | struct scsi_transport_template * |
| 1816 | sas_attach_transport(struct sas_function_template *ft) |
| 1817 | { |
| 1818 | struct sas_internal *i; |
| 1819 | int count; |
| 1820 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1821 | i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1822 | if (!i) |
| 1823 | return NULL; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1824 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1825 | i->t.user_scan = sas_user_scan; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1826 | |
| 1827 | i->t.host_attrs.ac.attrs = &i->host_attrs[0]; |
| 1828 | i->t.host_attrs.ac.class = &sas_host_class.class; |
| 1829 | i->t.host_attrs.ac.match = sas_host_match; |
| 1830 | transport_container_register(&i->t.host_attrs); |
| 1831 | i->t.host_size = sizeof(struct sas_host_attrs); |
| 1832 | |
| 1833 | i->phy_attr_cont.ac.class = &sas_phy_class.class; |
| 1834 | i->phy_attr_cont.ac.attrs = &i->phy_attrs[0]; |
| 1835 | i->phy_attr_cont.ac.match = sas_phy_match; |
| 1836 | transport_container_register(&i->phy_attr_cont); |
| 1837 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1838 | i->port_attr_cont.ac.class = &sas_port_class.class; |
| 1839 | i->port_attr_cont.ac.attrs = &i->port_attrs[0]; |
| 1840 | i->port_attr_cont.ac.match = sas_port_match; |
| 1841 | transport_container_register(&i->port_attr_cont); |
| 1842 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1843 | i->rphy_attr_cont.ac.class = &sas_rphy_class.class; |
| 1844 | i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; |
| 1845 | i->rphy_attr_cont.ac.match = sas_rphy_match; |
| 1846 | transport_container_register(&i->rphy_attr_cont); |
| 1847 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1848 | i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class; |
| 1849 | i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0]; |
| 1850 | i->end_dev_attr_cont.ac.match = sas_end_dev_match; |
| 1851 | transport_container_register(&i->end_dev_attr_cont); |
| 1852 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1853 | i->expander_attr_cont.ac.class = &sas_expander_class.class; |
| 1854 | i->expander_attr_cont.ac.attrs = &i->expander_attrs[0]; |
| 1855 | i->expander_attr_cont.ac.match = sas_expander_match; |
| 1856 | transport_container_register(&i->expander_attr_cont); |
| 1857 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1858 | i->f = ft; |
| 1859 | |
| 1860 | count = 0; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1861 | SETUP_PHY_ATTRIBUTE(initiator_port_protocols); |
| 1862 | SETUP_PHY_ATTRIBUTE(target_port_protocols); |
| 1863 | SETUP_PHY_ATTRIBUTE(device_type); |
| 1864 | SETUP_PHY_ATTRIBUTE(sas_address); |
| 1865 | SETUP_PHY_ATTRIBUTE(phy_identifier); |
| 1866 | //SETUP_PHY_ATTRIBUTE(port_identifier); |
| 1867 | SETUP_PHY_ATTRIBUTE(negotiated_linkrate); |
| 1868 | SETUP_PHY_ATTRIBUTE(minimum_linkrate_hw); |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1869 | SETUP_PHY_ATTRIBUTE_RW(minimum_linkrate); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1870 | SETUP_PHY_ATTRIBUTE(maximum_linkrate_hw); |
James Bottomley | d24e1ee | 2006-09-06 19:25:22 -0500 | [diff] [blame] | 1871 | SETUP_PHY_ATTRIBUTE_RW(maximum_linkrate); |
Christoph Hellwig | c3ee74c | 2005-09-19 21:59:42 +0200 | [diff] [blame] | 1872 | |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1873 | SETUP_PHY_ATTRIBUTE(invalid_dword_count); |
| 1874 | SETUP_PHY_ATTRIBUTE(running_disparity_error_count); |
| 1875 | SETUP_PHY_ATTRIBUTE(loss_of_dword_sync_count); |
| 1876 | SETUP_PHY_ATTRIBUTE(phy_reset_problem_count); |
| 1877 | SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset); |
| 1878 | SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 1879 | SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(enable, phy_enable); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1880 | i->phy_attrs[count] = NULL; |
| 1881 | |
| 1882 | count = 0; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1883 | SETUP_PORT_ATTRIBUTE(num_phys); |
| 1884 | i->port_attrs[count] = NULL; |
| 1885 | |
| 1886 | count = 0; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1887 | SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols); |
| 1888 | SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols); |
| 1889 | SETUP_RPORT_ATTRIBUTE(rphy_device_type); |
| 1890 | SETUP_RPORT_ATTRIBUTE(rphy_sas_address); |
| 1891 | SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier); |
Hannes Reinecke | cdc43ae | 2016-03-14 10:43:08 +0100 | [diff] [blame] | 1892 | SETUP_RPORT_ATTRIBUTE(rphy_scsi_target_id); |
James Bottomley | dd9fbb52 | 2006-03-02 16:01:31 -0600 | [diff] [blame] | 1893 | SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_enclosure_identifier, |
| 1894 | get_enclosure_identifier); |
| 1895 | SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_bay_identifier, |
| 1896 | get_bay_identifier); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1897 | i->rphy_attrs[count] = NULL; |
| 1898 | |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1899 | count = 0; |
| 1900 | SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning); |
| 1901 | SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout); |
| 1902 | SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout); |
James Bottomley | 0f88009 | 2010-01-18 10:14:51 -0600 | [diff] [blame] | 1903 | SETUP_END_DEV_ATTRIBUTE(end_dev_tlr_supported); |
| 1904 | SETUP_END_DEV_ATTRIBUTE(end_dev_tlr_enabled); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1905 | i->end_dev_attrs[count] = NULL; |
| 1906 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1907 | count = 0; |
| 1908 | SETUP_EXPANDER_ATTRIBUTE(vendor_id); |
| 1909 | SETUP_EXPANDER_ATTRIBUTE(product_id); |
| 1910 | SETUP_EXPANDER_ATTRIBUTE(product_rev); |
| 1911 | SETUP_EXPANDER_ATTRIBUTE(component_vendor_id); |
| 1912 | SETUP_EXPANDER_ATTRIBUTE(component_id); |
| 1913 | SETUP_EXPANDER_ATTRIBUTE(component_revision_id); |
| 1914 | SETUP_EXPANDER_ATTRIBUTE(level); |
| 1915 | i->expander_attrs[count] = NULL; |
| 1916 | |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1917 | return &i->t; |
| 1918 | } |
| 1919 | EXPORT_SYMBOL(sas_attach_transport); |
| 1920 | |
| 1921 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1922 | * sas_release_transport - release SAS transport template instance |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1923 | * @t: transport template instance |
| 1924 | */ |
| 1925 | void sas_release_transport(struct scsi_transport_template *t) |
| 1926 | { |
| 1927 | struct sas_internal *i = to_sas_internal(t); |
| 1928 | |
| 1929 | transport_container_unregister(&i->t.host_attrs); |
| 1930 | transport_container_unregister(&i->phy_attr_cont); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1931 | transport_container_unregister(&i->port_attr_cont); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1932 | transport_container_unregister(&i->rphy_attr_cont); |
James Bottomley | db82f84 | 2006-03-09 22:06:36 -0500 | [diff] [blame] | 1933 | transport_container_unregister(&i->end_dev_attr_cont); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1934 | transport_container_unregister(&i->expander_attr_cont); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1935 | |
| 1936 | kfree(i); |
| 1937 | } |
| 1938 | EXPORT_SYMBOL(sas_release_transport); |
| 1939 | |
| 1940 | static __init int sas_transport_init(void) |
| 1941 | { |
| 1942 | int error; |
| 1943 | |
| 1944 | error = transport_class_register(&sas_host_class); |
| 1945 | if (error) |
| 1946 | goto out; |
| 1947 | error = transport_class_register(&sas_phy_class); |
| 1948 | if (error) |
| 1949 | goto out_unregister_transport; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1950 | error = transport_class_register(&sas_port_class); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1951 | if (error) |
| 1952 | goto out_unregister_phy; |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1953 | error = transport_class_register(&sas_rphy_class); |
| 1954 | if (error) |
| 1955 | goto out_unregister_port; |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1956 | error = transport_class_register(&sas_end_dev_class); |
| 1957 | if (error) |
| 1958 | goto out_unregister_rphy; |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1959 | error = transport_class_register(&sas_expander_class); |
| 1960 | if (error) |
| 1961 | goto out_unregister_end_dev; |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1962 | |
| 1963 | return 0; |
| 1964 | |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1965 | out_unregister_end_dev: |
| 1966 | transport_class_unregister(&sas_end_dev_class); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1967 | out_unregister_rphy: |
| 1968 | transport_class_unregister(&sas_rphy_class); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1969 | out_unregister_port: |
| 1970 | transport_class_unregister(&sas_port_class); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1971 | out_unregister_phy: |
| 1972 | transport_class_unregister(&sas_phy_class); |
| 1973 | out_unregister_transport: |
| 1974 | transport_class_unregister(&sas_host_class); |
| 1975 | out: |
| 1976 | return error; |
| 1977 | |
| 1978 | } |
| 1979 | |
| 1980 | static void __exit sas_transport_exit(void) |
| 1981 | { |
| 1982 | transport_class_unregister(&sas_host_class); |
| 1983 | transport_class_unregister(&sas_phy_class); |
James Bottomley | 65c92b0 | 2006-06-28 12:22:50 -0400 | [diff] [blame] | 1984 | transport_class_unregister(&sas_port_class); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1985 | transport_class_unregister(&sas_rphy_class); |
James Bottomley | 42ab036 | 2006-03-04 09:10:18 -0600 | [diff] [blame] | 1986 | transport_class_unregister(&sas_end_dev_class); |
James Bottomley | 79cb181 | 2006-03-13 13:50:04 -0600 | [diff] [blame] | 1987 | transport_class_unregister(&sas_expander_class); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | MODULE_AUTHOR("Christoph Hellwig"); |
Alexis Bruemmer | 86b9c4c1 | 2007-01-16 15:36:12 -0800 | [diff] [blame] | 1991 | MODULE_DESCRIPTION("SAS Transport Attributes"); |
Christoph Hellwig | c7ebbbc | 2005-09-09 16:22:50 +0200 | [diff] [blame] | 1992 | MODULE_LICENSE("GPL"); |
| 1993 | |
| 1994 | module_init(sas_transport_init); |
| 1995 | module_exit(sas_transport_exit); |