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