sbp2.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  1. /*
  2. * sbp2.c - SBP-2 protocol driver for IEEE-1394
  3. *
  4. * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com)
  5. * jamesg@filanet.com (JSG)
  6. *
  7. * Copyright (C) 2003 Ben Collins <bcollins@debian.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. /*
  24. * Brief Description:
  25. *
  26. * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394
  27. * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level
  28. * driver. It also registers as a SCSI lower-level driver in order to accept
  29. * SCSI commands for transport using SBP-2.
  30. *
  31. * You may access any attached SBP-2 (usually storage devices) as regular
  32. * SCSI devices. E.g. mount /dev/sda1, fdisk, mkfs, etc..
  33. *
  34. * See http://www.t10.org/drafts.htm#sbp2 for the final draft of the SBP-2
  35. * specification and for where to purchase the official standard.
  36. *
  37. * TODO:
  38. * - look into possible improvements of the SCSI error handlers
  39. * - handle Unit_Characteristics.mgt_ORB_timeout and .ORB_size
  40. * - handle Logical_Unit_Number.ordered
  41. * - handle src == 1 in status blocks
  42. * - reimplement the DMA mapping in absence of physical DMA so that
  43. * bus_to_virt is no longer required
  44. * - debug the handling of absent physical DMA
  45. * - replace CONFIG_IEEE1394_SBP2_PHYS_DMA by automatic detection
  46. * (this is easy but depends on the previous two TODO items)
  47. * - make the parameter serialize_io configurable per device
  48. * - move all requests to fetch agent registers into non-atomic context,
  49. * replace all usages of sbp2util_node_write_no_wait by true transactions
  50. * Grep for inline FIXME comments below.
  51. */
  52. #include <linux/blkdev.h>
  53. #include <linux/compiler.h>
  54. #include <linux/delay.h>
  55. #include <linux/device.h>
  56. #include <linux/dma-mapping.h>
  57. #include <linux/gfp.h>
  58. #include <linux/init.h>
  59. #include <linux/kernel.h>
  60. #include <linux/list.h>
  61. #include <linux/mm.h>
  62. #include <linux/module.h>
  63. #include <linux/moduleparam.h>
  64. #include <linux/sched.h>
  65. #include <linux/slab.h>
  66. #include <linux/spinlock.h>
  67. #include <linux/stat.h>
  68. #include <linux/string.h>
  69. #include <linux/stringify.h>
  70. #include <linux/types.h>
  71. #include <linux/wait.h>
  72. #include <linux/workqueue.h>
  73. #include <linux/scatterlist.h>
  74. #include <asm/byteorder.h>
  75. #include <asm/errno.h>
  76. #include <asm/param.h>
  77. #include <asm/system.h>
  78. #include <asm/types.h>
  79. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  80. #include <asm/io.h> /* for bus_to_virt */
  81. #endif
  82. #include <scsi/scsi.h>
  83. #include <scsi/scsi_cmnd.h>
  84. #include <scsi/scsi_dbg.h>
  85. #include <scsi/scsi_device.h>
  86. #include <scsi/scsi_host.h>
  87. #include "csr1212.h"
  88. #include "highlevel.h"
  89. #include "hosts.h"
  90. #include "ieee1394.h"
  91. #include "ieee1394_core.h"
  92. #include "ieee1394_hotplug.h"
  93. #include "ieee1394_transactions.h"
  94. #include "ieee1394_types.h"
  95. #include "nodemgr.h"
  96. #include "sbp2.h"
  97. /*
  98. * Module load parameter definitions
  99. */
  100. /*
  101. * Change max_speed on module load if you have a bad IEEE-1394
  102. * controller that has trouble running 2KB packets at 400mb.
  103. *
  104. * NOTE: On certain OHCI parts I have seen short packets on async transmit
  105. * (probably due to PCI latency/throughput issues with the part). You can
  106. * bump down the speed if you are running into problems.
  107. */
  108. static int sbp2_max_speed = IEEE1394_SPEED_MAX;
  109. module_param_named(max_speed, sbp2_max_speed, int, 0644);
  110. MODULE_PARM_DESC(max_speed, "Limit data transfer speed (5 <= 3200, "
  111. "4 <= 1600, 3 <= 800, 2 <= 400, 1 <= 200, 0 = 100 Mb/s)");
  112. /*
  113. * Set serialize_io to 0 or N to use dynamically appended lists of command ORBs.
  114. * This is and always has been buggy in multiple subtle ways. See above TODOs.
  115. */
  116. static int sbp2_serialize_io = 1;
  117. module_param_named(serialize_io, sbp2_serialize_io, bool, 0444);
  118. MODULE_PARM_DESC(serialize_io, "Serialize requests coming from SCSI drivers "
  119. "(default = Y, faster but buggy = N)");
  120. /*
  121. * Adjust max_sectors if you'd like to influence how many sectors each SCSI
  122. * command can transfer at most. Please note that some older SBP-2 bridge
  123. * chips are broken for transfers greater or equal to 128KB, therefore
  124. * max_sectors used to be a safe 255 sectors for many years. We now have a
  125. * default of 0 here which means that we let the SCSI stack choose a limit.
  126. *
  127. * The SBP2_WORKAROUND_128K_MAX_TRANS flag, if set either in the workarounds
  128. * module parameter or in the sbp2_workarounds_table[], will override the
  129. * value of max_sectors. We should use sbp2_workarounds_table[] to cover any
  130. * bridge chip which becomes known to need the 255 sectors limit.
  131. */
  132. static int sbp2_max_sectors;
  133. module_param_named(max_sectors, sbp2_max_sectors, int, 0444);
  134. MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported "
  135. "(default = 0 = use SCSI stack's default)");
  136. /*
  137. * Exclusive login to sbp2 device? In most cases, the sbp2 driver should
  138. * do an exclusive login, as it's generally unsafe to have two hosts
  139. * talking to a single sbp2 device at the same time (filesystem coherency,
  140. * etc.). If you're running an sbp2 device that supports multiple logins,
  141. * and you're either running read-only filesystems or some sort of special
  142. * filesystem supporting multiple hosts, e.g. OpenGFS, Oracle Cluster
  143. * File System, or Lustre, then set exclusive_login to zero.
  144. *
  145. * So far only bridges from Oxford Semiconductor are known to support
  146. * concurrent logins. Depending on firmware, four or two concurrent logins
  147. * are possible on OXFW911 and newer Oxsemi bridges.
  148. */
  149. static int sbp2_exclusive_login = 1;
  150. module_param_named(exclusive_login, sbp2_exclusive_login, bool, 0644);
  151. MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
  152. "(default = Y, use N for concurrent initiators)");
  153. /*
  154. * If any of the following workarounds is required for your device to work,
  155. * please submit the kernel messages logged by sbp2 to the linux1394-devel
  156. * mailing list.
  157. *
  158. * - 128kB max transfer
  159. * Limit transfer size. Necessary for some old bridges.
  160. *
  161. * - 36 byte inquiry
  162. * When scsi_mod probes the device, let the inquiry command look like that
  163. * from MS Windows.
  164. *
  165. * - skip mode page 8
  166. * Suppress sending of mode_sense for mode page 8 if the device pretends to
  167. * support the SCSI Primary Block commands instead of Reduced Block Commands.
  168. *
  169. * - fix capacity
  170. * Tell sd_mod to correct the last sector number reported by read_capacity.
  171. * Avoids access beyond actual disk limits on devices with an off-by-one bug.
  172. * Don't use this with devices which don't have this bug.
  173. *
  174. * - delay inquiry
  175. * Wait extra SBP2_INQUIRY_DELAY seconds after login before SCSI inquiry.
  176. *
  177. * - power condition
  178. * Set the power condition field in the START STOP UNIT commands sent by
  179. * sd_mod on suspend, resume, and shutdown (if manage_start_stop is on).
  180. * Some disks need this to spin down or to resume properly.
  181. *
  182. * - override internal blacklist
  183. * Instead of adding to the built-in blacklist, use only the workarounds
  184. * specified in the module load parameter.
  185. * Useful if a blacklist entry interfered with a non-broken device.
  186. */
  187. static int sbp2_default_workarounds;
  188. module_param_named(workarounds, sbp2_default_workarounds, int, 0644);
  189. MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
  190. ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS)
  191. ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36)
  192. ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8)
  193. ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY)
  194. ", delay inquiry = " __stringify(SBP2_WORKAROUND_DELAY_INQUIRY)
  195. ", set power condition in start stop unit = "
  196. __stringify(SBP2_WORKAROUND_POWER_CONDITION)
  197. ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
  198. ", or a combination)");
  199. /*
  200. * This influences the format of the sysfs attribute
  201. * /sys/bus/scsi/devices/.../ieee1394_id.
  202. *
  203. * The default format is like in older kernels: %016Lx:%d:%d
  204. * It contains the target's EUI-64, a number given to the logical unit by
  205. * the ieee1394 driver's nodemgr (starting at 0), and the LUN.
  206. *
  207. * The long format is: %016Lx:%06x:%04x
  208. * It contains the target's EUI-64, the unit directory's directory_ID as per
  209. * IEEE 1212 clause 7.7.19, and the LUN. This format comes closest to the
  210. * format of SBP(-3) target port and logical unit identifier as per SAM (SCSI
  211. * Architecture Model) rev.2 to 4 annex A. Therefore and because it is
  212. * independent of the implementation of the ieee1394 nodemgr, the longer format
  213. * is recommended for future use.
  214. */
  215. static int sbp2_long_sysfs_ieee1394_id;
  216. module_param_named(long_ieee1394_id, sbp2_long_sysfs_ieee1394_id, bool, 0644);
  217. MODULE_PARM_DESC(long_ieee1394_id, "8+3+2 bytes format of ieee1394_id in sysfs "
  218. "(default = backwards-compatible = N, SAM-conforming = Y)");
  219. #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)
  220. #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
  221. /*
  222. * Globals
  223. */
  224. static void sbp2scsi_complete_all_commands(struct sbp2_lu *, u32);
  225. static void sbp2scsi_complete_command(struct sbp2_lu *, u32, struct scsi_cmnd *,
  226. void (*)(struct scsi_cmnd *));
  227. static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *);
  228. static int sbp2_start_device(struct sbp2_lu *);
  229. static void sbp2_remove_device(struct sbp2_lu *);
  230. static int sbp2_login_device(struct sbp2_lu *);
  231. static int sbp2_reconnect_device(struct sbp2_lu *);
  232. static int sbp2_logout_device(struct sbp2_lu *);
  233. static void sbp2_host_reset(struct hpsb_host *);
  234. static int sbp2_handle_status_write(struct hpsb_host *, int, int, quadlet_t *,
  235. u64, size_t, u16);
  236. static int sbp2_agent_reset(struct sbp2_lu *, int);
  237. static void sbp2_parse_unit_directory(struct sbp2_lu *,
  238. struct unit_directory *);
  239. static int sbp2_set_busy_timeout(struct sbp2_lu *);
  240. static int sbp2_max_speed_and_size(struct sbp2_lu *);
  241. static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xa, 0xa, 0xa };
  242. static DEFINE_RWLOCK(sbp2_hi_logical_units_lock);
  243. static struct hpsb_highlevel sbp2_highlevel = {
  244. .name = SBP2_DEVICE_NAME,
  245. .host_reset = sbp2_host_reset,
  246. };
  247. static const struct hpsb_address_ops sbp2_ops = {
  248. .write = sbp2_handle_status_write
  249. };
  250. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  251. static int sbp2_handle_physdma_write(struct hpsb_host *, int, int, quadlet_t *,
  252. u64, size_t, u16);
  253. static int sbp2_handle_physdma_read(struct hpsb_host *, int, quadlet_t *, u64,
  254. size_t, u16);
  255. static const struct hpsb_address_ops sbp2_physdma_ops = {
  256. .read = sbp2_handle_physdma_read,
  257. .write = sbp2_handle_physdma_write,
  258. };
  259. #endif
  260. /*
  261. * Interface to driver core and IEEE 1394 core
  262. */
  263. static const struct ieee1394_device_id sbp2_id_table[] = {
  264. {
  265. .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
  266. .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
  267. .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
  268. {}
  269. };
  270. MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
  271. static int sbp2_probe(struct device *);
  272. static int sbp2_remove(struct device *);
  273. static int sbp2_update(struct unit_directory *);
  274. static struct hpsb_protocol_driver sbp2_driver = {
  275. .name = SBP2_DEVICE_NAME,
  276. .id_table = sbp2_id_table,
  277. .update = sbp2_update,
  278. .driver = {
  279. .probe = sbp2_probe,
  280. .remove = sbp2_remove,
  281. },
  282. };
  283. /*
  284. * Interface to SCSI core
  285. */
  286. static int sbp2scsi_queuecommand(struct scsi_cmnd *,
  287. void (*)(struct scsi_cmnd *));
  288. static int sbp2scsi_abort(struct scsi_cmnd *);
  289. static int sbp2scsi_reset(struct scsi_cmnd *);
  290. static int sbp2scsi_slave_alloc(struct scsi_device *);
  291. static int sbp2scsi_slave_configure(struct scsi_device *);
  292. static void sbp2scsi_slave_destroy(struct scsi_device *);
  293. static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *,
  294. struct device_attribute *, char *);
  295. static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
  296. static struct device_attribute *sbp2_sysfs_sdev_attrs[] = {
  297. &dev_attr_ieee1394_id,
  298. NULL
  299. };
  300. static struct scsi_host_template sbp2_shost_template = {
  301. .module = THIS_MODULE,
  302. .name = "SBP-2 IEEE-1394",
  303. .proc_name = SBP2_DEVICE_NAME,
  304. .queuecommand = sbp2scsi_queuecommand,
  305. .eh_abort_handler = sbp2scsi_abort,
  306. .eh_device_reset_handler = sbp2scsi_reset,
  307. .slave_alloc = sbp2scsi_slave_alloc,
  308. .slave_configure = sbp2scsi_slave_configure,
  309. .slave_destroy = sbp2scsi_slave_destroy,
  310. .this_id = -1,
  311. .sg_tablesize = SG_ALL,
  312. .use_clustering = ENABLE_CLUSTERING,
  313. .cmd_per_lun = SBP2_MAX_CMDS,
  314. .can_queue = SBP2_MAX_CMDS,
  315. .sdev_attrs = sbp2_sysfs_sdev_attrs,
  316. };
  317. #define SBP2_ROM_VALUE_WILDCARD ~0 /* match all */
  318. #define SBP2_ROM_VALUE_MISSING 0xff000000 /* not present in the unit dir. */
  319. /*
  320. * List of devices with known bugs.
  321. *
  322. * The firmware_revision field, masked with 0xffff00, is the best indicator
  323. * for the type of bridge chip of a device. It yields a few false positives
  324. * but this did not break correctly behaving devices so far.
  325. */
  326. static const struct {
  327. u32 firmware_revision;
  328. u32 model;
  329. unsigned workarounds;
  330. } sbp2_workarounds_table[] = {
  331. /* DViCO Momobay CX-1 with TSB42AA9 bridge */ {
  332. .firmware_revision = 0x002800,
  333. .model = 0x001010,
  334. .workarounds = SBP2_WORKAROUND_INQUIRY_36 |
  335. SBP2_WORKAROUND_MODE_SENSE_8 |
  336. SBP2_WORKAROUND_POWER_CONDITION,
  337. },
  338. /* DViCO Momobay FX-3A with TSB42AA9A bridge */ {
  339. .firmware_revision = 0x002800,
  340. .model = 0x000000,
  341. .workarounds = SBP2_WORKAROUND_DELAY_INQUIRY |
  342. SBP2_WORKAROUND_POWER_CONDITION,
  343. },
  344. /* Initio bridges, actually only needed for some older ones */ {
  345. .firmware_revision = 0x000200,
  346. .model = SBP2_ROM_VALUE_WILDCARD,
  347. .workarounds = SBP2_WORKAROUND_INQUIRY_36,
  348. },
  349. /* PL-3507 bridge with Prolific firmware */ {
  350. .firmware_revision = 0x012800,
  351. .model = SBP2_ROM_VALUE_WILDCARD,
  352. .workarounds = SBP2_WORKAROUND_POWER_CONDITION,
  353. },
  354. /* Symbios bridge */ {
  355. .firmware_revision = 0xa0b800,
  356. .model = SBP2_ROM_VALUE_WILDCARD,
  357. .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS,
  358. },
  359. /* Datafab MD2-FW2 with Symbios/LSILogic SYM13FW500 bridge */ {
  360. .firmware_revision = 0x002600,
  361. .model = SBP2_ROM_VALUE_WILDCARD,
  362. .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS,
  363. },
  364. /*
  365. * iPod 2nd generation: needs 128k max transfer size workaround
  366. * iPod 3rd generation: needs fix capacity workaround
  367. */
  368. {
  369. .firmware_revision = 0x0a2700,
  370. .model = 0x000000,
  371. .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS |
  372. SBP2_WORKAROUND_FIX_CAPACITY,
  373. },
  374. /* iPod 4th generation */ {
  375. .firmware_revision = 0x0a2700,
  376. .model = 0x000021,
  377. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  378. },
  379. /* iPod mini */ {
  380. .firmware_revision = 0x0a2700,
  381. .model = 0x000022,
  382. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  383. },
  384. /* iPod mini */ {
  385. .firmware_revision = 0x0a2700,
  386. .model = 0x000023,
  387. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  388. },
  389. /* iPod Photo */ {
  390. .firmware_revision = 0x0a2700,
  391. .model = 0x00007e,
  392. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  393. }
  394. };
  395. /**************************************
  396. * General utility functions
  397. **************************************/
  398. #ifndef __BIG_ENDIAN
  399. /*
  400. * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
  401. */
  402. static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
  403. {
  404. u32 *temp = buffer;
  405. for (length = (length >> 2); length--; )
  406. temp[length] = be32_to_cpu(temp[length]);
  407. }
  408. /*
  409. * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
  410. */
  411. static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
  412. {
  413. u32 *temp = buffer;
  414. for (length = (length >> 2); length--; )
  415. temp[length] = cpu_to_be32(temp[length]);
  416. }
  417. #else /* BIG_ENDIAN */
  418. /* Why waste the cpu cycles? */
  419. #define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0)
  420. #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0)
  421. #endif
  422. static DECLARE_WAIT_QUEUE_HEAD(sbp2_access_wq);
  423. /*
  424. * Waits for completion of an SBP-2 access request.
  425. * Returns nonzero if timed out or prematurely interrupted.
  426. */
  427. static int sbp2util_access_timeout(struct sbp2_lu *lu, int timeout)
  428. {
  429. long leftover;
  430. leftover = wait_event_interruptible_timeout(
  431. sbp2_access_wq, lu->access_complete, timeout);
  432. lu->access_complete = 0;
  433. return leftover <= 0;
  434. }
  435. static void sbp2_free_packet(void *packet)
  436. {
  437. hpsb_free_tlabel(packet);
  438. hpsb_free_packet(packet);
  439. }
  440. /*
  441. * This is much like hpsb_node_write(), except it ignores the response
  442. * subaction and returns immediately. Can be used from atomic context.
  443. */
  444. static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
  445. quadlet_t *buf, size_t len)
  446. {
  447. struct hpsb_packet *packet;
  448. packet = hpsb_make_writepacket(ne->host, ne->nodeid, addr, buf, len);
  449. if (!packet)
  450. return -ENOMEM;
  451. hpsb_set_packet_complete_task(packet, sbp2_free_packet, packet);
  452. hpsb_node_fill_packet(ne, packet);
  453. if (hpsb_send_packet(packet) < 0) {
  454. sbp2_free_packet(packet);
  455. return -EIO;
  456. }
  457. return 0;
  458. }
  459. static void sbp2util_notify_fetch_agent(struct sbp2_lu *lu, u64 offset,
  460. quadlet_t *data, size_t len)
  461. {
  462. /* There is a small window after a bus reset within which the node
  463. * entry's generation is current but the reconnect wasn't completed. */
  464. if (unlikely(atomic_read(&lu->state) == SBP2LU_STATE_IN_RESET))
  465. return;
  466. if (hpsb_node_write(lu->ne, lu->command_block_agent_addr + offset,
  467. data, len))
  468. SBP2_ERR("sbp2util_notify_fetch_agent failed.");
  469. /* Now accept new SCSI commands, unless a bus reset happended during
  470. * hpsb_node_write. */
  471. if (likely(atomic_read(&lu->state) != SBP2LU_STATE_IN_RESET))
  472. scsi_unblock_requests(lu->shost);
  473. }
  474. static void sbp2util_write_orb_pointer(struct work_struct *work)
  475. {
  476. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  477. quadlet_t data[2];
  478. data[0] = ORB_SET_NODE_ID(lu->hi->host->node_id);
  479. data[1] = lu->last_orb_dma;
  480. sbp2util_cpu_to_be32_buffer(data, 8);
  481. sbp2util_notify_fetch_agent(lu, SBP2_ORB_POINTER_OFFSET, data, 8);
  482. }
  483. static void sbp2util_write_doorbell(struct work_struct *work)
  484. {
  485. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  486. sbp2util_notify_fetch_agent(lu, SBP2_DOORBELL_OFFSET, NULL, 4);
  487. }
  488. static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
  489. {
  490. struct sbp2_command_info *cmd;
  491. struct device *dmadev = lu->hi->host->device.parent;
  492. int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
  493. for (i = 0; i < orbs; i++) {
  494. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  495. if (!cmd)
  496. goto failed_alloc;
  497. cmd->command_orb_dma =
  498. dma_map_single(dmadev, &cmd->command_orb,
  499. sizeof(struct sbp2_command_orb),
  500. DMA_TO_DEVICE);
  501. if (dma_mapping_error(dmadev, cmd->command_orb_dma))
  502. goto failed_orb;
  503. cmd->sge_dma =
  504. dma_map_single(dmadev, &cmd->scatter_gather_element,
  505. sizeof(cmd->scatter_gather_element),
  506. DMA_TO_DEVICE);
  507. if (dma_mapping_error(dmadev, cmd->sge_dma))
  508. goto failed_sge;
  509. INIT_LIST_HEAD(&cmd->list);
  510. list_add_tail(&cmd->list, &lu->cmd_orb_completed);
  511. }
  512. return 0;
  513. failed_sge:
  514. dma_unmap_single(dmadev, cmd->command_orb_dma,
  515. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  516. failed_orb:
  517. kfree(cmd);
  518. failed_alloc:
  519. return -ENOMEM;
  520. }
  521. static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu,
  522. struct hpsb_host *host)
  523. {
  524. struct list_head *lh, *next;
  525. struct sbp2_command_info *cmd;
  526. unsigned long flags;
  527. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  528. if (!list_empty(&lu->cmd_orb_completed))
  529. list_for_each_safe(lh, next, &lu->cmd_orb_completed) {
  530. cmd = list_entry(lh, struct sbp2_command_info, list);
  531. dma_unmap_single(host->device.parent,
  532. cmd->command_orb_dma,
  533. sizeof(struct sbp2_command_orb),
  534. DMA_TO_DEVICE);
  535. dma_unmap_single(host->device.parent, cmd->sge_dma,
  536. sizeof(cmd->scatter_gather_element),
  537. DMA_TO_DEVICE);
  538. kfree(cmd);
  539. }
  540. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  541. return;
  542. }
  543. /*
  544. * Finds the sbp2_command for a given outstanding command ORB.
  545. * Only looks at the in-use list.
  546. */
  547. static struct sbp2_command_info *sbp2util_find_command_for_orb(
  548. struct sbp2_lu *lu, dma_addr_t orb)
  549. {
  550. struct sbp2_command_info *cmd;
  551. unsigned long flags;
  552. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  553. if (!list_empty(&lu->cmd_orb_inuse))
  554. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  555. if (cmd->command_orb_dma == orb) {
  556. spin_unlock_irqrestore(
  557. &lu->cmd_orb_lock, flags);
  558. return cmd;
  559. }
  560. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  561. return NULL;
  562. }
  563. /*
  564. * Finds the sbp2_command for a given outstanding SCpnt.
  565. * Only looks at the in-use list.
  566. * Must be called with lu->cmd_orb_lock held.
  567. */
  568. static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
  569. struct sbp2_lu *lu, void *SCpnt)
  570. {
  571. struct sbp2_command_info *cmd;
  572. if (!list_empty(&lu->cmd_orb_inuse))
  573. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  574. if (cmd->Current_SCpnt == SCpnt)
  575. return cmd;
  576. return NULL;
  577. }
  578. static struct sbp2_command_info *sbp2util_allocate_command_orb(
  579. struct sbp2_lu *lu,
  580. struct scsi_cmnd *Current_SCpnt,
  581. void (*Current_done)(struct scsi_cmnd *))
  582. {
  583. struct list_head *lh;
  584. struct sbp2_command_info *cmd = NULL;
  585. unsigned long flags;
  586. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  587. if (!list_empty(&lu->cmd_orb_completed)) {
  588. lh = lu->cmd_orb_completed.next;
  589. list_del(lh);
  590. cmd = list_entry(lh, struct sbp2_command_info, list);
  591. cmd->Current_done = Current_done;
  592. cmd->Current_SCpnt = Current_SCpnt;
  593. list_add_tail(&cmd->list, &lu->cmd_orb_inuse);
  594. } else
  595. SBP2_ERR("%s: no orbs available", __func__);
  596. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  597. return cmd;
  598. }
  599. /*
  600. * Unmaps the DMAs of a command and moves the command to the completed ORB list.
  601. * Must be called with lu->cmd_orb_lock held.
  602. */
  603. static void sbp2util_mark_command_completed(struct sbp2_lu *lu,
  604. struct sbp2_command_info *cmd)
  605. {
  606. if (scsi_sg_count(cmd->Current_SCpnt))
  607. dma_unmap_sg(lu->ud->ne->host->device.parent,
  608. scsi_sglist(cmd->Current_SCpnt),
  609. scsi_sg_count(cmd->Current_SCpnt),
  610. cmd->Current_SCpnt->sc_data_direction);
  611. list_move_tail(&cmd->list, &lu->cmd_orb_completed);
  612. }
  613. /*
  614. * Is lu valid? Is the 1394 node still present?
  615. */
  616. static inline int sbp2util_node_is_available(struct sbp2_lu *lu)
  617. {
  618. return lu && lu->ne && !lu->ne->in_limbo;
  619. }
  620. /*********************************************
  621. * IEEE-1394 core driver stack related section
  622. *********************************************/
  623. static int sbp2_probe(struct device *dev)
  624. {
  625. struct unit_directory *ud;
  626. struct sbp2_lu *lu;
  627. ud = container_of(dev, struct unit_directory, device);
  628. /* Don't probe UD's that have the LUN flag. We'll probe the LUN(s)
  629. * instead. */
  630. if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY)
  631. return -ENODEV;
  632. lu = sbp2_alloc_device(ud);
  633. if (!lu)
  634. return -ENOMEM;
  635. sbp2_parse_unit_directory(lu, ud);
  636. return sbp2_start_device(lu);
  637. }
  638. static int sbp2_remove(struct device *dev)
  639. {
  640. struct unit_directory *ud;
  641. struct sbp2_lu *lu;
  642. struct scsi_device *sdev;
  643. ud = container_of(dev, struct unit_directory, device);
  644. lu = ud->device.driver_data;
  645. if (!lu)
  646. return 0;
  647. if (lu->shost) {
  648. /* Get rid of enqueued commands if there is no chance to
  649. * send them. */
  650. if (!sbp2util_node_is_available(lu))
  651. sbp2scsi_complete_all_commands(lu, DID_NO_CONNECT);
  652. /* scsi_remove_device() may trigger shutdown functions of SCSI
  653. * highlevel drivers which would deadlock if blocked. */
  654. atomic_set(&lu->state, SBP2LU_STATE_IN_SHUTDOWN);
  655. scsi_unblock_requests(lu->shost);
  656. }
  657. sdev = lu->sdev;
  658. if (sdev) {
  659. lu->sdev = NULL;
  660. scsi_remove_device(sdev);
  661. }
  662. sbp2_logout_device(lu);
  663. sbp2_remove_device(lu);
  664. return 0;
  665. }
  666. static int sbp2_update(struct unit_directory *ud)
  667. {
  668. struct sbp2_lu *lu = ud->device.driver_data;
  669. if (sbp2_reconnect_device(lu) != 0) {
  670. /*
  671. * Reconnect failed. If another bus reset happened,
  672. * let nodemgr proceed and call sbp2_update again later
  673. * (or sbp2_remove if this node went away).
  674. */
  675. if (!hpsb_node_entry_valid(lu->ne))
  676. return 0;
  677. /*
  678. * Or the target rejected the reconnect because we weren't
  679. * fast enough. Try a regular login, but first log out
  680. * just in case of any weirdness.
  681. */
  682. sbp2_logout_device(lu);
  683. if (sbp2_login_device(lu) != 0) {
  684. if (!hpsb_node_entry_valid(lu->ne))
  685. return 0;
  686. /* Maybe another initiator won the login. */
  687. SBP2_ERR("Failed to reconnect to sbp2 device!");
  688. return -EBUSY;
  689. }
  690. }
  691. sbp2_set_busy_timeout(lu);
  692. sbp2_agent_reset(lu, 1);
  693. sbp2_max_speed_and_size(lu);
  694. /* Complete any pending commands with busy (so they get retried)
  695. * and remove them from our queue. */
  696. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  697. /* Accept new commands unless there was another bus reset in the
  698. * meantime. */
  699. if (hpsb_node_entry_valid(lu->ne)) {
  700. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  701. scsi_unblock_requests(lu->shost);
  702. }
  703. return 0;
  704. }
  705. static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
  706. {
  707. struct sbp2_fwhost_info *hi;
  708. struct Scsi_Host *shost = NULL;
  709. struct sbp2_lu *lu = NULL;
  710. unsigned long flags;
  711. lu = kzalloc(sizeof(*lu), GFP_KERNEL);
  712. if (!lu) {
  713. SBP2_ERR("failed to create lu");
  714. goto failed_alloc;
  715. }
  716. lu->ne = ud->ne;
  717. lu->ud = ud;
  718. lu->speed_code = IEEE1394_SPEED_100;
  719. lu->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
  720. lu->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE;
  721. INIT_LIST_HEAD(&lu->cmd_orb_inuse);
  722. INIT_LIST_HEAD(&lu->cmd_orb_completed);
  723. INIT_LIST_HEAD(&lu->lu_list);
  724. spin_lock_init(&lu->cmd_orb_lock);
  725. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  726. INIT_WORK(&lu->protocol_work, NULL);
  727. ud->device.driver_data = lu;
  728. hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host);
  729. if (!hi) {
  730. hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host,
  731. sizeof(*hi));
  732. if (!hi) {
  733. SBP2_ERR("failed to allocate hostinfo");
  734. goto failed_alloc;
  735. }
  736. hi->host = ud->ne->host;
  737. INIT_LIST_HEAD(&hi->logical_units);
  738. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  739. /* Handle data movement if physical dma is not
  740. * enabled or not supported on host controller */
  741. if (!hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host,
  742. &sbp2_physdma_ops,
  743. 0x0ULL, 0xfffffffcULL)) {
  744. SBP2_ERR("failed to register lower 4GB address range");
  745. goto failed_alloc;
  746. }
  747. #endif
  748. }
  749. if (dma_get_max_seg_size(hi->host->device.parent) > SBP2_MAX_SEG_SIZE)
  750. BUG_ON(dma_set_max_seg_size(hi->host->device.parent,
  751. SBP2_MAX_SEG_SIZE));
  752. /* Prevent unloading of the 1394 host */
  753. if (!try_module_get(hi->host->driver->owner)) {
  754. SBP2_ERR("failed to get a reference on 1394 host driver");
  755. goto failed_alloc;
  756. }
  757. lu->hi = hi;
  758. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  759. list_add_tail(&lu->lu_list, &hi->logical_units);
  760. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  761. /* Register the status FIFO address range. We could use the same FIFO
  762. * for targets at different nodes. However we need different FIFOs per
  763. * target in order to support multi-unit devices.
  764. * The FIFO is located out of the local host controller's physical range
  765. * but, if possible, within the posted write area. Status writes will
  766. * then be performed as unified transactions. This slightly reduces
  767. * bandwidth usage, and some Prolific based devices seem to require it.
  768. */
  769. lu->status_fifo_addr = hpsb_allocate_and_register_addrspace(
  770. &sbp2_highlevel, ud->ne->host, &sbp2_ops,
  771. sizeof(struct sbp2_status_block), sizeof(quadlet_t),
  772. ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END);
  773. if (lu->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
  774. SBP2_ERR("failed to allocate status FIFO address range");
  775. goto failed_alloc;
  776. }
  777. shost = scsi_host_alloc(&sbp2_shost_template, sizeof(unsigned long));
  778. if (!shost) {
  779. SBP2_ERR("failed to register scsi host");
  780. goto failed_alloc;
  781. }
  782. shost->hostdata[0] = (unsigned long)lu;
  783. if (!scsi_add_host(shost, &ud->device)) {
  784. lu->shost = shost;
  785. return lu;
  786. }
  787. SBP2_ERR("failed to add scsi host");
  788. scsi_host_put(shost);
  789. failed_alloc:
  790. sbp2_remove_device(lu);
  791. return NULL;
  792. }
  793. static void sbp2_host_reset(struct hpsb_host *host)
  794. {
  795. struct sbp2_fwhost_info *hi;
  796. struct sbp2_lu *lu;
  797. unsigned long flags;
  798. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  799. if (!hi)
  800. return;
  801. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  802. list_for_each_entry(lu, &hi->logical_units, lu_list)
  803. if (atomic_cmpxchg(&lu->state,
  804. SBP2LU_STATE_RUNNING, SBP2LU_STATE_IN_RESET)
  805. == SBP2LU_STATE_RUNNING)
  806. scsi_block_requests(lu->shost);
  807. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  808. }
  809. static int sbp2_start_device(struct sbp2_lu *lu)
  810. {
  811. struct sbp2_fwhost_info *hi = lu->hi;
  812. int error;
  813. lu->login_response = dma_alloc_coherent(hi->host->device.parent,
  814. sizeof(struct sbp2_login_response),
  815. &lu->login_response_dma, GFP_KERNEL);
  816. if (!lu->login_response)
  817. goto alloc_fail;
  818. lu->query_logins_orb = dma_alloc_coherent(hi->host->device.parent,
  819. sizeof(struct sbp2_query_logins_orb),
  820. &lu->query_logins_orb_dma, GFP_KERNEL);
  821. if (!lu->query_logins_orb)
  822. goto alloc_fail;
  823. lu->query_logins_response = dma_alloc_coherent(hi->host->device.parent,
  824. sizeof(struct sbp2_query_logins_response),
  825. &lu->query_logins_response_dma, GFP_KERNEL);
  826. if (!lu->query_logins_response)
  827. goto alloc_fail;
  828. lu->reconnect_orb = dma_alloc_coherent(hi->host->device.parent,
  829. sizeof(struct sbp2_reconnect_orb),
  830. &lu->reconnect_orb_dma, GFP_KERNEL);
  831. if (!lu->reconnect_orb)
  832. goto alloc_fail;
  833. lu->logout_orb = dma_alloc_coherent(hi->host->device.parent,
  834. sizeof(struct sbp2_logout_orb),
  835. &lu->logout_orb_dma, GFP_KERNEL);
  836. if (!lu->logout_orb)
  837. goto alloc_fail;
  838. lu->login_orb = dma_alloc_coherent(hi->host->device.parent,
  839. sizeof(struct sbp2_login_orb),
  840. &lu->login_orb_dma, GFP_KERNEL);
  841. if (!lu->login_orb)
  842. goto alloc_fail;
  843. if (sbp2util_create_command_orb_pool(lu))
  844. goto alloc_fail;
  845. /* Wait a second before trying to log in. Previously logged in
  846. * initiators need a chance to reconnect. */
  847. if (msleep_interruptible(1000)) {
  848. sbp2_remove_device(lu);
  849. return -EINTR;
  850. }
  851. if (sbp2_login_device(lu)) {
  852. sbp2_remove_device(lu);
  853. return -EBUSY;
  854. }
  855. sbp2_set_busy_timeout(lu);
  856. sbp2_agent_reset(lu, 1);
  857. sbp2_max_speed_and_size(lu);
  858. if (lu->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
  859. ssleep(SBP2_INQUIRY_DELAY);
  860. error = scsi_add_device(lu->shost, 0, lu->ud->id, 0);
  861. if (error) {
  862. SBP2_ERR("scsi_add_device failed");
  863. sbp2_logout_device(lu);
  864. sbp2_remove_device(lu);
  865. return error;
  866. }
  867. return 0;
  868. alloc_fail:
  869. SBP2_ERR("Could not allocate memory for lu");
  870. sbp2_remove_device(lu);
  871. return -ENOMEM;
  872. }
  873. static void sbp2_remove_device(struct sbp2_lu *lu)
  874. {
  875. struct sbp2_fwhost_info *hi;
  876. unsigned long flags;
  877. if (!lu)
  878. return;
  879. hi = lu->hi;
  880. if (!hi)
  881. goto no_hi;
  882. if (lu->shost) {
  883. scsi_remove_host(lu->shost);
  884. scsi_host_put(lu->shost);
  885. }
  886. flush_scheduled_work();
  887. sbp2util_remove_command_orb_pool(lu, hi->host);
  888. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  889. list_del(&lu->lu_list);
  890. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  891. if (lu->login_response)
  892. dma_free_coherent(hi->host->device.parent,
  893. sizeof(struct sbp2_login_response),
  894. lu->login_response,
  895. lu->login_response_dma);
  896. if (lu->login_orb)
  897. dma_free_coherent(hi->host->device.parent,
  898. sizeof(struct sbp2_login_orb),
  899. lu->login_orb,
  900. lu->login_orb_dma);
  901. if (lu->reconnect_orb)
  902. dma_free_coherent(hi->host->device.parent,
  903. sizeof(struct sbp2_reconnect_orb),
  904. lu->reconnect_orb,
  905. lu->reconnect_orb_dma);
  906. if (lu->logout_orb)
  907. dma_free_coherent(hi->host->device.parent,
  908. sizeof(struct sbp2_logout_orb),
  909. lu->logout_orb,
  910. lu->logout_orb_dma);
  911. if (lu->query_logins_orb)
  912. dma_free_coherent(hi->host->device.parent,
  913. sizeof(struct sbp2_query_logins_orb),
  914. lu->query_logins_orb,
  915. lu->query_logins_orb_dma);
  916. if (lu->query_logins_response)
  917. dma_free_coherent(hi->host->device.parent,
  918. sizeof(struct sbp2_query_logins_response),
  919. lu->query_logins_response,
  920. lu->query_logins_response_dma);
  921. if (lu->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE)
  922. hpsb_unregister_addrspace(&sbp2_highlevel, hi->host,
  923. lu->status_fifo_addr);
  924. lu->ud->device.driver_data = NULL;
  925. module_put(hi->host->driver->owner);
  926. no_hi:
  927. kfree(lu);
  928. }
  929. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  930. /*
  931. * Deal with write requests on adapters which do not support physical DMA or
  932. * have it switched off.
  933. */
  934. static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid,
  935. int destid, quadlet_t *data, u64 addr,
  936. size_t length, u16 flags)
  937. {
  938. memcpy(bus_to_virt((u32) addr), data, length);
  939. return RCODE_COMPLETE;
  940. }
  941. /*
  942. * Deal with read requests on adapters which do not support physical DMA or
  943. * have it switched off.
  944. */
  945. static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid,
  946. quadlet_t *data, u64 addr, size_t length,
  947. u16 flags)
  948. {
  949. memcpy(data, bus_to_virt((u32) addr), length);
  950. return RCODE_COMPLETE;
  951. }
  952. #endif
  953. /**************************************
  954. * SBP-2 protocol related section
  955. **************************************/
  956. static int sbp2_query_logins(struct sbp2_lu *lu)
  957. {
  958. struct sbp2_fwhost_info *hi = lu->hi;
  959. quadlet_t data[2];
  960. int max_logins;
  961. int active_logins;
  962. lu->query_logins_orb->reserved1 = 0x0;
  963. lu->query_logins_orb->reserved2 = 0x0;
  964. lu->query_logins_orb->query_response_lo = lu->query_logins_response_dma;
  965. lu->query_logins_orb->query_response_hi =
  966. ORB_SET_NODE_ID(hi->host->node_id);
  967. lu->query_logins_orb->lun_misc =
  968. ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST);
  969. lu->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
  970. lu->query_logins_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  971. lu->query_logins_orb->reserved_resp_length =
  972. ORB_SET_QUERY_LOGINS_RESP_LENGTH(
  973. sizeof(struct sbp2_query_logins_response));
  974. lu->query_logins_orb->status_fifo_hi =
  975. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  976. lu->query_logins_orb->status_fifo_lo =
  977. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  978. sbp2util_cpu_to_be32_buffer(lu->query_logins_orb,
  979. sizeof(struct sbp2_query_logins_orb));
  980. memset(lu->query_logins_response, 0,
  981. sizeof(struct sbp2_query_logins_response));
  982. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  983. data[1] = lu->query_logins_orb_dma;
  984. sbp2util_cpu_to_be32_buffer(data, 8);
  985. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  986. if (sbp2util_access_timeout(lu, 2*HZ)) {
  987. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  988. return -EIO;
  989. }
  990. if (lu->status_block.ORB_offset_lo != lu->query_logins_orb_dma) {
  991. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  992. return -EIO;
  993. }
  994. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  995. SBP2_INFO("Error querying logins to SBP-2 device - failed");
  996. return -EIO;
  997. }
  998. sbp2util_cpu_to_be32_buffer(lu->query_logins_response,
  999. sizeof(struct sbp2_query_logins_response));
  1000. max_logins = RESPONSE_GET_MAX_LOGINS(
  1001. lu->query_logins_response->length_max_logins);
  1002. SBP2_INFO("Maximum concurrent logins supported: %d", max_logins);
  1003. active_logins = RESPONSE_GET_ACTIVE_LOGINS(
  1004. lu->query_logins_response->length_max_logins);
  1005. SBP2_INFO("Number of active logins: %d", active_logins);
  1006. if (active_logins >= max_logins) {
  1007. return -EIO;
  1008. }
  1009. return 0;
  1010. }
  1011. static int sbp2_login_device(struct sbp2_lu *lu)
  1012. {
  1013. struct sbp2_fwhost_info *hi = lu->hi;
  1014. quadlet_t data[2];
  1015. if (!lu->login_orb)
  1016. return -EIO;
  1017. if (!sbp2_exclusive_login && sbp2_query_logins(lu)) {
  1018. SBP2_INFO("Device does not support any more concurrent logins");
  1019. return -EIO;
  1020. }
  1021. /* assume no password */
  1022. lu->login_orb->password_hi = 0;
  1023. lu->login_orb->password_lo = 0;
  1024. lu->login_orb->login_response_lo = lu->login_response_dma;
  1025. lu->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1026. lu->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
  1027. /* one second reconnect time */
  1028. lu->login_orb->lun_misc |= ORB_SET_RECONNECT(0);
  1029. lu->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(sbp2_exclusive_login);
  1030. lu->login_orb->lun_misc |= ORB_SET_NOTIFY(1);
  1031. lu->login_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  1032. lu->login_orb->passwd_resp_lengths =
  1033. ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
  1034. lu->login_orb->status_fifo_hi =
  1035. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1036. lu->login_orb->status_fifo_lo =
  1037. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1038. sbp2util_cpu_to_be32_buffer(lu->login_orb,
  1039. sizeof(struct sbp2_login_orb));
  1040. memset(lu->login_response, 0, sizeof(struct sbp2_login_response));
  1041. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1042. data[1] = lu->login_orb_dma;
  1043. sbp2util_cpu_to_be32_buffer(data, 8);
  1044. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1045. /* wait up to 20 seconds for login status */
  1046. if (sbp2util_access_timeout(lu, 20*HZ)) {
  1047. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1048. return -EIO;
  1049. }
  1050. /* make sure that the returned status matches the login ORB */
  1051. if (lu->status_block.ORB_offset_lo != lu->login_orb_dma) {
  1052. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1053. return -EIO;
  1054. }
  1055. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1056. SBP2_ERR("Error logging into SBP-2 device - failed");
  1057. return -EIO;
  1058. }
  1059. sbp2util_cpu_to_be32_buffer(lu->login_response,
  1060. sizeof(struct sbp2_login_response));
  1061. lu->command_block_agent_addr =
  1062. ((u64)lu->login_response->command_block_agent_hi) << 32;
  1063. lu->command_block_agent_addr |=
  1064. ((u64)lu->login_response->command_block_agent_lo);
  1065. lu->command_block_agent_addr &= 0x0000ffffffffffffULL;
  1066. SBP2_INFO("Logged into SBP-2 device");
  1067. return 0;
  1068. }
  1069. static int sbp2_logout_device(struct sbp2_lu *lu)
  1070. {
  1071. struct sbp2_fwhost_info *hi = lu->hi;
  1072. quadlet_t data[2];
  1073. int error;
  1074. lu->logout_orb->reserved1 = 0x0;
  1075. lu->logout_orb->reserved2 = 0x0;
  1076. lu->logout_orb->reserved3 = 0x0;
  1077. lu->logout_orb->reserved4 = 0x0;
  1078. lu->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST);
  1079. lu->logout_orb->login_ID_misc |=
  1080. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1081. lu->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1082. lu->logout_orb->reserved5 = 0x0;
  1083. lu->logout_orb->status_fifo_hi =
  1084. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1085. lu->logout_orb->status_fifo_lo =
  1086. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1087. sbp2util_cpu_to_be32_buffer(lu->logout_orb,
  1088. sizeof(struct sbp2_logout_orb));
  1089. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1090. data[1] = lu->logout_orb_dma;
  1091. sbp2util_cpu_to_be32_buffer(data, 8);
  1092. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1093. if (error)
  1094. return error;
  1095. /* wait up to 1 second for the device to complete logout */
  1096. if (sbp2util_access_timeout(lu, HZ))
  1097. return -EIO;
  1098. SBP2_INFO("Logged out of SBP-2 device");
  1099. return 0;
  1100. }
  1101. static int sbp2_reconnect_device(struct sbp2_lu *lu)
  1102. {
  1103. struct sbp2_fwhost_info *hi = lu->hi;
  1104. quadlet_t data[2];
  1105. int error;
  1106. lu->reconnect_orb->reserved1 = 0x0;
  1107. lu->reconnect_orb->reserved2 = 0x0;
  1108. lu->reconnect_orb->reserved3 = 0x0;
  1109. lu->reconnect_orb->reserved4 = 0x0;
  1110. lu->reconnect_orb->login_ID_misc =
  1111. ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST);
  1112. lu->reconnect_orb->login_ID_misc |=
  1113. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1114. lu->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1115. lu->reconnect_orb->reserved5 = 0x0;
  1116. lu->reconnect_orb->status_fifo_hi =
  1117. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1118. lu->reconnect_orb->status_fifo_lo =
  1119. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1120. sbp2util_cpu_to_be32_buffer(lu->reconnect_orb,
  1121. sizeof(struct sbp2_reconnect_orb));
  1122. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1123. data[1] = lu->reconnect_orb_dma;
  1124. sbp2util_cpu_to_be32_buffer(data, 8);
  1125. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1126. if (error)
  1127. return error;
  1128. /* wait up to 1 second for reconnect status */
  1129. if (sbp2util_access_timeout(lu, HZ)) {
  1130. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1131. return -EIO;
  1132. }
  1133. /* make sure that the returned status matches the reconnect ORB */
  1134. if (lu->status_block.ORB_offset_lo != lu->reconnect_orb_dma) {
  1135. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1136. return -EIO;
  1137. }
  1138. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1139. SBP2_ERR("Error reconnecting to SBP-2 device - failed");
  1140. return -EIO;
  1141. }
  1142. SBP2_INFO("Reconnected to SBP-2 device");
  1143. return 0;
  1144. }
  1145. /*
  1146. * Set the target node's Single Phase Retry limit. Affects the target's retry
  1147. * behaviour if our node is too busy to accept requests.
  1148. */
  1149. static int sbp2_set_busy_timeout(struct sbp2_lu *lu)
  1150. {
  1151. quadlet_t data;
  1152. data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
  1153. if (hpsb_node_write(lu->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4))
  1154. SBP2_ERR("%s error", __func__);
  1155. return 0;
  1156. }
  1157. static void sbp2_parse_unit_directory(struct sbp2_lu *lu,
  1158. struct unit_directory *ud)
  1159. {
  1160. struct csr1212_keyval *kv;
  1161. struct csr1212_dentry *dentry;
  1162. u64 management_agent_addr;
  1163. u32 unit_characteristics, firmware_revision, model;
  1164. unsigned workarounds;
  1165. int i;
  1166. management_agent_addr = 0;
  1167. unit_characteristics = 0;
  1168. firmware_revision = SBP2_ROM_VALUE_MISSING;
  1169. model = ud->flags & UNIT_DIRECTORY_MODEL_ID ?
  1170. ud->model_id : SBP2_ROM_VALUE_MISSING;
  1171. csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) {
  1172. switch (kv->key.id) {
  1173. case CSR1212_KV_ID_DEPENDENT_INFO:
  1174. if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET)
  1175. management_agent_addr =
  1176. CSR1212_REGISTER_SPACE_BASE +
  1177. (kv->value.csr_offset << 2);
  1178. else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE)
  1179. lu->lun = ORB_SET_LUN(kv->value.immediate);
  1180. break;
  1181. case SBP2_UNIT_CHARACTERISTICS_KEY:
  1182. /* FIXME: This is ignored so far.
  1183. * See SBP-2 clause 7.4.8. */
  1184. unit_characteristics = kv->value.immediate;
  1185. break;
  1186. case SBP2_FIRMWARE_REVISION_KEY:
  1187. firmware_revision = kv->value.immediate;
  1188. break;
  1189. default:
  1190. /* FIXME: Check for SBP2_DEVICE_TYPE_AND_LUN_KEY.
  1191. * Its "ordered" bit has consequences for command ORB
  1192. * list handling. See SBP-2 clauses 4.6, 7.4.11, 10.2 */
  1193. break;
  1194. }
  1195. }
  1196. workarounds = sbp2_default_workarounds;
  1197. if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
  1198. for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
  1199. if (sbp2_workarounds_table[i].firmware_revision !=
  1200. SBP2_ROM_VALUE_WILDCARD &&
  1201. sbp2_workarounds_table[i].firmware_revision !=
  1202. (firmware_revision & 0xffff00))
  1203. continue;
  1204. if (sbp2_workarounds_table[i].model !=
  1205. SBP2_ROM_VALUE_WILDCARD &&
  1206. sbp2_workarounds_table[i].model != model)
  1207. continue;
  1208. workarounds |= sbp2_workarounds_table[i].workarounds;
  1209. break;
  1210. }
  1211. if (workarounds)
  1212. SBP2_INFO("Workarounds for node " NODE_BUS_FMT ": 0x%x "
  1213. "(firmware_revision 0x%06x, vendor_id 0x%06x,"
  1214. " model_id 0x%06x)",
  1215. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1216. workarounds, firmware_revision, ud->vendor_id,
  1217. model);
  1218. /* We would need one SCSI host template for each target to adjust
  1219. * max_sectors on the fly, therefore warn only. */
  1220. if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS &&
  1221. (sbp2_max_sectors * 512) > (128 * 1024))
  1222. SBP2_INFO("Node " NODE_BUS_FMT ": Bridge only supports 128KB "
  1223. "max transfer size. WARNING: Current max_sectors "
  1224. "setting is larger than 128KB (%d sectors)",
  1225. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1226. sbp2_max_sectors);
  1227. /* If this is a logical unit directory entry, process the parent
  1228. * to get the values. */
  1229. if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) {
  1230. struct unit_directory *parent_ud = container_of(
  1231. ud->device.parent, struct unit_directory, device);
  1232. sbp2_parse_unit_directory(lu, parent_ud);
  1233. } else {
  1234. lu->management_agent_addr = management_agent_addr;
  1235. lu->workarounds = workarounds;
  1236. if (ud->flags & UNIT_DIRECTORY_HAS_LUN)
  1237. lu->lun = ORB_SET_LUN(ud->lun);
  1238. }
  1239. }
  1240. #define SBP2_PAYLOAD_TO_BYTES(p) (1 << ((p) + 2))
  1241. /*
  1242. * This function is called in order to determine the max speed and packet
  1243. * size we can use in our ORBs. Note, that we (the driver and host) only
  1244. * initiate the transaction. The SBP-2 device actually transfers the data
  1245. * (by reading from the DMA area we tell it). This means that the SBP-2
  1246. * device decides the actual maximum data it can transfer. We just tell it
  1247. * the speed that it needs to use, and the max_rec the host supports, and
  1248. * it takes care of the rest.
  1249. */
  1250. static int sbp2_max_speed_and_size(struct sbp2_lu *lu)
  1251. {
  1252. struct sbp2_fwhost_info *hi = lu->hi;
  1253. u8 payload;
  1254. lu->speed_code = hi->host->speed[NODEID_TO_NODE(lu->ne->nodeid)];
  1255. if (lu->speed_code > sbp2_max_speed) {
  1256. lu->speed_code = sbp2_max_speed;
  1257. SBP2_INFO("Reducing speed to %s",
  1258. hpsb_speedto_str[sbp2_max_speed]);
  1259. }
  1260. /* Payload size is the lesser of what our speed supports and what
  1261. * our host supports. */
  1262. payload = min(sbp2_speedto_max_payload[lu->speed_code],
  1263. (u8) (hi->host->csr.max_rec - 1));
  1264. /* If physical DMA is off, work around limitation in ohci1394:
  1265. * packet size must not exceed PAGE_SIZE */
  1266. if (lu->ne->host->low_addr_space < (1ULL << 32))
  1267. while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE &&
  1268. payload)
  1269. payload--;
  1270. SBP2_INFO("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]",
  1271. NODE_BUS_ARGS(hi->host, lu->ne->nodeid),
  1272. hpsb_speedto_str[lu->speed_code],
  1273. SBP2_PAYLOAD_TO_BYTES(payload));
  1274. lu->max_payload_size = payload;
  1275. return 0;
  1276. }
  1277. static int sbp2_agent_reset(struct sbp2_lu *lu, int wait)
  1278. {
  1279. quadlet_t data;
  1280. u64 addr;
  1281. int retval;
  1282. unsigned long flags;
  1283. /* flush lu->protocol_work */
  1284. if (wait)
  1285. flush_scheduled_work();
  1286. data = ntohl(SBP2_AGENT_RESET_DATA);
  1287. addr = lu->command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
  1288. if (wait)
  1289. retval = hpsb_node_write(lu->ne, addr, &data, 4);
  1290. else
  1291. retval = sbp2util_node_write_no_wait(lu->ne, addr, &data, 4);
  1292. if (retval < 0) {
  1293. SBP2_ERR("hpsb_node_write failed.\n");
  1294. return -EIO;
  1295. }
  1296. /* make sure that the ORB_POINTER is written on next command */
  1297. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1298. lu->last_orb = NULL;
  1299. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1300. return 0;
  1301. }
  1302. static int sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
  1303. struct sbp2_fwhost_info *hi,
  1304. struct sbp2_command_info *cmd,
  1305. unsigned int sg_count,
  1306. struct scatterlist *sg,
  1307. u32 orb_direction,
  1308. enum dma_data_direction dma_dir)
  1309. {
  1310. struct device *dmadev = hi->host->device.parent;
  1311. struct sbp2_unrestricted_page_table *pt;
  1312. int i, n;
  1313. n = dma_map_sg(dmadev, sg, sg_count, dma_dir);
  1314. if (n == 0)
  1315. return -ENOMEM;
  1316. orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1317. orb->misc |= ORB_SET_DIRECTION(orb_direction);
  1318. /* special case if only one element (and less than 64KB in size) */
  1319. if (n == 1) {
  1320. orb->misc |= ORB_SET_DATA_SIZE(sg_dma_len(sg));
  1321. orb->data_descriptor_lo = sg_dma_address(sg);
  1322. } else {
  1323. pt = &cmd->scatter_gather_element[0];
  1324. dma_sync_single_for_cpu(dmadev, cmd->sge_dma,
  1325. sizeof(cmd->scatter_gather_element),
  1326. DMA_TO_DEVICE);
  1327. for_each_sg(sg, sg, n, i) {
  1328. pt[i].high = cpu_to_be32(sg_dma_len(sg) << 16);
  1329. pt[i].low = cpu_to_be32(sg_dma_address(sg));
  1330. }
  1331. orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1) |
  1332. ORB_SET_DATA_SIZE(n);
  1333. orb->data_descriptor_lo = cmd->sge_dma;
  1334. dma_sync_single_for_device(dmadev, cmd->sge_dma,
  1335. sizeof(cmd->scatter_gather_element),
  1336. DMA_TO_DEVICE);
  1337. }
  1338. return 0;
  1339. }
  1340. static int sbp2_create_command_orb(struct sbp2_lu *lu,
  1341. struct sbp2_command_info *cmd,
  1342. struct scsi_cmnd *SCpnt)
  1343. {
  1344. struct device *dmadev = lu->hi->host->device.parent;
  1345. struct sbp2_command_orb *orb = &cmd->command_orb;
  1346. unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
  1347. enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
  1348. u32 orb_direction;
  1349. int ret;
  1350. dma_sync_single_for_cpu(dmadev, cmd->command_orb_dma,
  1351. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  1352. /*
  1353. * Set-up our command ORB.
  1354. *
  1355. * NOTE: We're doing unrestricted page tables (s/g), as this is
  1356. * best performance (at least with the devices I have). This means
  1357. * that data_size becomes the number of s/g elements, and
  1358. * page_size should be zero (for unrestricted).
  1359. */
  1360. orb->next_ORB_hi = ORB_SET_NULL_PTR(1);
  1361. orb->next_ORB_lo = 0x0;
  1362. orb->misc = ORB_SET_MAX_PAYLOAD(lu->max_payload_size);
  1363. orb->misc |= ORB_SET_SPEED(lu->speed_code);
  1364. orb->misc |= ORB_SET_NOTIFY(1);
  1365. if (dma_dir == DMA_NONE)
  1366. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1367. else if (dma_dir == DMA_TO_DEVICE && scsi_request_bufflen)
  1368. orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA;
  1369. else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen)
  1370. orb_direction = ORB_DIRECTION_READ_FROM_MEDIA;
  1371. else {
  1372. SBP2_INFO("Falling back to DMA_NONE");
  1373. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1374. }
  1375. /* set up our page table stuff */
  1376. if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
  1377. orb->data_descriptor_hi = 0x0;
  1378. orb->data_descriptor_lo = 0x0;
  1379. orb->misc |= ORB_SET_DIRECTION(1);
  1380. ret = 0;
  1381. } else {
  1382. ret = sbp2_prep_command_orb_sg(orb, lu->hi, cmd,
  1383. scsi_sg_count(SCpnt),
  1384. scsi_sglist(SCpnt),
  1385. orb_direction, dma_dir);
  1386. }
  1387. sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
  1388. memset(orb->cdb, 0, sizeof(orb->cdb));
  1389. memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
  1390. dma_sync_single_for_device(dmadev, cmd->command_orb_dma,
  1391. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  1392. return ret;
  1393. }
  1394. static void sbp2_link_orb_command(struct sbp2_lu *lu,
  1395. struct sbp2_command_info *cmd)
  1396. {
  1397. struct sbp2_fwhost_info *hi = lu->hi;
  1398. struct sbp2_command_orb *last_orb;
  1399. dma_addr_t last_orb_dma;
  1400. u64 addr = lu->command_block_agent_addr;
  1401. quadlet_t data[2];
  1402. size_t length;
  1403. unsigned long flags;
  1404. /* check to see if there are any previous orbs to use */
  1405. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1406. last_orb = lu->last_orb;
  1407. last_orb_dma = lu->last_orb_dma;
  1408. if (!last_orb) {
  1409. /*
  1410. * last_orb == NULL means: We know that the target's fetch agent
  1411. * is not active right now.
  1412. */
  1413. addr += SBP2_ORB_POINTER_OFFSET;
  1414. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1415. data[1] = cmd->command_orb_dma;
  1416. sbp2util_cpu_to_be32_buffer(data, 8);
  1417. length = 8;
  1418. } else {
  1419. /*
  1420. * last_orb != NULL means: We know that the target's fetch agent
  1421. * is (very probably) not dead or in reset state right now.
  1422. * We have an ORB already sent that we can append a new one to.
  1423. * The target's fetch agent may or may not have read this
  1424. * previous ORB yet.
  1425. */
  1426. dma_sync_single_for_cpu(hi->host->device.parent, last_orb_dma,
  1427. sizeof(struct sbp2_command_orb),
  1428. DMA_TO_DEVICE);
  1429. last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma);
  1430. wmb();
  1431. /* Tells hardware that this pointer is valid */
  1432. last_orb->next_ORB_hi = 0;
  1433. dma_sync_single_for_device(hi->host->device.parent,
  1434. last_orb_dma,
  1435. sizeof(struct sbp2_command_orb),
  1436. DMA_TO_DEVICE);
  1437. addr += SBP2_DOORBELL_OFFSET;
  1438. data[0] = 0;
  1439. length = 4;
  1440. }
  1441. lu->last_orb = &cmd->command_orb;
  1442. lu->last_orb_dma = cmd->command_orb_dma;
  1443. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1444. if (sbp2util_node_write_no_wait(lu->ne, addr, data, length)) {
  1445. /*
  1446. * sbp2util_node_write_no_wait failed. We certainly ran out
  1447. * of transaction labels, perhaps just because there were no
  1448. * context switches which gave khpsbpkt a chance to collect
  1449. * free tlabels. Try again in non-atomic context. If necessary,
  1450. * the workqueue job will sleep to guaranteedly get a tlabel.
  1451. * We do not accept new commands until the job is over.
  1452. */
  1453. scsi_block_requests(lu->shost);
  1454. PREPARE_WORK(&lu->protocol_work,
  1455. last_orb ? sbp2util_write_doorbell:
  1456. sbp2util_write_orb_pointer);
  1457. schedule_work(&lu->protocol_work);
  1458. }
  1459. }
  1460. static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
  1461. void (*done)(struct scsi_cmnd *))
  1462. {
  1463. struct sbp2_command_info *cmd;
  1464. cmd = sbp2util_allocate_command_orb(lu, SCpnt, done);
  1465. if (!cmd)
  1466. return -EIO;
  1467. if (sbp2_create_command_orb(lu, cmd, SCpnt))
  1468. return -ENOMEM;
  1469. sbp2_link_orb_command(lu, cmd);
  1470. return 0;
  1471. }
  1472. /*
  1473. * Translates SBP-2 status into SCSI sense data for check conditions
  1474. */
  1475. static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status,
  1476. unchar *sense_data)
  1477. {
  1478. /* OK, it's pretty ugly... ;-) */
  1479. sense_data[0] = 0x70;
  1480. sense_data[1] = 0x0;
  1481. sense_data[2] = sbp2_status[9];
  1482. sense_data[3] = sbp2_status[12];
  1483. sense_data[4] = sbp2_status[13];
  1484. sense_data[5] = sbp2_status[14];
  1485. sense_data[6] = sbp2_status[15];
  1486. sense_data[7] = 10;
  1487. sense_data[8] = sbp2_status[16];
  1488. sense_data[9] = sbp2_status[17];
  1489. sense_data[10] = sbp2_status[18];
  1490. sense_data[11] = sbp2_status[19];
  1491. sense_data[12] = sbp2_status[10];
  1492. sense_data[13] = sbp2_status[11];
  1493. sense_data[14] = sbp2_status[20];
  1494. sense_data[15] = sbp2_status[21];
  1495. return sbp2_status[8] & 0x3f;
  1496. }
  1497. static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
  1498. int destid, quadlet_t *data, u64 addr,
  1499. size_t length, u16 fl)
  1500. {
  1501. struct sbp2_fwhost_info *hi;
  1502. struct sbp2_lu *lu = NULL, *lu_tmp;
  1503. struct scsi_cmnd *SCpnt = NULL;
  1504. struct sbp2_status_block *sb;
  1505. u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
  1506. struct sbp2_command_info *cmd;
  1507. unsigned long flags;
  1508. if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) {
  1509. SBP2_ERR("Wrong size of status block");
  1510. return RCODE_ADDRESS_ERROR;
  1511. }
  1512. if (unlikely(!host)) {
  1513. SBP2_ERR("host is NULL - this is bad!");
  1514. return RCODE_ADDRESS_ERROR;
  1515. }
  1516. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  1517. if (unlikely(!hi)) {
  1518. SBP2_ERR("host info is NULL - this is bad!");
  1519. return RCODE_ADDRESS_ERROR;
  1520. }
  1521. /* Find the unit which wrote the status. */
  1522. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  1523. list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) {
  1524. if (lu_tmp->ne->nodeid == nodeid &&
  1525. lu_tmp->status_fifo_addr == addr) {
  1526. lu = lu_tmp;
  1527. break;
  1528. }
  1529. }
  1530. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  1531. if (unlikely(!lu)) {
  1532. SBP2_ERR("lu is NULL - device is gone?");
  1533. return RCODE_ADDRESS_ERROR;
  1534. }
  1535. /* Put response into lu status fifo buffer. The first two bytes
  1536. * come in big endian bit order. Often the target writes only a
  1537. * truncated status block, minimally the first two quadlets. The rest
  1538. * is implied to be zeros. */
  1539. sb = &lu->status_block;
  1540. memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent));
  1541. memcpy(sb, data, length);
  1542. sbp2util_be32_to_cpu_buffer(sb, 8);
  1543. /* Ignore unsolicited status. Handle command ORB status. */
  1544. if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2))
  1545. cmd = NULL;
  1546. else
  1547. cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo);
  1548. if (cmd) {
  1549. /* Grab SCSI command pointers and check status. */
  1550. /*
  1551. * FIXME: If the src field in the status is 1, the ORB DMA must
  1552. * not be reused until status for a subsequent ORB is received.
  1553. */
  1554. SCpnt = cmd->Current_SCpnt;
  1555. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1556. sbp2util_mark_command_completed(lu, cmd);
  1557. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1558. if (SCpnt) {
  1559. u32 h = sb->ORB_offset_hi_misc;
  1560. u32 r = STATUS_GET_RESP(h);
  1561. if (r != RESP_STATUS_REQUEST_COMPLETE) {
  1562. SBP2_INFO("resp 0x%x, sbp_status 0x%x",
  1563. r, STATUS_GET_SBP_STATUS(h));
  1564. scsi_status =
  1565. r == RESP_STATUS_TRANSPORT_FAILURE ?
  1566. SBP2_SCSI_STATUS_BUSY :
  1567. SBP2_SCSI_STATUS_COMMAND_TERMINATED;
  1568. }
  1569. if (STATUS_GET_LEN(h) > 1)
  1570. scsi_status = sbp2_status_to_sense_data(
  1571. (unchar *)sb, SCpnt->sense_buffer);
  1572. if (STATUS_TEST_DEAD(h))
  1573. sbp2_agent_reset(lu, 0);
  1574. }
  1575. /* Check here to see if there are no commands in-use. If there
  1576. * are none, we know that the fetch agent left the active state
  1577. * _and_ that we did not reactivate it yet. Therefore clear
  1578. * last_orb so that next time we write directly to the
  1579. * ORB_POINTER register. That way the fetch agent does not need
  1580. * to refetch the next_ORB. */
  1581. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1582. if (list_empty(&lu->cmd_orb_inuse))
  1583. lu->last_orb = NULL;
  1584. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1585. } else {
  1586. /* It's probably status after a management request. */
  1587. if ((sb->ORB_offset_lo == lu->reconnect_orb_dma) ||
  1588. (sb->ORB_offset_lo == lu->login_orb_dma) ||
  1589. (sb->ORB_offset_lo == lu->query_logins_orb_dma) ||
  1590. (sb->ORB_offset_lo == lu->logout_orb_dma)) {
  1591. lu->access_complete = 1;
  1592. wake_up_interruptible(&sbp2_access_wq);
  1593. }
  1594. }
  1595. if (SCpnt)
  1596. sbp2scsi_complete_command(lu, scsi_status, SCpnt,
  1597. cmd->Current_done);
  1598. return RCODE_COMPLETE;
  1599. }
  1600. /**************************************
  1601. * SCSI interface related section
  1602. **************************************/
  1603. static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
  1604. void (*done)(struct scsi_cmnd *))
  1605. {
  1606. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1607. struct sbp2_fwhost_info *hi;
  1608. int result = DID_NO_CONNECT << 16;
  1609. if (unlikely(!sbp2util_node_is_available(lu)))
  1610. goto done;
  1611. hi = lu->hi;
  1612. if (unlikely(!hi)) {
  1613. SBP2_ERR("sbp2_fwhost_info is NULL - this is bad!");
  1614. goto done;
  1615. }
  1616. /* Multiple units are currently represented to the SCSI core as separate
  1617. * targets, not as one target with multiple LUs. Therefore return
  1618. * selection time-out to any IO directed at non-zero LUNs. */
  1619. if (unlikely(SCpnt->device->lun))
  1620. goto done;
  1621. if (unlikely(!hpsb_node_entry_valid(lu->ne))) {
  1622. SBP2_ERR("Bus reset in progress - rejecting command");
  1623. result = DID_BUS_BUSY << 16;
  1624. goto done;
  1625. }
  1626. /* Bidirectional commands are not yet implemented,
  1627. * and unknown transfer direction not handled. */
  1628. if (unlikely(SCpnt->sc_data_direction == DMA_BIDIRECTIONAL)) {
  1629. SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command");
  1630. result = DID_ERROR << 16;
  1631. goto done;
  1632. }
  1633. if (sbp2_send_command(lu, SCpnt, done)) {
  1634. SBP2_ERR("Error sending SCSI command");
  1635. sbp2scsi_complete_command(lu,
  1636. SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
  1637. SCpnt, done);
  1638. }
  1639. return 0;
  1640. done:
  1641. SCpnt->result = result;
  1642. done(SCpnt);
  1643. return 0;
  1644. }
  1645. static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
  1646. {
  1647. struct list_head *lh;
  1648. struct sbp2_command_info *cmd;
  1649. unsigned long flags;
  1650. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1651. while (!list_empty(&lu->cmd_orb_inuse)) {
  1652. lh = lu->cmd_orb_inuse.next;
  1653. cmd = list_entry(lh, struct sbp2_command_info, list);
  1654. sbp2util_mark_command_completed(lu, cmd);
  1655. if (cmd->Current_SCpnt) {
  1656. cmd->Current_SCpnt->result = status << 16;
  1657. cmd->Current_done(cmd->Current_SCpnt);
  1658. }
  1659. }
  1660. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1661. return;
  1662. }
  1663. /*
  1664. * Complete a regular SCSI command. Can be called in atomic context.
  1665. */
  1666. static void sbp2scsi_complete_command(struct sbp2_lu *lu, u32 scsi_status,
  1667. struct scsi_cmnd *SCpnt,
  1668. void (*done)(struct scsi_cmnd *))
  1669. {
  1670. if (!SCpnt) {
  1671. SBP2_ERR("SCpnt is NULL");
  1672. return;
  1673. }
  1674. switch (scsi_status) {
  1675. case SBP2_SCSI_STATUS_GOOD:
  1676. SCpnt->result = DID_OK << 16;
  1677. break;
  1678. case SBP2_SCSI_STATUS_BUSY:
  1679. SBP2_ERR("SBP2_SCSI_STATUS_BUSY");
  1680. SCpnt->result = DID_BUS_BUSY << 16;
  1681. break;
  1682. case SBP2_SCSI_STATUS_CHECK_CONDITION:
  1683. SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16;
  1684. break;
  1685. case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
  1686. SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT");
  1687. SCpnt->result = DID_NO_CONNECT << 16;
  1688. scsi_print_command(SCpnt);
  1689. break;
  1690. case SBP2_SCSI_STATUS_CONDITION_MET:
  1691. case SBP2_SCSI_STATUS_RESERVATION_CONFLICT:
  1692. case SBP2_SCSI_STATUS_COMMAND_TERMINATED:
  1693. SBP2_ERR("Bad SCSI status = %x", scsi_status);
  1694. SCpnt->result = DID_ERROR << 16;
  1695. scsi_print_command(SCpnt);
  1696. break;
  1697. default:
  1698. SBP2_ERR("Unsupported SCSI status = %x", scsi_status);
  1699. SCpnt->result = DID_ERROR << 16;
  1700. }
  1701. /* If a bus reset is in progress and there was an error, complete
  1702. * the command as busy so that it will get retried. */
  1703. if (!hpsb_node_entry_valid(lu->ne)
  1704. && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
  1705. SBP2_ERR("Completing command with busy (bus reset)");
  1706. SCpnt->result = DID_BUS_BUSY << 16;
  1707. }
  1708. /* Tell the SCSI stack that we're done with this command. */
  1709. done(SCpnt);
  1710. }
  1711. static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
  1712. {
  1713. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1714. if (sdev->lun != 0 || sdev->id != lu->ud->id || sdev->channel != 0)
  1715. return -ENODEV;
  1716. lu->sdev = sdev;
  1717. sdev->allow_restart = 1;
  1718. /* SBP-2 requires quadlet alignment of the data buffers. */
  1719. blk_queue_update_dma_alignment(sdev->request_queue, 4 - 1);
  1720. if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36)
  1721. sdev->inquiry_len = 36;
  1722. return 0;
  1723. }
  1724. static int sbp2scsi_slave_configure(struct scsi_device *sdev)
  1725. {
  1726. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1727. sdev->use_10_for_rw = 1;
  1728. if (sbp2_exclusive_login)
  1729. sdev->manage_start_stop = 1;
  1730. if (sdev->type == TYPE_ROM)
  1731. sdev->use_10_for_ms = 1;
  1732. if (sdev->type == TYPE_DISK &&
  1733. lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
  1734. sdev->skip_ms_page_8 = 1;
  1735. if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
  1736. sdev->fix_capacity = 1;
  1737. if (lu->workarounds & SBP2_WORKAROUND_POWER_CONDITION)
  1738. sdev->start_stop_pwr_cond = 1;
  1739. if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
  1740. blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
  1741. blk_queue_max_segment_size(sdev->request_queue, SBP2_MAX_SEG_SIZE);
  1742. return 0;
  1743. }
  1744. static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
  1745. {
  1746. ((struct sbp2_lu *)sdev->host->hostdata[0])->sdev = NULL;
  1747. return;
  1748. }
  1749. /*
  1750. * Called by scsi stack when something has really gone wrong.
  1751. * Usually called when a command has timed-out for some reason.
  1752. */
  1753. static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
  1754. {
  1755. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1756. struct sbp2_command_info *cmd;
  1757. unsigned long flags;
  1758. SBP2_INFO("aborting sbp2 command");
  1759. scsi_print_command(SCpnt);
  1760. if (sbp2util_node_is_available(lu)) {
  1761. sbp2_agent_reset(lu, 1);
  1762. /* Return a matching command structure to the free pool. */
  1763. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1764. cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt);
  1765. if (cmd) {
  1766. sbp2util_mark_command_completed(lu, cmd);
  1767. if (cmd->Current_SCpnt) {
  1768. cmd->Current_SCpnt->result = DID_ABORT << 16;
  1769. cmd->Current_done(cmd->Current_SCpnt);
  1770. }
  1771. }
  1772. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1773. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  1774. }
  1775. return SUCCESS;
  1776. }
  1777. /*
  1778. * Called by scsi stack when something has really gone wrong.
  1779. */
  1780. static int sbp2scsi_reset(struct scsi_cmnd *SCpnt)
  1781. {
  1782. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1783. SBP2_INFO("reset requested");
  1784. if (sbp2util_node_is_available(lu)) {
  1785. SBP2_INFO("generating sbp2 fetch agent reset");
  1786. sbp2_agent_reset(lu, 1);
  1787. }
  1788. return SUCCESS;
  1789. }
  1790. static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,
  1791. struct device_attribute *attr,
  1792. char *buf)
  1793. {
  1794. struct scsi_device *sdev;
  1795. struct sbp2_lu *lu;
  1796. if (!(sdev = to_scsi_device(dev)))
  1797. return 0;
  1798. if (!(lu = (struct sbp2_lu *)sdev->host->hostdata[0]))
  1799. return 0;
  1800. if (sbp2_long_sysfs_ieee1394_id)
  1801. return sprintf(buf, "%016Lx:%06x:%04x\n",
  1802. (unsigned long long)lu->ne->guid,
  1803. lu->ud->directory_id, ORB_SET_LUN(lu->lun));
  1804. else
  1805. return sprintf(buf, "%016Lx:%d:%d\n",
  1806. (unsigned long long)lu->ne->guid,
  1807. lu->ud->id, ORB_SET_LUN(lu->lun));
  1808. }
  1809. MODULE_AUTHOR("Ben Collins <bcollins@debian.org>");
  1810. MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
  1811. MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
  1812. MODULE_LICENSE("GPL");
  1813. static int sbp2_module_init(void)
  1814. {
  1815. int ret;
  1816. if (sbp2_serialize_io) {
  1817. sbp2_shost_template.can_queue = 1;
  1818. sbp2_shost_template.cmd_per_lun = 1;
  1819. }
  1820. sbp2_shost_template.max_sectors = sbp2_max_sectors;
  1821. hpsb_register_highlevel(&sbp2_highlevel);
  1822. ret = hpsb_register_protocol(&sbp2_driver);
  1823. if (ret) {
  1824. SBP2_ERR("Failed to register protocol");
  1825. hpsb_unregister_highlevel(&sbp2_highlevel);
  1826. return ret;
  1827. }
  1828. return 0;
  1829. }
  1830. static void __exit sbp2_module_exit(void)
  1831. {
  1832. hpsb_unregister_protocol(&sbp2_driver);
  1833. hpsb_unregister_highlevel(&sbp2_highlevel);
  1834. }
  1835. module_init(sbp2_module_init);
  1836. module_exit(sbp2_module_exit);