Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Parallel SCSI (SPI) transport specific attributes exported to sysfs. |
| 3 | * |
| 4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. |
| 5 | * Copyright (c) 2004, 2005 James Bottomley <James.Bottomley@SteelEye.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | #include <linux/ctype.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/workqueue.h> |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 25 | #include <linux/blkdev.h> |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Randy Dunlap | 9f9a73b | 2008-04-23 09:56:14 -0700 | [diff] [blame] | 27 | #include <linux/sysfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| 30 | #include "scsi_priv.h" |
| 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_host.h> |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <scsi/scsi_eh.h> |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 35 | #include <scsi/scsi_tcq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <scsi/scsi_transport.h> |
| 37 | #include <scsi/scsi_transport_spi.h> |
| 38 | |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 39 | #define SPI_NUM_ATTRS 14 /* increase this if you add attributes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define SPI_OTHER_ATTRS 1 /* Increase this if you add "always |
| 41 | * on" attributes */ |
| 42 | #define SPI_HOST_ATTRS 1 |
| 43 | |
| 44 | #define SPI_MAX_ECHO_BUFFER_SIZE 4096 |
| 45 | |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 46 | #define DV_LOOPS 3 |
| 47 | #define DV_TIMEOUT (10*HZ) |
| 48 | #define DV_RETRIES 3 /* should only need at most |
| 49 | * two cc/ua clears */ |
| 50 | |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 51 | /* Our blacklist flags */ |
| 52 | enum { |
| 53 | SPI_BLIST_NOIUS = 0x1, |
| 54 | }; |
| 55 | |
| 56 | /* blacklist table, modelled on scsi_devinfo.c */ |
| 57 | static struct { |
| 58 | char *vendor; |
| 59 | char *model; |
| 60 | unsigned flags; |
| 61 | } spi_static_device_list[] __initdata = { |
| 62 | {"HP", "Ultrium 3-SCSI", SPI_BLIST_NOIUS }, |
| 63 | {"IBM", "ULTRIUM-TD3", SPI_BLIST_NOIUS }, |
| 64 | {NULL, NULL, 0} |
| 65 | }; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* Private data accessors (keep these out of the header file) */ |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 68 | #define spi_dv_in_progress(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_in_progress) |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 69 | #define spi_dv_mutex(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_mutex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | struct spi_internal { |
| 72 | struct scsi_transport_template t; |
| 73 | struct spi_function_template *f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #define to_spi_internal(tmpl) container_of(tmpl, struct spi_internal, t) |
| 77 | |
| 78 | static const int ppr_to_ps[] = { |
| 79 | /* The PPR values 0-6 are reserved, fill them in when |
| 80 | * the committee defines them */ |
| 81 | -1, /* 0x00 */ |
| 82 | -1, /* 0x01 */ |
| 83 | -1, /* 0x02 */ |
| 84 | -1, /* 0x03 */ |
| 85 | -1, /* 0x04 */ |
| 86 | -1, /* 0x05 */ |
| 87 | -1, /* 0x06 */ |
| 88 | 3125, /* 0x07 */ |
| 89 | 6250, /* 0x08 */ |
| 90 | 12500, /* 0x09 */ |
| 91 | 25000, /* 0x0a */ |
| 92 | 30300, /* 0x0b */ |
| 93 | 50000, /* 0x0c */ |
| 94 | }; |
| 95 | /* The PPR values at which you calculate the period in ns by multiplying |
| 96 | * by 4 */ |
| 97 | #define SPI_STATIC_PPR 0x0c |
| 98 | |
| 99 | static int sprint_frac(char *dest, int value, int denom) |
| 100 | { |
| 101 | int frac = value % denom; |
| 102 | int result = sprintf(dest, "%d", value / denom); |
| 103 | |
| 104 | if (frac == 0) |
| 105 | return result; |
| 106 | dest[result++] = '.'; |
| 107 | |
| 108 | do { |
| 109 | denom /= 10; |
| 110 | sprintf(dest + result, "%d", frac / denom); |
| 111 | result++; |
| 112 | frac %= denom; |
| 113 | } while (frac); |
| 114 | |
| 115 | dest[result++] = '\0'; |
| 116 | return result; |
| 117 | } |
| 118 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 119 | static int spi_execute(struct scsi_device *sdev, const void *cmd, |
| 120 | enum dma_data_direction dir, |
| 121 | void *buffer, unsigned bufflen, |
| 122 | struct scsi_sense_hdr *sshdr) |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 123 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 124 | int i, result; |
| 125 | unsigned char sense[SCSI_SENSE_BUFFERSIZE]; |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 126 | struct scsi_sense_hdr sshdr_tmp; |
| 127 | |
| 128 | if (!sshdr) |
| 129 | sshdr = &sshdr_tmp; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 130 | |
| 131 | for(i = 0; i < DV_RETRIES; i++) { |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 132 | result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense, |
| 133 | sshdr, DV_TIMEOUT, /* retries */ 1, |
Mike Christie | 6000a36 | 2008-08-19 18:45:30 -0500 | [diff] [blame] | 134 | REQ_FAILFAST_DEV | |
| 135 | REQ_FAILFAST_TRANSPORT | |
FUJITA Tomonori | f4f4e47 | 2008-12-04 14:24:39 +0900 | [diff] [blame] | 136 | REQ_FAILFAST_DRIVER, |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 137 | 0, NULL); |
| 138 | if (!(driver_byte(result) & DRIVER_SENSE) || |
| 139 | sshdr->sense_key != UNIT_ATTENTION) |
| 140 | break; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 141 | } |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 142 | return result; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static struct { |
| 146 | enum spi_signal_type value; |
| 147 | char *name; |
| 148 | } signal_types[] = { |
| 149 | { SPI_SIGNAL_UNKNOWN, "unknown" }, |
| 150 | { SPI_SIGNAL_SE, "SE" }, |
| 151 | { SPI_SIGNAL_LVD, "LVD" }, |
| 152 | { SPI_SIGNAL_HVD, "HVD" }, |
| 153 | }; |
| 154 | |
| 155 | static inline const char *spi_signal_to_string(enum spi_signal_type type) |
| 156 | { |
| 157 | int i; |
| 158 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 159 | for (i = 0; i < ARRAY_SIZE(signal_types); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (type == signal_types[i].value) |
| 161 | return signal_types[i].name; |
| 162 | } |
| 163 | return NULL; |
| 164 | } |
| 165 | static inline enum spi_signal_type spi_signal_to_value(const char *name) |
| 166 | { |
| 167 | int i, len; |
| 168 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 169 | for (i = 0; i < ARRAY_SIZE(signal_types); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | len = strlen(signal_types[i].name); |
| 171 | if (strncmp(name, signal_types[i].name, len) == 0 && |
| 172 | (name[len] == '\n' || name[len] == '\0')) |
| 173 | return signal_types[i].value; |
| 174 | } |
| 175 | return SPI_SIGNAL_UNKNOWN; |
| 176 | } |
| 177 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 178 | static int spi_host_setup(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 179 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 182 | |
| 183 | spi_signalling(shost) = SPI_SIGNAL_UNKNOWN; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 188 | static int spi_host_configure(struct transport_container *tc, |
| 189 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 190 | struct device *cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static DECLARE_TRANSPORT_CLASS(spi_host_class, |
| 193 | "spi_host", |
| 194 | spi_host_setup, |
| 195 | NULL, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 196 | spi_host_configure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | static int spi_host_match(struct attribute_container *cont, |
| 199 | struct device *dev) |
| 200 | { |
| 201 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | if (!scsi_is_host_device(dev)) |
| 204 | return 0; |
| 205 | |
| 206 | shost = dev_to_shost(dev); |
| 207 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 208 | != &spi_host_class.class) |
| 209 | return 0; |
| 210 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 211 | return &shost->transportt->host_attrs.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 214 | static int spi_target_configure(struct transport_container *tc, |
| 215 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 216 | struct device *cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 217 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 218 | static int spi_device_configure(struct transport_container *tc, |
| 219 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 220 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
| 222 | struct scsi_device *sdev = to_scsi_device(dev); |
| 223 | struct scsi_target *starget = sdev->sdev_target; |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 224 | unsigned bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8], |
| 225 | &sdev->inquiry[16], |
| 226 | SCSI_DEVINFO_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /* Populate the target capability fields with the values |
| 229 | * gleaned from the device inquiry */ |
| 230 | |
| 231 | spi_support_sync(starget) = scsi_device_sync(sdev); |
| 232 | spi_support_wide(starget) = scsi_device_wide(sdev); |
| 233 | spi_support_dt(starget) = scsi_device_dt(sdev); |
| 234 | spi_support_dt_only(starget) = scsi_device_dt_only(sdev); |
| 235 | spi_support_ius(starget) = scsi_device_ius(sdev); |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 236 | if (bflags & SPI_BLIST_NOIUS) { |
| 237 | dev_info(dev, "Information Units disabled by blacklist\n"); |
| 238 | spi_support_ius(starget) = 0; |
| 239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | spi_support_qas(starget) = scsi_device_qas(sdev); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 245 | static int spi_setup_transport_attrs(struct transport_container *tc, |
| 246 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 247 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | struct scsi_target *starget = to_scsi_target(dev); |
| 250 | |
| 251 | spi_period(starget) = -1; /* illegal value */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 252 | spi_min_period(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | spi_offset(starget) = 0; /* async */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 254 | spi_max_offset(starget) = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | spi_width(starget) = 0; /* narrow */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 256 | spi_max_width(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | spi_iu(starget) = 0; /* no IU */ |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 258 | spi_max_iu(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | spi_dt(starget) = 0; /* ST */ |
| 260 | spi_qas(starget) = 0; |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 261 | spi_max_qas(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | spi_wr_flow(starget) = 0; |
| 263 | spi_rd_strm(starget) = 0; |
| 264 | spi_rti(starget) = 0; |
| 265 | spi_pcomp_en(starget) = 0; |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 266 | spi_hold_mcs(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | spi_dv_pending(starget) = 0; |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 268 | spi_dv_in_progress(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | spi_initial_dv(starget) = 0; |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 270 | mutex_init(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 275 | #define spi_transport_show_simple(field, format_string) \ |
| 276 | \ |
| 277 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 278 | show_spi_transport_##field(struct device *dev, \ |
| 279 | struct device_attribute *attr, char *buf) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 280 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 281 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 282 | struct spi_transport_attrs *tp; \ |
| 283 | \ |
| 284 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 285 | return snprintf(buf, 20, format_string, tp->field); \ |
| 286 | } |
| 287 | |
| 288 | #define spi_transport_store_simple(field, format_string) \ |
| 289 | \ |
| 290 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 291 | store_spi_transport_##field(struct device *dev, \ |
| 292 | struct device_attribute *attr, \ |
| 293 | const char *buf, size_t count) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 294 | { \ |
| 295 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 296 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 297 | struct spi_transport_attrs *tp; \ |
| 298 | \ |
| 299 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 300 | val = simple_strtoul(buf, NULL, 0); \ |
| 301 | tp->field = val; \ |
| 302 | return count; \ |
| 303 | } |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | #define spi_transport_show_function(field, format_string) \ |
| 306 | \ |
| 307 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 308 | show_spi_transport_##field(struct device *dev, \ |
| 309 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 311 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 313 | struct spi_transport_attrs *tp; \ |
| 314 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 315 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 316 | if (i->f->get_##field) \ |
| 317 | i->f->get_##field(starget); \ |
| 318 | return snprintf(buf, 20, format_string, tp->field); \ |
| 319 | } |
| 320 | |
| 321 | #define spi_transport_store_function(field, format_string) \ |
| 322 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 323 | store_spi_transport_##field(struct device *dev, \ |
| 324 | struct device_attribute *attr, \ |
| 325 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { \ |
| 327 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 328 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 330 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 331 | \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 332 | if (!i->f->set_##field) \ |
| 333 | return -EINVAL; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | val = simple_strtoul(buf, NULL, 0); \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 335 | i->f->set_##field(starget, val); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 336 | return count; \ |
| 337 | } |
| 338 | |
| 339 | #define spi_transport_store_max(field, format_string) \ |
| 340 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 341 | store_spi_transport_##field(struct device *dev, \ |
| 342 | struct device_attribute *attr, \ |
| 343 | const char *buf, size_t count) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 344 | { \ |
| 345 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 346 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 347 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 348 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 349 | struct spi_transport_attrs *tp \ |
| 350 | = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 351 | \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 352 | if (i->f->set_##field) \ |
| 353 | return -EINVAL; \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 354 | val = simple_strtoul(buf, NULL, 0); \ |
| 355 | if (val > tp->max_##field) \ |
| 356 | val = tp->max_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | i->f->set_##field(starget, val); \ |
| 358 | return count; \ |
| 359 | } |
| 360 | |
| 361 | #define spi_transport_rd_attr(field, format_string) \ |
| 362 | spi_transport_show_function(field, format_string) \ |
| 363 | spi_transport_store_function(field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 364 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 365 | show_spi_transport_##field, \ |
| 366 | store_spi_transport_##field); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 368 | #define spi_transport_simple_attr(field, format_string) \ |
| 369 | spi_transport_show_simple(field, format_string) \ |
| 370 | spi_transport_store_simple(field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 371 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 372 | show_spi_transport_##field, \ |
| 373 | store_spi_transport_##field); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 374 | |
| 375 | #define spi_transport_max_attr(field, format_string) \ |
| 376 | spi_transport_show_function(field, format_string) \ |
| 377 | spi_transport_store_max(field, format_string) \ |
| 378 | spi_transport_simple_attr(max_##field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 379 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 380 | show_spi_transport_##field, \ |
| 381 | store_spi_transport_##field); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* The Parallel SCSI Tranport Attributes: */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 384 | spi_transport_max_attr(offset, "%d\n"); |
| 385 | spi_transport_max_attr(width, "%d\n"); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 386 | spi_transport_max_attr(iu, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | spi_transport_rd_attr(dt, "%d\n"); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 388 | spi_transport_max_attr(qas, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | spi_transport_rd_attr(wr_flow, "%d\n"); |
| 390 | spi_transport_rd_attr(rd_strm, "%d\n"); |
| 391 | spi_transport_rd_attr(rti, "%d\n"); |
| 392 | spi_transport_rd_attr(pcomp_en, "%d\n"); |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 393 | spi_transport_rd_attr(hold_mcs, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 395 | /* we only care about the first child device that's a real SCSI device |
| 396 | * so we return 1 to terminate the iteration when we find it */ |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 397 | static int child_iter(struct device *dev, void *data) |
| 398 | { |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 399 | if (!scsi_is_sdev_device(dev)) |
| 400 | return 0; |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 401 | |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 402 | spi_dv_device(to_scsi_device(dev)); |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 403 | return 1; |
| 404 | } |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 407 | store_spi_revalidate(struct device *dev, struct device_attribute *attr, |
| 408 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 410 | struct scsi_target *starget = transport_class_to_starget(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 412 | device_for_each_child(&starget->dev, NULL, child_iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return count; |
| 414 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 415 | static DEVICE_ATTR(revalidate, S_IWUSR, NULL, store_spi_revalidate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | /* Translate the period into ns according to the current spec |
| 418 | * for SDTR/PPR messages */ |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 419 | static int period_to_str(char *buf, int period) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | int len, picosec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 423 | if (period < 0 || period > 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | picosec = -1; |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 425 | } else if (period <= SPI_STATIC_PPR) { |
| 426 | picosec = ppr_to_ps[period]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } else { |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 428 | picosec = period * 4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | if (picosec == -1) { |
| 432 | len = sprintf(buf, "reserved"); |
| 433 | } else { |
| 434 | len = sprint_frac(buf, picosec, 1000); |
| 435 | } |
| 436 | |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 437 | return len; |
| 438 | } |
| 439 | |
| 440 | static ssize_t |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 441 | show_spi_transport_period_helper(char *buf, int period) |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 442 | { |
| 443 | int len = period_to_str(buf, period); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | buf[len++] = '\n'; |
| 445 | buf[len] = '\0'; |
| 446 | return len; |
| 447 | } |
| 448 | |
| 449 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 450 | store_spi_transport_period_helper(struct device *dev, const char *buf, |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 451 | size_t count, int *periodp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | int j, picosec, period = -1; |
| 454 | char *endp; |
| 455 | |
| 456 | picosec = simple_strtoul(buf, &endp, 10) * 1000; |
| 457 | if (*endp == '.') { |
| 458 | int mult = 100; |
| 459 | do { |
| 460 | endp++; |
| 461 | if (!isdigit(*endp)) |
| 462 | break; |
| 463 | picosec += (*endp - '0') * mult; |
| 464 | mult /= 10; |
| 465 | } while (mult > 0); |
| 466 | } |
| 467 | |
| 468 | for (j = 0; j <= SPI_STATIC_PPR; j++) { |
| 469 | if (ppr_to_ps[j] < picosec) |
| 470 | continue; |
| 471 | period = j; |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | if (period == -1) |
| 476 | period = picosec / 4000; |
| 477 | |
| 478 | if (period > 0xff) |
| 479 | period = 0xff; |
| 480 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 481 | *periodp = period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | return count; |
| 484 | } |
| 485 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 486 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 487 | show_spi_transport_period(struct device *dev, |
| 488 | struct device_attribute *attr, char *buf) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 489 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 490 | struct scsi_target *starget = transport_class_to_starget(dev); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 491 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 492 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 493 | struct spi_transport_attrs *tp = |
| 494 | (struct spi_transport_attrs *)&starget->starget_data; |
| 495 | |
| 496 | if (i->f->get_period) |
| 497 | i->f->get_period(starget); |
| 498 | |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 499 | return show_spi_transport_period_helper(buf, tp->period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 503 | store_spi_transport_period(struct device *cdev, struct device_attribute *attr, |
| 504 | const char *buf, size_t count) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 505 | { |
| 506 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 507 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 508 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 509 | struct spi_transport_attrs *tp = |
| 510 | (struct spi_transport_attrs *)&starget->starget_data; |
| 511 | int period, retval; |
| 512 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 513 | if (!i->f->set_period) |
| 514 | return -EINVAL; |
| 515 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 516 | retval = store_spi_transport_period_helper(cdev, buf, count, &period); |
| 517 | |
| 518 | if (period < tp->min_period) |
| 519 | period = tp->min_period; |
| 520 | |
| 521 | i->f->set_period(starget, period); |
| 522 | |
| 523 | return retval; |
| 524 | } |
| 525 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 526 | static DEVICE_ATTR(period, S_IRUGO, |
| 527 | show_spi_transport_period, |
| 528 | store_spi_transport_period); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 530 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 531 | show_spi_transport_min_period(struct device *cdev, |
| 532 | struct device_attribute *attr, char *buf) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 533 | { |
| 534 | struct scsi_target *starget = transport_class_to_starget(cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 535 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 536 | struct spi_internal *i = to_spi_internal(shost->transportt); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 537 | struct spi_transport_attrs *tp = |
| 538 | (struct spi_transport_attrs *)&starget->starget_data; |
| 539 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 540 | if (!i->f->set_period) |
| 541 | return -EINVAL; |
| 542 | |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 543 | return show_spi_transport_period_helper(buf, tp->min_period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 547 | store_spi_transport_min_period(struct device *cdev, |
| 548 | struct device_attribute *attr, |
| 549 | const char *buf, size_t count) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 550 | { |
| 551 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 552 | struct spi_transport_attrs *tp = |
| 553 | (struct spi_transport_attrs *)&starget->starget_data; |
| 554 | |
| 555 | return store_spi_transport_period_helper(cdev, buf, count, |
| 556 | &tp->min_period); |
| 557 | } |
| 558 | |
| 559 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 560 | static DEVICE_ATTR(min_period, S_IRUGO, |
| 561 | show_spi_transport_min_period, |
| 562 | store_spi_transport_min_period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 563 | |
| 564 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 565 | static ssize_t show_spi_host_signalling(struct device *cdev, |
| 566 | struct device_attribute *attr, |
| 567 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
| 569 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 570 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 571 | |
| 572 | if (i->f->get_signalling) |
| 573 | i->f->get_signalling(shost); |
| 574 | |
| 575 | return sprintf(buf, "%s\n", spi_signal_to_string(spi_signalling(shost))); |
| 576 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 577 | static ssize_t store_spi_host_signalling(struct device *dev, |
| 578 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | const char *buf, size_t count) |
| 580 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 581 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 583 | enum spi_signal_type type = spi_signal_to_value(buf); |
| 584 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 585 | if (!i->f->set_signalling) |
| 586 | return -EINVAL; |
| 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | if (type != SPI_SIGNAL_UNKNOWN) |
| 589 | i->f->set_signalling(shost, type); |
| 590 | |
| 591 | return count; |
| 592 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 593 | static DEVICE_ATTR(signalling, S_IRUGO, |
| 594 | show_spi_host_signalling, |
| 595 | store_spi_host_signalling); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Hannes Reinecke | 0ac2377 | 2011-06-30 02:19:57 +0530 | [diff] [blame] | 597 | static ssize_t show_spi_host_width(struct device *cdev, |
| 598 | struct device_attribute *attr, |
| 599 | char *buf) |
| 600 | { |
| 601 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 602 | |
| 603 | return sprintf(buf, "%s\n", shost->max_id == 16 ? "wide" : "narrow"); |
| 604 | } |
| 605 | static DEVICE_ATTR(host_width, S_IRUGO, |
| 606 | show_spi_host_width, NULL); |
| 607 | |
| 608 | static ssize_t show_spi_host_hba_id(struct device *cdev, |
| 609 | struct device_attribute *attr, |
| 610 | char *buf) |
| 611 | { |
| 612 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 613 | |
| 614 | return sprintf(buf, "%d\n", shost->this_id); |
| 615 | } |
| 616 | static DEVICE_ATTR(hba_id, S_IRUGO, |
| 617 | show_spi_host_hba_id, NULL); |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #define DV_SET(x, y) \ |
| 620 | if(i->f->set_##x) \ |
| 621 | i->f->set_##x(sdev->sdev_target, y) |
| 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | enum spi_compare_returns { |
| 624 | SPI_COMPARE_SUCCESS, |
| 625 | SPI_COMPARE_FAILURE, |
| 626 | SPI_COMPARE_SKIP_TEST, |
| 627 | }; |
| 628 | |
| 629 | |
| 630 | /* This is for read/write Domain Validation: If the device supports |
| 631 | * an echo buffer, we do read/write tests to it */ |
| 632 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 633 | spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | u8 *ptr, const int retries) |
| 635 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | int len = ptr - buffer; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 637 | int j, k, r, result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | unsigned int pattern = 0x0000ffff; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 639 | struct scsi_sense_hdr sshdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | const char spi_write_buffer[] = { |
| 642 | WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 |
| 643 | }; |
| 644 | const char spi_read_buffer[] = { |
| 645 | READ_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 |
| 646 | }; |
| 647 | |
| 648 | /* set up the pattern buffer. Doesn't matter if we spill |
| 649 | * slightly beyond since that's where the read buffer is */ |
| 650 | for (j = 0; j < len; ) { |
| 651 | |
| 652 | /* fill the buffer with counting (test a) */ |
| 653 | for ( ; j < min(len, 32); j++) |
| 654 | buffer[j] = j; |
| 655 | k = j; |
| 656 | /* fill the buffer with alternating words of 0x0 and |
| 657 | * 0xffff (test b) */ |
| 658 | for ( ; j < min(len, k + 32); j += 2) { |
| 659 | u16 *word = (u16 *)&buffer[j]; |
| 660 | |
| 661 | *word = (j & 0x02) ? 0x0000 : 0xffff; |
| 662 | } |
| 663 | k = j; |
| 664 | /* fill with crosstalk (alternating 0x5555 0xaaa) |
| 665 | * (test c) */ |
| 666 | for ( ; j < min(len, k + 32); j += 2) { |
| 667 | u16 *word = (u16 *)&buffer[j]; |
| 668 | |
| 669 | *word = (j & 0x02) ? 0x5555 : 0xaaaa; |
| 670 | } |
| 671 | k = j; |
| 672 | /* fill with shifting bits (test d) */ |
| 673 | for ( ; j < min(len, k + 32); j += 4) { |
| 674 | u32 *word = (unsigned int *)&buffer[j]; |
| 675 | u32 roll = (pattern & 0x80000000) ? 1 : 0; |
| 676 | |
| 677 | *word = pattern; |
| 678 | pattern = (pattern << 1) | roll; |
| 679 | } |
| 680 | /* don't bother with random data (test e) */ |
| 681 | } |
| 682 | |
| 683 | for (r = 0; r < retries; r++) { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 684 | result = spi_execute(sdev, spi_write_buffer, DMA_TO_DEVICE, |
| 685 | buffer, len, &sshdr); |
| 686 | if(result || !scsi_device_online(sdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 689 | if (scsi_sense_valid(&sshdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | && sshdr.sense_key == ILLEGAL_REQUEST |
| 691 | /* INVALID FIELD IN CDB */ |
| 692 | && sshdr.asc == 0x24 && sshdr.ascq == 0x00) |
| 693 | /* This would mean that the drive lied |
| 694 | * to us about supporting an echo |
| 695 | * buffer (unfortunately some Western |
| 696 | * Digital drives do precisely this) |
| 697 | */ |
| 698 | return SPI_COMPARE_SKIP_TEST; |
| 699 | |
| 700 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 701 | sdev_printk(KERN_ERR, sdev, "Write Buffer failure %x\n", result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | return SPI_COMPARE_FAILURE; |
| 703 | } |
| 704 | |
| 705 | memset(ptr, 0, len); |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 706 | spi_execute(sdev, spi_read_buffer, DMA_FROM_DEVICE, |
| 707 | ptr, len, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
| 709 | |
| 710 | if (memcmp(buffer, ptr, len) != 0) |
| 711 | return SPI_COMPARE_FAILURE; |
| 712 | } |
| 713 | return SPI_COMPARE_SUCCESS; |
| 714 | } |
| 715 | |
| 716 | /* This is for the simplest form of Domain Validation: a read test |
| 717 | * on the inquiry data from the device */ |
| 718 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 719 | spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | u8 *ptr, const int retries) |
| 721 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 722 | int r, result; |
| 723 | const int len = sdev->inquiry_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | const char spi_inquiry[] = { |
| 725 | INQUIRY, 0, 0, 0, len, 0 |
| 726 | }; |
| 727 | |
| 728 | for (r = 0; r < retries; r++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | memset(ptr, 0, len); |
| 730 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 731 | result = spi_execute(sdev, spi_inquiry, DMA_FROM_DEVICE, |
| 732 | ptr, len, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 734 | if(result || !scsi_device_online(sdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
| 736 | return SPI_COMPARE_FAILURE; |
| 737 | } |
| 738 | |
| 739 | /* If we don't have the inquiry data already, the |
| 740 | * first read gets it */ |
| 741 | if (ptr == buffer) { |
| 742 | ptr += len; |
| 743 | --r; |
| 744 | continue; |
| 745 | } |
| 746 | |
| 747 | if (memcmp(buffer, ptr, len) != 0) |
| 748 | /* failure */ |
| 749 | return SPI_COMPARE_FAILURE; |
| 750 | } |
| 751 | return SPI_COMPARE_SUCCESS; |
| 752 | } |
| 753 | |
| 754 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 755 | spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 757 | (*compare_fn)(struct scsi_device *, u8 *, u8 *, int)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 759 | struct spi_internal *i = to_spi_internal(sdev->host->transportt); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 760 | struct scsi_target *starget = sdev->sdev_target; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | int period = 0, prevperiod = 0; |
| 762 | enum spi_compare_returns retval; |
| 763 | |
| 764 | |
| 765 | for (;;) { |
| 766 | int newperiod; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 767 | retval = compare_fn(sdev, buffer, ptr, DV_LOOPS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
| 769 | if (retval == SPI_COMPARE_SUCCESS |
| 770 | || retval == SPI_COMPARE_SKIP_TEST) |
| 771 | break; |
| 772 | |
| 773 | /* OK, retrain, fallback */ |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 774 | if (i->f->get_iu) |
| 775 | i->f->get_iu(starget); |
| 776 | if (i->f->get_qas) |
| 777 | i->f->get_qas(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | if (i->f->get_period) |
| 779 | i->f->get_period(sdev->sdev_target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 781 | /* Here's the fallback sequence; first try turning off |
| 782 | * IU, then QAS (if we can control them), then finally |
| 783 | * fall down the periods */ |
| 784 | if (i->f->set_iu && spi_iu(starget)) { |
Masanari Iida | 804ff60 | 2015-05-07 23:21:27 +0900 | [diff] [blame] | 785 | starget_printk(KERN_ERR, starget, "Domain Validation Disabling Information Units\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 786 | DV_SET(iu, 0); |
| 787 | } else if (i->f->set_qas && spi_qas(starget)) { |
Masanari Iida | 804ff60 | 2015-05-07 23:21:27 +0900 | [diff] [blame] | 788 | starget_printk(KERN_ERR, starget, "Domain Validation Disabling Quick Arbitration and Selection\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 789 | DV_SET(qas, 0); |
| 790 | } else { |
| 791 | newperiod = spi_period(starget); |
| 792 | period = newperiod > period ? newperiod : period; |
| 793 | if (period < 0x0d) |
| 794 | period++; |
| 795 | else |
| 796 | period += period >> 1; |
| 797 | |
| 798 | if (unlikely(period > 0xff || period == prevperiod)) { |
| 799 | /* Total failure; set to async and return */ |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 800 | starget_printk(KERN_ERR, starget, "Domain Validation Failure, dropping back to Asynchronous\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 801 | DV_SET(offset, 0); |
| 802 | return SPI_COMPARE_FAILURE; |
| 803 | } |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 804 | starget_printk(KERN_ERR, starget, "Domain Validation detected failure, dropping back\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 805 | DV_SET(period, period); |
| 806 | prevperiod = period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | return retval; |
| 810 | } |
| 811 | |
| 812 | static int |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 813 | spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 815 | int l, result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | /* first off do a test unit ready. This can error out |
| 818 | * because of reservations or some other reason. If it |
| 819 | * fails, the device won't let us write to the echo buffer |
| 820 | * so just return failure */ |
| 821 | |
| 822 | const char spi_test_unit_ready[] = { |
| 823 | TEST_UNIT_READY, 0, 0, 0, 0, 0 |
| 824 | }; |
| 825 | |
| 826 | const char spi_read_buffer_descriptor[] = { |
| 827 | READ_BUFFER, 0x0b, 0, 0, 0, 0, 0, 0, 4, 0 |
| 828 | }; |
| 829 | |
| 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | /* We send a set of three TURs to clear any outstanding |
| 832 | * unit attention conditions if they exist (Otherwise the |
| 833 | * buffer tests won't be happy). If the TUR still fails |
| 834 | * (reservation conflict, device not ready, etc) just |
| 835 | * skip the write tests */ |
| 836 | for (l = 0; ; l++) { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 837 | result = spi_execute(sdev, spi_test_unit_ready, DMA_NONE, |
| 838 | NULL, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 840 | if(result) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if(l >= 3) |
| 842 | return 0; |
| 843 | } else { |
| 844 | /* TUR succeeded */ |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 849 | result = spi_execute(sdev, spi_read_buffer_descriptor, |
| 850 | DMA_FROM_DEVICE, buffer, 4, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 852 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | /* Device has no echo buffer */ |
| 854 | return 0; |
| 855 | |
| 856 | return buffer[3] + ((buffer[2] & 0x1f) << 8); |
| 857 | } |
| 858 | |
| 859 | static void |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 860 | spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 862 | struct spi_internal *i = to_spi_internal(sdev->host->transportt); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 863 | struct scsi_target *starget = sdev->sdev_target; |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 864 | struct Scsi_Host *shost = sdev->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | int len = sdev->inquiry_len; |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 866 | int min_period = spi_min_period(starget); |
| 867 | int max_width = spi_max_width(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* first set us up for narrow async */ |
| 869 | DV_SET(offset, 0); |
| 870 | DV_SET(width, 0); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 871 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 872 | if (spi_dv_device_compare_inquiry(sdev, buffer, buffer, DV_LOOPS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | != SPI_COMPARE_SUCCESS) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 874 | starget_printk(KERN_ERR, starget, "Domain Validation Initial Inquiry Failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | /* FIXME: should probably offline the device here? */ |
| 876 | return; |
| 877 | } |
| 878 | |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 879 | if (!spi_support_wide(starget)) { |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 880 | spi_max_width(starget) = 0; |
| 881 | max_width = 0; |
| 882 | } |
| 883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | /* test width */ |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 885 | if (i->f->set_width && max_width) { |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 886 | i->f->set_width(starget, 1); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 887 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 888 | if (spi_dv_device_compare_inquiry(sdev, buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | buffer + len, |
| 890 | DV_LOOPS) |
| 891 | != SPI_COMPARE_SUCCESS) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 892 | starget_printk(KERN_ERR, starget, "Wide Transfers Fail\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 893 | i->f->set_width(starget, 0); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 894 | /* Make sure we don't force wide back on by asking |
| 895 | * for a transfer period that requires it */ |
| 896 | max_width = 0; |
| 897 | if (min_period < 10) |
| 898 | min_period = 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | if (!i->f->set_period) |
| 903 | return; |
| 904 | |
| 905 | /* device can't handle synchronous */ |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 906 | if (!spi_support_sync(starget) && !spi_support_dt(starget)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | return; |
| 908 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 909 | /* len == -1 is the signal that we need to ascertain the |
| 910 | * presence of an echo buffer before trying to use it. len == |
| 911 | * 0 means we don't have an echo buffer */ |
| 912 | len = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | retry: |
| 915 | |
| 916 | /* now set up to the maximum */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 917 | DV_SET(offset, spi_max_offset(starget)); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 918 | DV_SET(period, min_period); |
| 919 | |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 920 | /* try QAS requests; this should be harmless to set if the |
| 921 | * target supports it */ |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 922 | if (spi_support_qas(starget) && spi_max_qas(starget)) { |
James Bottomley | eb1dd68 | 2005-07-02 12:22:01 -0400 | [diff] [blame] | 923 | DV_SET(qas, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 924 | } else { |
| 925 | DV_SET(qas, 0); |
| 926 | } |
| 927 | |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 928 | if (spi_support_ius(starget) && spi_max_iu(starget) && |
| 929 | min_period < 9) { |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 930 | /* This u320 (or u640). Set IU transfers */ |
James Bottomley | eb1dd68 | 2005-07-02 12:22:01 -0400 | [diff] [blame] | 931 | DV_SET(iu, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 932 | /* Then set the optional parameters */ |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 933 | DV_SET(rd_strm, 1); |
| 934 | DV_SET(wr_flow, 1); |
| 935 | DV_SET(rti, 1); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 936 | if (min_period == 8) |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 937 | DV_SET(pcomp_en, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 938 | } else { |
| 939 | DV_SET(iu, 0); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 940 | } |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 941 | |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 942 | /* now that we've done all this, actually check the bus |
| 943 | * signal type (if known). Some devices are stupid on |
| 944 | * a SE bus and still claim they can try LVD only settings */ |
| 945 | if (i->f->get_signalling) |
| 946 | i->f->get_signalling(shost); |
| 947 | if (spi_signalling(shost) == SPI_SIGNAL_SE || |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 948 | spi_signalling(shost) == SPI_SIGNAL_HVD || |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 949 | !spi_support_dt(starget)) { |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 950 | DV_SET(dt, 0); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 951 | } else { |
| 952 | DV_SET(dt, 1); |
| 953 | } |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 954 | /* set width last because it will pull all the other |
| 955 | * parameters down to required values */ |
| 956 | DV_SET(width, max_width); |
| 957 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 958 | /* Do the read only INQUIRY tests */ |
| 959 | spi_dv_retrain(sdev, buffer, buffer + sdev->inquiry_len, |
| 960 | spi_dv_device_compare_inquiry); |
| 961 | /* See if we actually managed to negotiate and sustain DT */ |
| 962 | if (i->f->get_dt) |
| 963 | i->f->get_dt(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 965 | /* see if the device has an echo buffer. If it does we can do |
| 966 | * the SPI pattern write tests. Because of some broken |
| 967 | * devices, we *only* try this on a device that has actually |
| 968 | * negotiated DT */ |
| 969 | |
| 970 | if (len == -1 && spi_dt(starget)) |
| 971 | len = spi_dv_device_get_echo_buffer(sdev, buffer); |
| 972 | |
| 973 | if (len <= 0) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 974 | starget_printk(KERN_INFO, starget, "Domain Validation skipping write tests\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return; |
| 976 | } |
| 977 | |
| 978 | if (len > SPI_MAX_ECHO_BUFFER_SIZE) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 979 | starget_printk(KERN_WARNING, starget, "Echo buffer size %d is too big, trimming to %d\n", len, SPI_MAX_ECHO_BUFFER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | len = SPI_MAX_ECHO_BUFFER_SIZE; |
| 981 | } |
| 982 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 983 | if (spi_dv_retrain(sdev, buffer, buffer + len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | spi_dv_device_echo_buffer) |
| 985 | == SPI_COMPARE_SKIP_TEST) { |
| 986 | /* OK, the stupid drive can't do a write echo buffer |
| 987 | * test after all, fall back to the read tests */ |
| 988 | len = 0; |
| 989 | goto retry; |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | |
| 994 | /** spi_dv_device - Do Domain Validation on the device |
| 995 | * @sdev: scsi device to validate |
| 996 | * |
| 997 | * Performs the domain validation on the given device in the |
| 998 | * current execution thread. Since DV operations may sleep, |
| 999 | * the current thread must have user context. Also no SCSI |
| 1000 | * related locks that would deadlock I/O issued by the DV may |
| 1001 | * be held. |
| 1002 | */ |
| 1003 | void |
| 1004 | spi_dv_device(struct scsi_device *sdev) |
| 1005 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | struct scsi_target *starget = sdev->sdev_target; |
| 1007 | u8 *buffer; |
| 1008 | const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; |
| 1009 | |
Mike Maslenkin | 89a342c | 2012-04-28 05:32:14 +0400 | [diff] [blame] | 1010 | if (unlikely(spi_dv_in_progress(starget))) |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 1011 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Mike Maslenkin | 89a342c | 2012-04-28 05:32:14 +0400 | [diff] [blame] | 1013 | if (unlikely(scsi_device_get(sdev))) |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 1014 | return; |
| 1015 | spi_dv_in_progress(starget) = 1; |
| 1016 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1017 | buffer = kzalloc(len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | if (unlikely(!buffer)) |
| 1020 | goto out_put; |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | /* We need to verify that the actual device will quiesce; the |
| 1023 | * later target quiesce is just a nice to have */ |
| 1024 | if (unlikely(scsi_device_quiesce(sdev))) |
| 1025 | goto out_free; |
| 1026 | |
| 1027 | scsi_target_quiesce(starget); |
| 1028 | |
| 1029 | spi_dv_pending(starget) = 1; |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 1030 | mutex_lock(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 1032 | starget_printk(KERN_INFO, starget, "Beginning Domain Validation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 1034 | spi_dv_device_internal(sdev, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 1036 | starget_printk(KERN_INFO, starget, "Ending Domain Validation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 1038 | mutex_unlock(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | spi_dv_pending(starget) = 0; |
| 1040 | |
| 1041 | scsi_target_resume(starget); |
| 1042 | |
| 1043 | spi_initial_dv(starget) = 1; |
| 1044 | |
| 1045 | out_free: |
| 1046 | kfree(buffer); |
| 1047 | out_put: |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 1048 | spi_dv_in_progress(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | scsi_device_put(sdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
| 1051 | EXPORT_SYMBOL(spi_dv_device); |
| 1052 | |
| 1053 | struct work_queue_wrapper { |
| 1054 | struct work_struct work; |
| 1055 | struct scsi_device *sdev; |
| 1056 | }; |
| 1057 | |
| 1058 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1059 | spi_dv_device_work_wrapper(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1061 | struct work_queue_wrapper *wqw = |
| 1062 | container_of(work, struct work_queue_wrapper, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | struct scsi_device *sdev = wqw->sdev; |
| 1064 | |
| 1065 | kfree(wqw); |
| 1066 | spi_dv_device(sdev); |
| 1067 | spi_dv_pending(sdev->sdev_target) = 0; |
| 1068 | scsi_device_put(sdev); |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | /** |
| 1073 | * spi_schedule_dv_device - schedule domain validation to occur on the device |
| 1074 | * @sdev: The device to validate |
| 1075 | * |
| 1076 | * Identical to spi_dv_device() above, except that the DV will be |
| 1077 | * scheduled to occur in a workqueue later. All memory allocations |
| 1078 | * are atomic, so may be called from any context including those holding |
| 1079 | * SCSI locks. |
| 1080 | */ |
| 1081 | void |
| 1082 | spi_schedule_dv_device(struct scsi_device *sdev) |
| 1083 | { |
| 1084 | struct work_queue_wrapper *wqw = |
| 1085 | kmalloc(sizeof(struct work_queue_wrapper), GFP_ATOMIC); |
| 1086 | |
| 1087 | if (unlikely(!wqw)) |
| 1088 | return; |
| 1089 | |
| 1090 | if (unlikely(spi_dv_pending(sdev->sdev_target))) { |
| 1091 | kfree(wqw); |
| 1092 | return; |
| 1093 | } |
| 1094 | /* Set pending early (dv_device doesn't check it, only sets it) */ |
| 1095 | spi_dv_pending(sdev->sdev_target) = 1; |
| 1096 | if (unlikely(scsi_device_get(sdev))) { |
| 1097 | kfree(wqw); |
| 1098 | spi_dv_pending(sdev->sdev_target) = 0; |
| 1099 | return; |
| 1100 | } |
| 1101 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1102 | INIT_WORK(&wqw->work, spi_dv_device_work_wrapper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | wqw->sdev = sdev; |
| 1104 | |
| 1105 | schedule_work(&wqw->work); |
| 1106 | } |
| 1107 | EXPORT_SYMBOL(spi_schedule_dv_device); |
| 1108 | |
| 1109 | /** |
| 1110 | * spi_display_xfer_agreement - Print the current target transfer agreement |
| 1111 | * @starget: The target for which to display the agreement |
| 1112 | * |
| 1113 | * Each SPI port is required to maintain a transfer agreement for each |
| 1114 | * other port on the bus. This function prints a one-line summary of |
| 1115 | * the current agreement; more detailed information is available in sysfs. |
| 1116 | */ |
| 1117 | void spi_display_xfer_agreement(struct scsi_target *starget) |
| 1118 | { |
| 1119 | struct spi_transport_attrs *tp; |
| 1120 | tp = (struct spi_transport_attrs *)&starget->starget_data; |
| 1121 | |
| 1122 | if (tp->offset > 0 && tp->period > 0) { |
| 1123 | unsigned int picosec, kb100; |
| 1124 | char *scsi = "FAST-?"; |
| 1125 | char tmp[8]; |
| 1126 | |
| 1127 | if (tp->period <= SPI_STATIC_PPR) { |
| 1128 | picosec = ppr_to_ps[tp->period]; |
| 1129 | switch (tp->period) { |
| 1130 | case 7: scsi = "FAST-320"; break; |
| 1131 | case 8: scsi = "FAST-160"; break; |
| 1132 | case 9: scsi = "FAST-80"; break; |
| 1133 | case 10: |
| 1134 | case 11: scsi = "FAST-40"; break; |
| 1135 | case 12: scsi = "FAST-20"; break; |
| 1136 | } |
| 1137 | } else { |
| 1138 | picosec = tp->period * 4000; |
| 1139 | if (tp->period < 25) |
| 1140 | scsi = "FAST-20"; |
| 1141 | else if (tp->period < 50) |
| 1142 | scsi = "FAST-10"; |
| 1143 | else |
| 1144 | scsi = "FAST-5"; |
| 1145 | } |
| 1146 | |
| 1147 | kb100 = (10000000 + picosec / 2) / picosec; |
| 1148 | if (tp->width) |
| 1149 | kb100 *= 2; |
| 1150 | sprint_frac(tmp, picosec, 1000); |
| 1151 | |
| 1152 | dev_info(&starget->dev, |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 1153 | "%s %sSCSI %d.%d MB/s %s%s%s%s%s%s%s%s (%s ns, offset %d)\n", |
| 1154 | scsi, tp->width ? "WIDE " : "", kb100/10, kb100 % 10, |
| 1155 | tp->dt ? "DT" : "ST", |
| 1156 | tp->iu ? " IU" : "", |
| 1157 | tp->qas ? " QAS" : "", |
| 1158 | tp->rd_strm ? " RDSTRM" : "", |
| 1159 | tp->rti ? " RTI" : "", |
| 1160 | tp->wr_flow ? " WRFLOW" : "", |
| 1161 | tp->pcomp_en ? " PCOMP" : "", |
| 1162 | tp->hold_mcs ? " HMCS" : "", |
| 1163 | tmp, tp->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } else { |
Matthew Wilcox | 493ff4e | 2005-11-17 11:13:43 -0700 | [diff] [blame] | 1165 | dev_info(&starget->dev, "%sasynchronous\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | tp->width ? "wide " : ""); |
| 1167 | } |
| 1168 | } |
| 1169 | EXPORT_SYMBOL(spi_display_xfer_agreement); |
| 1170 | |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1171 | int spi_populate_width_msg(unsigned char *msg, int width) |
| 1172 | { |
| 1173 | msg[0] = EXTENDED_MESSAGE; |
| 1174 | msg[1] = 2; |
| 1175 | msg[2] = EXTENDED_WDTR; |
| 1176 | msg[3] = width; |
| 1177 | return 4; |
| 1178 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1179 | EXPORT_SYMBOL_GPL(spi_populate_width_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1180 | |
| 1181 | int spi_populate_sync_msg(unsigned char *msg, int period, int offset) |
| 1182 | { |
| 1183 | msg[0] = EXTENDED_MESSAGE; |
| 1184 | msg[1] = 3; |
| 1185 | msg[2] = EXTENDED_SDTR; |
| 1186 | msg[3] = period; |
| 1187 | msg[4] = offset; |
| 1188 | return 5; |
| 1189 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1190 | EXPORT_SYMBOL_GPL(spi_populate_sync_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1191 | |
| 1192 | int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, |
| 1193 | int width, int options) |
| 1194 | { |
| 1195 | msg[0] = EXTENDED_MESSAGE; |
| 1196 | msg[1] = 6; |
| 1197 | msg[2] = EXTENDED_PPR; |
| 1198 | msg[3] = period; |
| 1199 | msg[4] = 0; |
| 1200 | msg[5] = offset; |
| 1201 | msg[6] = width; |
| 1202 | msg[7] = options; |
| 1203 | return 8; |
| 1204 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1205 | EXPORT_SYMBOL_GPL(spi_populate_ppr_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1206 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1207 | /** |
| 1208 | * spi_populate_tag_msg - place a tag message in a buffer |
| 1209 | * @msg: pointer to the area to place the tag |
| 1210 | * @cmd: pointer to the scsi command for the tag |
| 1211 | * |
| 1212 | * Notes: |
| 1213 | * designed to create the correct type of tag message for the |
| 1214 | * particular request. Returns the size of the tag message. |
| 1215 | * May return 0 if TCQ is disabled for this device. |
| 1216 | **/ |
| 1217 | int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd) |
| 1218 | { |
| 1219 | if (cmd->flags & SCMD_TAGGED) { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 1220 | *msg++ = SIMPLE_QUEUE_TAG; |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1221 | *msg++ = cmd->request->tag; |
| 1222 | return 2; |
| 1223 | } |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | EXPORT_SYMBOL_GPL(spi_populate_tag_msg); |
| 1228 | |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1229 | #ifdef CONFIG_SCSI_CONSTANTS |
| 1230 | static const char * const one_byte_msgs[] = { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1231 | /* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers", |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1232 | /* 0x03 */ "Restore Pointers", "Disconnect", "Initiator Error", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1233 | /* 0x06 */ "Abort Task Set", "Message Reject", "Nop", "Message Parity Error", |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1234 | /* 0x0a */ "Linked Command Complete", "Linked Command Complete w/flag", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1235 | /* 0x0c */ "Target Reset", "Abort Task", "Clear Task Set", |
| 1236 | /* 0x0f */ "Initiate Recovery", "Release Recovery", |
| 1237 | /* 0x11 */ "Terminate Process", "Continue Task", "Target Transfer Disable", |
| 1238 | /* 0x14 */ NULL, NULL, "Clear ACA", "LUN Reset" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1239 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1240 | |
| 1241 | static const char * const two_byte_msgs[] = { |
Matthew Wilcox | 4797215 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1242 | /* 0x20 */ "Simple Queue Tag", "Head of Queue Tag", "Ordered Queue Tag", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1243 | /* 0x23 */ "Ignore Wide Residue", "ACA" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1244 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1245 | |
| 1246 | static const char * const extended_msgs[] = { |
| 1247 | /* 0x00 */ "Modify Data Pointer", "Synchronous Data Transfer Request", |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1248 | /* 0x02 */ "SCSI-I Extended Identify", "Wide Data Transfer Request", |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1249 | /* 0x04 */ "Parallel Protocol Request", "Modify Bidirectional Data Pointer" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1250 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1251 | |
Adrian Bunk | bdd70f2 | 2006-01-05 23:39:18 +0100 | [diff] [blame] | 1252 | static void print_nego(const unsigned char *msg, int per, int off, int width) |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1253 | { |
| 1254 | if (per) { |
| 1255 | char buf[20]; |
| 1256 | period_to_str(buf, msg[per]); |
| 1257 | printk("period = %s ns ", buf); |
| 1258 | } |
| 1259 | |
| 1260 | if (off) |
| 1261 | printk("offset = %d ", msg[off]); |
| 1262 | if (width) |
| 1263 | printk("width = %d ", 8 << msg[width]); |
| 1264 | } |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1265 | |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1266 | static void print_ptr(const unsigned char *msg, int msb, const char *desc) |
| 1267 | { |
| 1268 | int ptr = (msg[msb] << 24) | (msg[msb+1] << 16) | (msg[msb+2] << 8) | |
| 1269 | msg[msb+3]; |
| 1270 | printk("%s = %d ", desc, ptr); |
| 1271 | } |
| 1272 | |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1273 | int spi_print_msg(const unsigned char *msg) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1274 | { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1275 | int len = 1, i; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1276 | if (msg[0] == EXTENDED_MESSAGE) { |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1277 | len = 2 + msg[1]; |
| 1278 | if (len == 2) |
| 1279 | len += 256; |
Matthew Wilcox | b32aaff | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1280 | if (msg[2] < ARRAY_SIZE(extended_msgs)) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1281 | printk ("%s ", extended_msgs[msg[2]]); |
| 1282 | else |
| 1283 | printk ("Extended Message, reserved code (0x%02x) ", |
| 1284 | (int) msg[2]); |
| 1285 | switch (msg[2]) { |
| 1286 | case EXTENDED_MODIFY_DATA_POINTER: |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1287 | print_ptr(msg, 3, "pointer"); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1288 | break; |
| 1289 | case EXTENDED_SDTR: |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1290 | print_nego(msg, 3, 4, 0); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1291 | break; |
| 1292 | case EXTENDED_WDTR: |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1293 | print_nego(msg, 0, 0, 3); |
| 1294 | break; |
| 1295 | case EXTENDED_PPR: |
| 1296 | print_nego(msg, 3, 5, 6); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1297 | break; |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1298 | case EXTENDED_MODIFY_BIDI_DATA_PTR: |
| 1299 | print_ptr(msg, 3, "out"); |
| 1300 | print_ptr(msg, 7, "in"); |
| 1301 | break; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1302 | default: |
| 1303 | for (i = 2; i < len; ++i) |
| 1304 | printk("%02x ", msg[i]); |
| 1305 | } |
| 1306 | /* Identify */ |
| 1307 | } else if (msg[0] & 0x80) { |
| 1308 | printk("Identify disconnect %sallowed %s %d ", |
| 1309 | (msg[0] & 0x40) ? "" : "not ", |
| 1310 | (msg[0] & 0x20) ? "target routine" : "lun", |
| 1311 | msg[0] & 0x7); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1312 | /* Normal One byte */ |
| 1313 | } else if (msg[0] < 0x1f) { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1314 | if (msg[0] < ARRAY_SIZE(one_byte_msgs) && one_byte_msgs[msg[0]]) |
Matthew Wilcox | e24d873 | 2006-02-07 08:05:26 -0700 | [diff] [blame] | 1315 | printk("%s ", one_byte_msgs[msg[0]]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1316 | else |
| 1317 | printk("reserved (%02x) ", msg[0]); |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1318 | } else if (msg[0] == 0x55) { |
| 1319 | printk("QAS Request "); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1320 | /* Two byte */ |
| 1321 | } else if (msg[0] <= 0x2f) { |
Matthew Wilcox | b32aaff | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1322 | if ((msg[0] - 0x20) < ARRAY_SIZE(two_byte_msgs)) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1323 | printk("%s %02x ", two_byte_msgs[msg[0] - 0x20], |
| 1324 | msg[1]); |
| 1325 | else |
| 1326 | printk("reserved two byte (%02x %02x) ", |
| 1327 | msg[0], msg[1]); |
| 1328 | len = 2; |
| 1329 | } else |
Matthew Wilcox | e24d873 | 2006-02-07 08:05:26 -0700 | [diff] [blame] | 1330 | printk("reserved "); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1331 | return len; |
| 1332 | } |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1333 | EXPORT_SYMBOL(spi_print_msg); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1334 | |
| 1335 | #else /* ifndef CONFIG_SCSI_CONSTANTS */ |
| 1336 | |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1337 | int spi_print_msg(const unsigned char *msg) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1338 | { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1339 | int len = 1, i; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1340 | |
| 1341 | if (msg[0] == EXTENDED_MESSAGE) { |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1342 | len = 2 + msg[1]; |
| 1343 | if (len == 2) |
| 1344 | len += 256; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1345 | for (i = 0; i < len; ++i) |
| 1346 | printk("%02x ", msg[i]); |
| 1347 | /* Identify */ |
| 1348 | } else if (msg[0] & 0x80) { |
| 1349 | printk("%02x ", msg[0]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1350 | /* Normal One byte */ |
James Bottomley | 597705a | 2006-03-12 09:54:19 -0600 | [diff] [blame] | 1351 | } else if ((msg[0] < 0x1f) || (msg[0] == 0x55)) { |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1352 | printk("%02x ", msg[0]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1353 | /* Two byte */ |
| 1354 | } else if (msg[0] <= 0x2f) { |
| 1355 | printk("%02x %02x", msg[0], msg[1]); |
| 1356 | len = 2; |
| 1357 | } else |
| 1358 | printk("%02x ", msg[0]); |
| 1359 | return len; |
| 1360 | } |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1361 | EXPORT_SYMBOL(spi_print_msg); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1362 | #endif /* ! CONFIG_SCSI_CONSTANTS */ |
| 1363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | static int spi_device_match(struct attribute_container *cont, |
| 1365 | struct device *dev) |
| 1366 | { |
| 1367 | struct scsi_device *sdev; |
| 1368 | struct Scsi_Host *shost; |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1369 | struct spi_internal *i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | if (!scsi_is_sdev_device(dev)) |
| 1372 | return 0; |
| 1373 | |
| 1374 | sdev = to_scsi_device(dev); |
| 1375 | shost = sdev->host; |
| 1376 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1377 | != &spi_host_class.class) |
| 1378 | return 0; |
| 1379 | /* Note: this class has no device attributes, so it has |
| 1380 | * no per-HBA allocation and thus we don't need to distinguish |
| 1381 | * the attribute containers for the device */ |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1382 | i = to_spi_internal(shost->transportt); |
| 1383 | if (i->f->deny_binding && i->f->deny_binding(sdev->sdev_target)) |
| 1384 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | return 1; |
| 1386 | } |
| 1387 | |
| 1388 | static int spi_target_match(struct attribute_container *cont, |
| 1389 | struct device *dev) |
| 1390 | { |
| 1391 | struct Scsi_Host *shost; |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1392 | struct scsi_target *starget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | struct spi_internal *i; |
| 1394 | |
| 1395 | if (!scsi_is_target_device(dev)) |
| 1396 | return 0; |
| 1397 | |
| 1398 | shost = dev_to_shost(dev->parent); |
| 1399 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1400 | != &spi_host_class.class) |
| 1401 | return 0; |
| 1402 | |
| 1403 | i = to_spi_internal(shost->transportt); |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1404 | starget = to_scsi_target(dev); |
| 1405 | |
| 1406 | if (i->f->deny_binding && i->f->deny_binding(starget)) |
| 1407 | return 0; |
| 1408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return &i->t.target_attrs.ac == cont; |
| 1410 | } |
| 1411 | |
| 1412 | static DECLARE_TRANSPORT_CLASS(spi_transport_class, |
| 1413 | "spi_transport", |
| 1414 | spi_setup_transport_attrs, |
| 1415 | NULL, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1416 | spi_target_configure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
| 1418 | static DECLARE_ANON_TRANSPORT_CLASS(spi_device_class, |
| 1419 | spi_device_match, |
| 1420 | spi_device_configure); |
| 1421 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1422 | static struct attribute *host_attributes[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1423 | &dev_attr_signalling.attr, |
Hannes Reinecke | 0ac2377 | 2011-06-30 02:19:57 +0530 | [diff] [blame] | 1424 | &dev_attr_host_width.attr, |
| 1425 | &dev_attr_hba_id.attr, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1426 | NULL |
| 1427 | }; |
| 1428 | |
| 1429 | static struct attribute_group host_attribute_group = { |
| 1430 | .attrs = host_attributes, |
| 1431 | }; |
| 1432 | |
| 1433 | static int spi_host_configure(struct transport_container *tc, |
| 1434 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1435 | struct device *cdev) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1436 | { |
| 1437 | struct kobject *kobj = &cdev->kobj; |
| 1438 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 1439 | struct spi_internal *si = to_spi_internal(shost->transportt); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1440 | struct attribute *attr = &dev_attr_signalling.attr; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1441 | int rc = 0; |
| 1442 | |
| 1443 | if (si->f->set_signalling) |
| 1444 | rc = sysfs_chmod_file(kobj, attr, attr->mode | S_IWUSR); |
| 1445 | |
| 1446 | return rc; |
| 1447 | } |
| 1448 | |
| 1449 | /* returns true if we should be showing the variable. Also |
| 1450 | * overloads the return by setting 1<<1 if the attribute should |
| 1451 | * be writeable */ |
| 1452 | #define TARGET_ATTRIBUTE_HELPER(name) \ |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1453 | (si->f->show_##name ? S_IRUGO : 0) | \ |
| 1454 | (si->f->set_##name ? S_IWUSR : 0) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1455 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 1456 | static umode_t target_attribute_is_visible(struct kobject *kobj, |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1457 | struct attribute *attr, int i) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1458 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1459 | struct device *cdev = container_of(kobj, struct device, kobj); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1460 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 1461 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 1462 | struct spi_internal *si = to_spi_internal(shost->transportt); |
| 1463 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1464 | if (attr == &dev_attr_period.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1465 | spi_support_sync(starget)) |
| 1466 | return TARGET_ATTRIBUTE_HELPER(period); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1467 | else if (attr == &dev_attr_min_period.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1468 | spi_support_sync(starget)) |
| 1469 | return TARGET_ATTRIBUTE_HELPER(period); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1470 | else if (attr == &dev_attr_offset.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1471 | spi_support_sync(starget)) |
| 1472 | return TARGET_ATTRIBUTE_HELPER(offset); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1473 | else if (attr == &dev_attr_max_offset.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1474 | spi_support_sync(starget)) |
| 1475 | return TARGET_ATTRIBUTE_HELPER(offset); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1476 | else if (attr == &dev_attr_width.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1477 | spi_support_wide(starget)) |
| 1478 | return TARGET_ATTRIBUTE_HELPER(width); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1479 | else if (attr == &dev_attr_max_width.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1480 | spi_support_wide(starget)) |
| 1481 | return TARGET_ATTRIBUTE_HELPER(width); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1482 | else if (attr == &dev_attr_iu.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1483 | spi_support_ius(starget)) |
| 1484 | return TARGET_ATTRIBUTE_HELPER(iu); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1485 | else if (attr == &dev_attr_max_iu.attr && |
| 1486 | spi_support_ius(starget)) |
| 1487 | return TARGET_ATTRIBUTE_HELPER(iu); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1488 | else if (attr == &dev_attr_dt.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1489 | spi_support_dt(starget)) |
| 1490 | return TARGET_ATTRIBUTE_HELPER(dt); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1491 | else if (attr == &dev_attr_qas.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1492 | spi_support_qas(starget)) |
| 1493 | return TARGET_ATTRIBUTE_HELPER(qas); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1494 | else if (attr == &dev_attr_max_qas.attr && |
| 1495 | spi_support_qas(starget)) |
| 1496 | return TARGET_ATTRIBUTE_HELPER(qas); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1497 | else if (attr == &dev_attr_wr_flow.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1498 | spi_support_ius(starget)) |
| 1499 | return TARGET_ATTRIBUTE_HELPER(wr_flow); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1500 | else if (attr == &dev_attr_rd_strm.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1501 | spi_support_ius(starget)) |
| 1502 | return TARGET_ATTRIBUTE_HELPER(rd_strm); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1503 | else if (attr == &dev_attr_rti.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1504 | spi_support_ius(starget)) |
| 1505 | return TARGET_ATTRIBUTE_HELPER(rti); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1506 | else if (attr == &dev_attr_pcomp_en.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1507 | spi_support_ius(starget)) |
| 1508 | return TARGET_ATTRIBUTE_HELPER(pcomp_en); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1509 | else if (attr == &dev_attr_hold_mcs.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1510 | spi_support_ius(starget)) |
| 1511 | return TARGET_ATTRIBUTE_HELPER(hold_mcs); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1512 | else if (attr == &dev_attr_revalidate.attr) |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1513 | return S_IWUSR; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1514 | |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static struct attribute *target_attributes[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1519 | &dev_attr_period.attr, |
| 1520 | &dev_attr_min_period.attr, |
| 1521 | &dev_attr_offset.attr, |
| 1522 | &dev_attr_max_offset.attr, |
| 1523 | &dev_attr_width.attr, |
| 1524 | &dev_attr_max_width.attr, |
| 1525 | &dev_attr_iu.attr, |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1526 | &dev_attr_max_iu.attr, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1527 | &dev_attr_dt.attr, |
| 1528 | &dev_attr_qas.attr, |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1529 | &dev_attr_max_qas.attr, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1530 | &dev_attr_wr_flow.attr, |
| 1531 | &dev_attr_rd_strm.attr, |
| 1532 | &dev_attr_rti.attr, |
| 1533 | &dev_attr_pcomp_en.attr, |
| 1534 | &dev_attr_hold_mcs.attr, |
| 1535 | &dev_attr_revalidate.attr, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1536 | NULL |
| 1537 | }; |
| 1538 | |
| 1539 | static struct attribute_group target_attribute_group = { |
| 1540 | .attrs = target_attributes, |
| 1541 | .is_visible = target_attribute_is_visible, |
| 1542 | }; |
| 1543 | |
| 1544 | static int spi_target_configure(struct transport_container *tc, |
| 1545 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1546 | struct device *cdev) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1547 | { |
| 1548 | struct kobject *kobj = &cdev->kobj; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1549 | |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1550 | /* force an update based on parameters read from the device */ |
| 1551 | sysfs_update_group(kobj, &target_attribute_group); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | struct scsi_transport_template * |
| 1557 | spi_attach_transport(struct spi_function_template *ft) |
| 1558 | { |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1559 | struct spi_internal *i = kzalloc(sizeof(struct spi_internal), |
| 1560 | GFP_KERNEL); |
| 1561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | if (unlikely(!i)) |
| 1563 | return NULL; |
| 1564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | i->t.target_attrs.ac.class = &spi_transport_class.class; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1566 | i->t.target_attrs.ac.grp = &target_attribute_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | i->t.target_attrs.ac.match = spi_target_match; |
| 1568 | transport_container_register(&i->t.target_attrs); |
| 1569 | i->t.target_size = sizeof(struct spi_transport_attrs); |
| 1570 | i->t.host_attrs.ac.class = &spi_host_class.class; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1571 | i->t.host_attrs.ac.grp = &host_attribute_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | i->t.host_attrs.ac.match = spi_host_match; |
| 1573 | transport_container_register(&i->t.host_attrs); |
| 1574 | i->t.host_size = sizeof(struct spi_host_attrs); |
| 1575 | i->f = ft; |
| 1576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | return &i->t; |
| 1578 | } |
| 1579 | EXPORT_SYMBOL(spi_attach_transport); |
| 1580 | |
| 1581 | void spi_release_transport(struct scsi_transport_template *t) |
| 1582 | { |
| 1583 | struct spi_internal *i = to_spi_internal(t); |
| 1584 | |
| 1585 | transport_container_unregister(&i->t.target_attrs); |
| 1586 | transport_container_unregister(&i->t.host_attrs); |
| 1587 | |
| 1588 | kfree(i); |
| 1589 | } |
| 1590 | EXPORT_SYMBOL(spi_release_transport); |
| 1591 | |
| 1592 | static __init int spi_transport_init(void) |
| 1593 | { |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 1594 | int error = scsi_dev_info_add_list(SCSI_DEVINFO_SPI, |
| 1595 | "SCSI Parallel Transport Class"); |
| 1596 | if (!error) { |
| 1597 | int i; |
| 1598 | |
| 1599 | for (i = 0; spi_static_device_list[i].vendor; i++) |
| 1600 | scsi_dev_info_list_add_keyed(1, /* compatible */ |
| 1601 | spi_static_device_list[i].vendor, |
| 1602 | spi_static_device_list[i].model, |
| 1603 | NULL, |
| 1604 | spi_static_device_list[i].flags, |
| 1605 | SCSI_DEVINFO_SPI); |
| 1606 | } |
| 1607 | |
| 1608 | error = transport_class_register(&spi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | if (error) |
| 1610 | return error; |
| 1611 | error = anon_transport_class_register(&spi_device_class); |
| 1612 | return transport_class_register(&spi_host_class); |
| 1613 | } |
| 1614 | |
| 1615 | static void __exit spi_transport_exit(void) |
| 1616 | { |
| 1617 | transport_class_unregister(&spi_transport_class); |
| 1618 | anon_transport_class_unregister(&spi_device_class); |
| 1619 | transport_class_unregister(&spi_host_class); |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 1620 | scsi_dev_info_remove_list(SCSI_DEVINFO_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | MODULE_AUTHOR("Martin Hicks"); |
| 1624 | MODULE_DESCRIPTION("SPI Transport Attributes"); |
| 1625 | MODULE_LICENSE("GPL"); |
| 1626 | |
| 1627 | module_init(spi_transport_init); |
| 1628 | module_exit(spi_transport_exit); |