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