sbp2.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  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. const static 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. const static 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 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. /* iPod 4th generation */ {
  365. .firmware_revision = 0x0a2700,
  366. .model = 0x000021,
  367. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  368. },
  369. /* iPod mini */ {
  370. .firmware_revision = 0x0a2700,
  371. .model = 0x000022,
  372. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  373. },
  374. /* iPod mini */ {
  375. .firmware_revision = 0x0a2700,
  376. .model = 0x000023,
  377. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  378. },
  379. /* iPod Photo */ {
  380. .firmware_revision = 0x0a2700,
  381. .model = 0x00007e,
  382. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  383. }
  384. };
  385. /**************************************
  386. * General utility functions
  387. **************************************/
  388. #ifndef __BIG_ENDIAN
  389. /*
  390. * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
  391. */
  392. static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
  393. {
  394. u32 *temp = buffer;
  395. for (length = (length >> 2); length--; )
  396. temp[length] = be32_to_cpu(temp[length]);
  397. }
  398. /*
  399. * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
  400. */
  401. static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
  402. {
  403. u32 *temp = buffer;
  404. for (length = (length >> 2); length--; )
  405. temp[length] = cpu_to_be32(temp[length]);
  406. }
  407. #else /* BIG_ENDIAN */
  408. /* Why waste the cpu cycles? */
  409. #define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0)
  410. #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0)
  411. #endif
  412. static DECLARE_WAIT_QUEUE_HEAD(sbp2_access_wq);
  413. /*
  414. * Waits for completion of an SBP-2 access request.
  415. * Returns nonzero if timed out or prematurely interrupted.
  416. */
  417. static int sbp2util_access_timeout(struct sbp2_lu *lu, int timeout)
  418. {
  419. long leftover;
  420. leftover = wait_event_interruptible_timeout(
  421. sbp2_access_wq, lu->access_complete, timeout);
  422. lu->access_complete = 0;
  423. return leftover <= 0;
  424. }
  425. static void sbp2_free_packet(void *packet)
  426. {
  427. hpsb_free_tlabel(packet);
  428. hpsb_free_packet(packet);
  429. }
  430. /*
  431. * This is much like hpsb_node_write(), except it ignores the response
  432. * subaction and returns immediately. Can be used from atomic context.
  433. */
  434. static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
  435. quadlet_t *buf, size_t len)
  436. {
  437. struct hpsb_packet *packet;
  438. packet = hpsb_make_writepacket(ne->host, ne->nodeid, addr, buf, len);
  439. if (!packet)
  440. return -ENOMEM;
  441. hpsb_set_packet_complete_task(packet, sbp2_free_packet, packet);
  442. hpsb_node_fill_packet(ne, packet);
  443. if (hpsb_send_packet(packet) < 0) {
  444. sbp2_free_packet(packet);
  445. return -EIO;
  446. }
  447. return 0;
  448. }
  449. static void sbp2util_notify_fetch_agent(struct sbp2_lu *lu, u64 offset,
  450. quadlet_t *data, size_t len)
  451. {
  452. /* There is a small window after a bus reset within which the node
  453. * entry's generation is current but the reconnect wasn't completed. */
  454. if (unlikely(atomic_read(&lu->state) == SBP2LU_STATE_IN_RESET))
  455. return;
  456. if (hpsb_node_write(lu->ne, lu->command_block_agent_addr + offset,
  457. data, len))
  458. SBP2_ERR("sbp2util_notify_fetch_agent failed.");
  459. /* Now accept new SCSI commands, unless a bus reset happended during
  460. * hpsb_node_write. */
  461. if (likely(atomic_read(&lu->state) != SBP2LU_STATE_IN_RESET))
  462. scsi_unblock_requests(lu->shost);
  463. }
  464. static void sbp2util_write_orb_pointer(struct work_struct *work)
  465. {
  466. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  467. quadlet_t data[2];
  468. data[0] = ORB_SET_NODE_ID(lu->hi->host->node_id);
  469. data[1] = lu->last_orb_dma;
  470. sbp2util_cpu_to_be32_buffer(data, 8);
  471. sbp2util_notify_fetch_agent(lu, SBP2_ORB_POINTER_OFFSET, data, 8);
  472. }
  473. static void sbp2util_write_doorbell(struct work_struct *work)
  474. {
  475. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  476. sbp2util_notify_fetch_agent(lu, SBP2_DOORBELL_OFFSET, NULL, 4);
  477. }
  478. static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
  479. {
  480. struct sbp2_command_info *cmd;
  481. struct device *dmadev = lu->hi->host->device.parent;
  482. int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
  483. for (i = 0; i < orbs; i++) {
  484. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  485. if (!cmd)
  486. goto failed_alloc;
  487. cmd->command_orb_dma =
  488. dma_map_single(dmadev, &cmd->command_orb,
  489. sizeof(struct sbp2_command_orb),
  490. DMA_TO_DEVICE);
  491. if (dma_mapping_error(dmadev, cmd->command_orb_dma))
  492. goto failed_orb;
  493. cmd->sge_dma =
  494. dma_map_single(dmadev, &cmd->scatter_gather_element,
  495. sizeof(cmd->scatter_gather_element),
  496. DMA_TO_DEVICE);
  497. if (dma_mapping_error(dmadev, cmd->sge_dma))
  498. goto failed_sge;
  499. INIT_LIST_HEAD(&cmd->list);
  500. list_add_tail(&cmd->list, &lu->cmd_orb_completed);
  501. }
  502. return 0;
  503. failed_sge:
  504. dma_unmap_single(dmadev, cmd->command_orb_dma,
  505. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  506. failed_orb:
  507. kfree(cmd);
  508. failed_alloc:
  509. return -ENOMEM;
  510. }
  511. static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu,
  512. struct hpsb_host *host)
  513. {
  514. struct list_head *lh, *next;
  515. struct sbp2_command_info *cmd;
  516. unsigned long flags;
  517. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  518. if (!list_empty(&lu->cmd_orb_completed))
  519. list_for_each_safe(lh, next, &lu->cmd_orb_completed) {
  520. cmd = list_entry(lh, struct sbp2_command_info, list);
  521. dma_unmap_single(host->device.parent,
  522. cmd->command_orb_dma,
  523. sizeof(struct sbp2_command_orb),
  524. DMA_TO_DEVICE);
  525. dma_unmap_single(host->device.parent, cmd->sge_dma,
  526. sizeof(cmd->scatter_gather_element),
  527. DMA_TO_DEVICE);
  528. kfree(cmd);
  529. }
  530. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  531. return;
  532. }
  533. /*
  534. * Finds the sbp2_command for a given outstanding command ORB.
  535. * Only looks at the in-use list.
  536. */
  537. static struct sbp2_command_info *sbp2util_find_command_for_orb(
  538. struct sbp2_lu *lu, dma_addr_t orb)
  539. {
  540. struct sbp2_command_info *cmd;
  541. unsigned long flags;
  542. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  543. if (!list_empty(&lu->cmd_orb_inuse))
  544. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  545. if (cmd->command_orb_dma == orb) {
  546. spin_unlock_irqrestore(
  547. &lu->cmd_orb_lock, flags);
  548. return cmd;
  549. }
  550. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  551. return NULL;
  552. }
  553. /*
  554. * Finds the sbp2_command for a given outstanding SCpnt.
  555. * Only looks at the in-use list.
  556. * Must be called with lu->cmd_orb_lock held.
  557. */
  558. static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
  559. struct sbp2_lu *lu, void *SCpnt)
  560. {
  561. struct sbp2_command_info *cmd;
  562. if (!list_empty(&lu->cmd_orb_inuse))
  563. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  564. if (cmd->Current_SCpnt == SCpnt)
  565. return cmd;
  566. return NULL;
  567. }
  568. static struct sbp2_command_info *sbp2util_allocate_command_orb(
  569. struct sbp2_lu *lu,
  570. struct scsi_cmnd *Current_SCpnt,
  571. void (*Current_done)(struct scsi_cmnd *))
  572. {
  573. struct list_head *lh;
  574. struct sbp2_command_info *cmd = NULL;
  575. unsigned long flags;
  576. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  577. if (!list_empty(&lu->cmd_orb_completed)) {
  578. lh = lu->cmd_orb_completed.next;
  579. list_del(lh);
  580. cmd = list_entry(lh, struct sbp2_command_info, list);
  581. cmd->Current_done = Current_done;
  582. cmd->Current_SCpnt = Current_SCpnt;
  583. list_add_tail(&cmd->list, &lu->cmd_orb_inuse);
  584. } else
  585. SBP2_ERR("%s: no orbs available", __func__);
  586. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  587. return cmd;
  588. }
  589. /*
  590. * Unmaps the DMAs of a command and moves the command to the completed ORB list.
  591. * Must be called with lu->cmd_orb_lock held.
  592. */
  593. static void sbp2util_mark_command_completed(struct sbp2_lu *lu,
  594. struct sbp2_command_info *cmd)
  595. {
  596. if (scsi_sg_count(cmd->Current_SCpnt))
  597. dma_unmap_sg(lu->ud->ne->host->device.parent,
  598. scsi_sglist(cmd->Current_SCpnt),
  599. scsi_sg_count(cmd->Current_SCpnt),
  600. cmd->Current_SCpnt->sc_data_direction);
  601. list_move_tail(&cmd->list, &lu->cmd_orb_completed);
  602. }
  603. /*
  604. * Is lu valid? Is the 1394 node still present?
  605. */
  606. static inline int sbp2util_node_is_available(struct sbp2_lu *lu)
  607. {
  608. return lu && lu->ne && !lu->ne->in_limbo;
  609. }
  610. /*********************************************
  611. * IEEE-1394 core driver stack related section
  612. *********************************************/
  613. static int sbp2_probe(struct device *dev)
  614. {
  615. struct unit_directory *ud;
  616. struct sbp2_lu *lu;
  617. ud = container_of(dev, struct unit_directory, device);
  618. /* Don't probe UD's that have the LUN flag. We'll probe the LUN(s)
  619. * instead. */
  620. if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY)
  621. return -ENODEV;
  622. lu = sbp2_alloc_device(ud);
  623. if (!lu)
  624. return -ENOMEM;
  625. sbp2_parse_unit_directory(lu, ud);
  626. return sbp2_start_device(lu);
  627. }
  628. static int sbp2_remove(struct device *dev)
  629. {
  630. struct unit_directory *ud;
  631. struct sbp2_lu *lu;
  632. struct scsi_device *sdev;
  633. ud = container_of(dev, struct unit_directory, device);
  634. lu = ud->device.driver_data;
  635. if (!lu)
  636. return 0;
  637. if (lu->shost) {
  638. /* Get rid of enqueued commands if there is no chance to
  639. * send them. */
  640. if (!sbp2util_node_is_available(lu))
  641. sbp2scsi_complete_all_commands(lu, DID_NO_CONNECT);
  642. /* scsi_remove_device() may trigger shutdown functions of SCSI
  643. * highlevel drivers which would deadlock if blocked. */
  644. atomic_set(&lu->state, SBP2LU_STATE_IN_SHUTDOWN);
  645. scsi_unblock_requests(lu->shost);
  646. }
  647. sdev = lu->sdev;
  648. if (sdev) {
  649. lu->sdev = NULL;
  650. scsi_remove_device(sdev);
  651. }
  652. sbp2_logout_device(lu);
  653. sbp2_remove_device(lu);
  654. return 0;
  655. }
  656. static int sbp2_update(struct unit_directory *ud)
  657. {
  658. struct sbp2_lu *lu = ud->device.driver_data;
  659. if (sbp2_reconnect_device(lu) != 0) {
  660. /*
  661. * Reconnect failed. If another bus reset happened,
  662. * let nodemgr proceed and call sbp2_update again later
  663. * (or sbp2_remove if this node went away).
  664. */
  665. if (!hpsb_node_entry_valid(lu->ne))
  666. return 0;
  667. /*
  668. * Or the target rejected the reconnect because we weren't
  669. * fast enough. Try a regular login, but first log out
  670. * just in case of any weirdness.
  671. */
  672. sbp2_logout_device(lu);
  673. if (sbp2_login_device(lu) != 0) {
  674. if (!hpsb_node_entry_valid(lu->ne))
  675. return 0;
  676. /* Maybe another initiator won the login. */
  677. SBP2_ERR("Failed to reconnect to sbp2 device!");
  678. return -EBUSY;
  679. }
  680. }
  681. sbp2_set_busy_timeout(lu);
  682. sbp2_agent_reset(lu, 1);
  683. sbp2_max_speed_and_size(lu);
  684. /* Complete any pending commands with busy (so they get retried)
  685. * and remove them from our queue. */
  686. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  687. /* Accept new commands unless there was another bus reset in the
  688. * meantime. */
  689. if (hpsb_node_entry_valid(lu->ne)) {
  690. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  691. scsi_unblock_requests(lu->shost);
  692. }
  693. return 0;
  694. }
  695. static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
  696. {
  697. struct sbp2_fwhost_info *hi;
  698. struct Scsi_Host *shost = NULL;
  699. struct sbp2_lu *lu = NULL;
  700. unsigned long flags;
  701. lu = kzalloc(sizeof(*lu), GFP_KERNEL);
  702. if (!lu) {
  703. SBP2_ERR("failed to create lu");
  704. goto failed_alloc;
  705. }
  706. lu->ne = ud->ne;
  707. lu->ud = ud;
  708. lu->speed_code = IEEE1394_SPEED_100;
  709. lu->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
  710. lu->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE;
  711. INIT_LIST_HEAD(&lu->cmd_orb_inuse);
  712. INIT_LIST_HEAD(&lu->cmd_orb_completed);
  713. INIT_LIST_HEAD(&lu->lu_list);
  714. spin_lock_init(&lu->cmd_orb_lock);
  715. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  716. INIT_WORK(&lu->protocol_work, NULL);
  717. ud->device.driver_data = lu;
  718. hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host);
  719. if (!hi) {
  720. hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host,
  721. sizeof(*hi));
  722. if (!hi) {
  723. SBP2_ERR("failed to allocate hostinfo");
  724. goto failed_alloc;
  725. }
  726. hi->host = ud->ne->host;
  727. INIT_LIST_HEAD(&hi->logical_units);
  728. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  729. /* Handle data movement if physical dma is not
  730. * enabled or not supported on host controller */
  731. if (!hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host,
  732. &sbp2_physdma_ops,
  733. 0x0ULL, 0xfffffffcULL)) {
  734. SBP2_ERR("failed to register lower 4GB address range");
  735. goto failed_alloc;
  736. }
  737. #endif
  738. }
  739. if (dma_get_max_seg_size(hi->host->device.parent) > SBP2_MAX_SEG_SIZE)
  740. BUG_ON(dma_set_max_seg_size(hi->host->device.parent,
  741. SBP2_MAX_SEG_SIZE));
  742. /* Prevent unloading of the 1394 host */
  743. if (!try_module_get(hi->host->driver->owner)) {
  744. SBP2_ERR("failed to get a reference on 1394 host driver");
  745. goto failed_alloc;
  746. }
  747. lu->hi = hi;
  748. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  749. list_add_tail(&lu->lu_list, &hi->logical_units);
  750. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  751. /* Register the status FIFO address range. We could use the same FIFO
  752. * for targets at different nodes. However we need different FIFOs per
  753. * target in order to support multi-unit devices.
  754. * The FIFO is located out of the local host controller's physical range
  755. * but, if possible, within the posted write area. Status writes will
  756. * then be performed as unified transactions. This slightly reduces
  757. * bandwidth usage, and some Prolific based devices seem to require it.
  758. */
  759. lu->status_fifo_addr = hpsb_allocate_and_register_addrspace(
  760. &sbp2_highlevel, ud->ne->host, &sbp2_ops,
  761. sizeof(struct sbp2_status_block), sizeof(quadlet_t),
  762. ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END);
  763. if (lu->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
  764. SBP2_ERR("failed to allocate status FIFO address range");
  765. goto failed_alloc;
  766. }
  767. shost = scsi_host_alloc(&sbp2_shost_template, sizeof(unsigned long));
  768. if (!shost) {
  769. SBP2_ERR("failed to register scsi host");
  770. goto failed_alloc;
  771. }
  772. shost->hostdata[0] = (unsigned long)lu;
  773. if (!scsi_add_host(shost, &ud->device)) {
  774. lu->shost = shost;
  775. return lu;
  776. }
  777. SBP2_ERR("failed to add scsi host");
  778. scsi_host_put(shost);
  779. failed_alloc:
  780. sbp2_remove_device(lu);
  781. return NULL;
  782. }
  783. static void sbp2_host_reset(struct hpsb_host *host)
  784. {
  785. struct sbp2_fwhost_info *hi;
  786. struct sbp2_lu *lu;
  787. unsigned long flags;
  788. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  789. if (!hi)
  790. return;
  791. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  792. list_for_each_entry(lu, &hi->logical_units, lu_list)
  793. if (atomic_cmpxchg(&lu->state,
  794. SBP2LU_STATE_RUNNING, SBP2LU_STATE_IN_RESET)
  795. == SBP2LU_STATE_RUNNING)
  796. scsi_block_requests(lu->shost);
  797. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  798. }
  799. static int sbp2_start_device(struct sbp2_lu *lu)
  800. {
  801. struct sbp2_fwhost_info *hi = lu->hi;
  802. int error;
  803. lu->login_response = dma_alloc_coherent(hi->host->device.parent,
  804. sizeof(struct sbp2_login_response),
  805. &lu->login_response_dma, GFP_KERNEL);
  806. if (!lu->login_response)
  807. goto alloc_fail;
  808. lu->query_logins_orb = dma_alloc_coherent(hi->host->device.parent,
  809. sizeof(struct sbp2_query_logins_orb),
  810. &lu->query_logins_orb_dma, GFP_KERNEL);
  811. if (!lu->query_logins_orb)
  812. goto alloc_fail;
  813. lu->query_logins_response = dma_alloc_coherent(hi->host->device.parent,
  814. sizeof(struct sbp2_query_logins_response),
  815. &lu->query_logins_response_dma, GFP_KERNEL);
  816. if (!lu->query_logins_response)
  817. goto alloc_fail;
  818. lu->reconnect_orb = dma_alloc_coherent(hi->host->device.parent,
  819. sizeof(struct sbp2_reconnect_orb),
  820. &lu->reconnect_orb_dma, GFP_KERNEL);
  821. if (!lu->reconnect_orb)
  822. goto alloc_fail;
  823. lu->logout_orb = dma_alloc_coherent(hi->host->device.parent,
  824. sizeof(struct sbp2_logout_orb),
  825. &lu->logout_orb_dma, GFP_KERNEL);
  826. if (!lu->logout_orb)
  827. goto alloc_fail;
  828. lu->login_orb = dma_alloc_coherent(hi->host->device.parent,
  829. sizeof(struct sbp2_login_orb),
  830. &lu->login_orb_dma, GFP_KERNEL);
  831. if (!lu->login_orb)
  832. goto alloc_fail;
  833. if (sbp2util_create_command_orb_pool(lu))
  834. goto alloc_fail;
  835. /* Wait a second before trying to log in. Previously logged in
  836. * initiators need a chance to reconnect. */
  837. if (msleep_interruptible(1000)) {
  838. sbp2_remove_device(lu);
  839. return -EINTR;
  840. }
  841. if (sbp2_login_device(lu)) {
  842. sbp2_remove_device(lu);
  843. return -EBUSY;
  844. }
  845. sbp2_set_busy_timeout(lu);
  846. sbp2_agent_reset(lu, 1);
  847. sbp2_max_speed_and_size(lu);
  848. if (lu->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
  849. ssleep(SBP2_INQUIRY_DELAY);
  850. error = scsi_add_device(lu->shost, 0, lu->ud->id, 0);
  851. if (error) {
  852. SBP2_ERR("scsi_add_device failed");
  853. sbp2_logout_device(lu);
  854. sbp2_remove_device(lu);
  855. return error;
  856. }
  857. return 0;
  858. alloc_fail:
  859. SBP2_ERR("Could not allocate memory for lu");
  860. sbp2_remove_device(lu);
  861. return -ENOMEM;
  862. }
  863. static void sbp2_remove_device(struct sbp2_lu *lu)
  864. {
  865. struct sbp2_fwhost_info *hi;
  866. unsigned long flags;
  867. if (!lu)
  868. return;
  869. hi = lu->hi;
  870. if (!hi)
  871. goto no_hi;
  872. if (lu->shost) {
  873. scsi_remove_host(lu->shost);
  874. scsi_host_put(lu->shost);
  875. }
  876. flush_scheduled_work();
  877. sbp2util_remove_command_orb_pool(lu, hi->host);
  878. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  879. list_del(&lu->lu_list);
  880. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  881. if (lu->login_response)
  882. dma_free_coherent(hi->host->device.parent,
  883. sizeof(struct sbp2_login_response),
  884. lu->login_response,
  885. lu->login_response_dma);
  886. if (lu->login_orb)
  887. dma_free_coherent(hi->host->device.parent,
  888. sizeof(struct sbp2_login_orb),
  889. lu->login_orb,
  890. lu->login_orb_dma);
  891. if (lu->reconnect_orb)
  892. dma_free_coherent(hi->host->device.parent,
  893. sizeof(struct sbp2_reconnect_orb),
  894. lu->reconnect_orb,
  895. lu->reconnect_orb_dma);
  896. if (lu->logout_orb)
  897. dma_free_coherent(hi->host->device.parent,
  898. sizeof(struct sbp2_logout_orb),
  899. lu->logout_orb,
  900. lu->logout_orb_dma);
  901. if (lu->query_logins_orb)
  902. dma_free_coherent(hi->host->device.parent,
  903. sizeof(struct sbp2_query_logins_orb),
  904. lu->query_logins_orb,
  905. lu->query_logins_orb_dma);
  906. if (lu->query_logins_response)
  907. dma_free_coherent(hi->host->device.parent,
  908. sizeof(struct sbp2_query_logins_response),
  909. lu->query_logins_response,
  910. lu->query_logins_response_dma);
  911. if (lu->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE)
  912. hpsb_unregister_addrspace(&sbp2_highlevel, hi->host,
  913. lu->status_fifo_addr);
  914. lu->ud->device.driver_data = NULL;
  915. module_put(hi->host->driver->owner);
  916. no_hi:
  917. kfree(lu);
  918. }
  919. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  920. /*
  921. * Deal with write requests on adapters which do not support physical DMA or
  922. * have it switched off.
  923. */
  924. static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid,
  925. int destid, quadlet_t *data, u64 addr,
  926. size_t length, u16 flags)
  927. {
  928. memcpy(bus_to_virt((u32) addr), data, length);
  929. return RCODE_COMPLETE;
  930. }
  931. /*
  932. * Deal with read requests on adapters which do not support physical DMA or
  933. * have it switched off.
  934. */
  935. static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid,
  936. quadlet_t *data, u64 addr, size_t length,
  937. u16 flags)
  938. {
  939. memcpy(data, bus_to_virt((u32) addr), length);
  940. return RCODE_COMPLETE;
  941. }
  942. #endif
  943. /**************************************
  944. * SBP-2 protocol related section
  945. **************************************/
  946. static int sbp2_query_logins(struct sbp2_lu *lu)
  947. {
  948. struct sbp2_fwhost_info *hi = lu->hi;
  949. quadlet_t data[2];
  950. int max_logins;
  951. int active_logins;
  952. lu->query_logins_orb->reserved1 = 0x0;
  953. lu->query_logins_orb->reserved2 = 0x0;
  954. lu->query_logins_orb->query_response_lo = lu->query_logins_response_dma;
  955. lu->query_logins_orb->query_response_hi =
  956. ORB_SET_NODE_ID(hi->host->node_id);
  957. lu->query_logins_orb->lun_misc =
  958. ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST);
  959. lu->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
  960. lu->query_logins_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  961. lu->query_logins_orb->reserved_resp_length =
  962. ORB_SET_QUERY_LOGINS_RESP_LENGTH(
  963. sizeof(struct sbp2_query_logins_response));
  964. lu->query_logins_orb->status_fifo_hi =
  965. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  966. lu->query_logins_orb->status_fifo_lo =
  967. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  968. sbp2util_cpu_to_be32_buffer(lu->query_logins_orb,
  969. sizeof(struct sbp2_query_logins_orb));
  970. memset(lu->query_logins_response, 0,
  971. sizeof(struct sbp2_query_logins_response));
  972. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  973. data[1] = lu->query_logins_orb_dma;
  974. sbp2util_cpu_to_be32_buffer(data, 8);
  975. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  976. if (sbp2util_access_timeout(lu, 2*HZ)) {
  977. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  978. return -EIO;
  979. }
  980. if (lu->status_block.ORB_offset_lo != lu->query_logins_orb_dma) {
  981. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  982. return -EIO;
  983. }
  984. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  985. SBP2_INFO("Error querying logins to SBP-2 device - failed");
  986. return -EIO;
  987. }
  988. sbp2util_cpu_to_be32_buffer(lu->query_logins_response,
  989. sizeof(struct sbp2_query_logins_response));
  990. max_logins = RESPONSE_GET_MAX_LOGINS(
  991. lu->query_logins_response->length_max_logins);
  992. SBP2_INFO("Maximum concurrent logins supported: %d", max_logins);
  993. active_logins = RESPONSE_GET_ACTIVE_LOGINS(
  994. lu->query_logins_response->length_max_logins);
  995. SBP2_INFO("Number of active logins: %d", active_logins);
  996. if (active_logins >= max_logins) {
  997. return -EIO;
  998. }
  999. return 0;
  1000. }
  1001. static int sbp2_login_device(struct sbp2_lu *lu)
  1002. {
  1003. struct sbp2_fwhost_info *hi = lu->hi;
  1004. quadlet_t data[2];
  1005. if (!lu->login_orb)
  1006. return -EIO;
  1007. if (!sbp2_exclusive_login && sbp2_query_logins(lu)) {
  1008. SBP2_INFO("Device does not support any more concurrent logins");
  1009. return -EIO;
  1010. }
  1011. /* assume no password */
  1012. lu->login_orb->password_hi = 0;
  1013. lu->login_orb->password_lo = 0;
  1014. lu->login_orb->login_response_lo = lu->login_response_dma;
  1015. lu->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1016. lu->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
  1017. /* one second reconnect time */
  1018. lu->login_orb->lun_misc |= ORB_SET_RECONNECT(0);
  1019. lu->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(sbp2_exclusive_login);
  1020. lu->login_orb->lun_misc |= ORB_SET_NOTIFY(1);
  1021. lu->login_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  1022. lu->login_orb->passwd_resp_lengths =
  1023. ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
  1024. lu->login_orb->status_fifo_hi =
  1025. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1026. lu->login_orb->status_fifo_lo =
  1027. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1028. sbp2util_cpu_to_be32_buffer(lu->login_orb,
  1029. sizeof(struct sbp2_login_orb));
  1030. memset(lu->login_response, 0, sizeof(struct sbp2_login_response));
  1031. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1032. data[1] = lu->login_orb_dma;
  1033. sbp2util_cpu_to_be32_buffer(data, 8);
  1034. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1035. /* wait up to 20 seconds for login status */
  1036. if (sbp2util_access_timeout(lu, 20*HZ)) {
  1037. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1038. return -EIO;
  1039. }
  1040. /* make sure that the returned status matches the login ORB */
  1041. if (lu->status_block.ORB_offset_lo != lu->login_orb_dma) {
  1042. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1043. return -EIO;
  1044. }
  1045. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1046. SBP2_ERR("Error logging into SBP-2 device - failed");
  1047. return -EIO;
  1048. }
  1049. sbp2util_cpu_to_be32_buffer(lu->login_response,
  1050. sizeof(struct sbp2_login_response));
  1051. lu->command_block_agent_addr =
  1052. ((u64)lu->login_response->command_block_agent_hi) << 32;
  1053. lu->command_block_agent_addr |=
  1054. ((u64)lu->login_response->command_block_agent_lo);
  1055. lu->command_block_agent_addr &= 0x0000ffffffffffffULL;
  1056. SBP2_INFO("Logged into SBP-2 device");
  1057. return 0;
  1058. }
  1059. static int sbp2_logout_device(struct sbp2_lu *lu)
  1060. {
  1061. struct sbp2_fwhost_info *hi = lu->hi;
  1062. quadlet_t data[2];
  1063. int error;
  1064. lu->logout_orb->reserved1 = 0x0;
  1065. lu->logout_orb->reserved2 = 0x0;
  1066. lu->logout_orb->reserved3 = 0x0;
  1067. lu->logout_orb->reserved4 = 0x0;
  1068. lu->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST);
  1069. lu->logout_orb->login_ID_misc |=
  1070. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1071. lu->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1072. lu->logout_orb->reserved5 = 0x0;
  1073. lu->logout_orb->status_fifo_hi =
  1074. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1075. lu->logout_orb->status_fifo_lo =
  1076. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1077. sbp2util_cpu_to_be32_buffer(lu->logout_orb,
  1078. sizeof(struct sbp2_logout_orb));
  1079. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1080. data[1] = lu->logout_orb_dma;
  1081. sbp2util_cpu_to_be32_buffer(data, 8);
  1082. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1083. if (error)
  1084. return error;
  1085. /* wait up to 1 second for the device to complete logout */
  1086. if (sbp2util_access_timeout(lu, HZ))
  1087. return -EIO;
  1088. SBP2_INFO("Logged out of SBP-2 device");
  1089. return 0;
  1090. }
  1091. static int sbp2_reconnect_device(struct sbp2_lu *lu)
  1092. {
  1093. struct sbp2_fwhost_info *hi = lu->hi;
  1094. quadlet_t data[2];
  1095. int error;
  1096. lu->reconnect_orb->reserved1 = 0x0;
  1097. lu->reconnect_orb->reserved2 = 0x0;
  1098. lu->reconnect_orb->reserved3 = 0x0;
  1099. lu->reconnect_orb->reserved4 = 0x0;
  1100. lu->reconnect_orb->login_ID_misc =
  1101. ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST);
  1102. lu->reconnect_orb->login_ID_misc |=
  1103. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1104. lu->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1105. lu->reconnect_orb->reserved5 = 0x0;
  1106. lu->reconnect_orb->status_fifo_hi =
  1107. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1108. lu->reconnect_orb->status_fifo_lo =
  1109. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1110. sbp2util_cpu_to_be32_buffer(lu->reconnect_orb,
  1111. sizeof(struct sbp2_reconnect_orb));
  1112. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1113. data[1] = lu->reconnect_orb_dma;
  1114. sbp2util_cpu_to_be32_buffer(data, 8);
  1115. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1116. if (error)
  1117. return error;
  1118. /* wait up to 1 second for reconnect status */
  1119. if (sbp2util_access_timeout(lu, HZ)) {
  1120. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1121. return -EIO;
  1122. }
  1123. /* make sure that the returned status matches the reconnect ORB */
  1124. if (lu->status_block.ORB_offset_lo != lu->reconnect_orb_dma) {
  1125. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1126. return -EIO;
  1127. }
  1128. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1129. SBP2_ERR("Error reconnecting to SBP-2 device - failed");
  1130. return -EIO;
  1131. }
  1132. SBP2_INFO("Reconnected to SBP-2 device");
  1133. return 0;
  1134. }
  1135. /*
  1136. * Set the target node's Single Phase Retry limit. Affects the target's retry
  1137. * behaviour if our node is too busy to accept requests.
  1138. */
  1139. static int sbp2_set_busy_timeout(struct sbp2_lu *lu)
  1140. {
  1141. quadlet_t data;
  1142. data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
  1143. if (hpsb_node_write(lu->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4))
  1144. SBP2_ERR("%s error", __func__);
  1145. return 0;
  1146. }
  1147. static void sbp2_parse_unit_directory(struct sbp2_lu *lu,
  1148. struct unit_directory *ud)
  1149. {
  1150. struct csr1212_keyval *kv;
  1151. struct csr1212_dentry *dentry;
  1152. u64 management_agent_addr;
  1153. u32 unit_characteristics, firmware_revision, model;
  1154. unsigned workarounds;
  1155. int i;
  1156. management_agent_addr = 0;
  1157. unit_characteristics = 0;
  1158. firmware_revision = SBP2_ROM_VALUE_MISSING;
  1159. model = ud->flags & UNIT_DIRECTORY_MODEL_ID ?
  1160. ud->model_id : SBP2_ROM_VALUE_MISSING;
  1161. csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) {
  1162. switch (kv->key.id) {
  1163. case CSR1212_KV_ID_DEPENDENT_INFO:
  1164. if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET)
  1165. management_agent_addr =
  1166. CSR1212_REGISTER_SPACE_BASE +
  1167. (kv->value.csr_offset << 2);
  1168. else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE)
  1169. lu->lun = ORB_SET_LUN(kv->value.immediate);
  1170. break;
  1171. case SBP2_UNIT_CHARACTERISTICS_KEY:
  1172. /* FIXME: This is ignored so far.
  1173. * See SBP-2 clause 7.4.8. */
  1174. unit_characteristics = kv->value.immediate;
  1175. break;
  1176. case SBP2_FIRMWARE_REVISION_KEY:
  1177. firmware_revision = kv->value.immediate;
  1178. break;
  1179. default:
  1180. /* FIXME: Check for SBP2_DEVICE_TYPE_AND_LUN_KEY.
  1181. * Its "ordered" bit has consequences for command ORB
  1182. * list handling. See SBP-2 clauses 4.6, 7.4.11, 10.2 */
  1183. break;
  1184. }
  1185. }
  1186. workarounds = sbp2_default_workarounds;
  1187. if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
  1188. for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
  1189. if (sbp2_workarounds_table[i].firmware_revision !=
  1190. SBP2_ROM_VALUE_WILDCARD &&
  1191. sbp2_workarounds_table[i].firmware_revision !=
  1192. (firmware_revision & 0xffff00))
  1193. continue;
  1194. if (sbp2_workarounds_table[i].model !=
  1195. SBP2_ROM_VALUE_WILDCARD &&
  1196. sbp2_workarounds_table[i].model != model)
  1197. continue;
  1198. workarounds |= sbp2_workarounds_table[i].workarounds;
  1199. break;
  1200. }
  1201. if (workarounds)
  1202. SBP2_INFO("Workarounds for node " NODE_BUS_FMT ": 0x%x "
  1203. "(firmware_revision 0x%06x, vendor_id 0x%06x,"
  1204. " model_id 0x%06x)",
  1205. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1206. workarounds, firmware_revision,
  1207. ud->vendor_id ? ud->vendor_id : ud->ne->vendor_id,
  1208. model);
  1209. /* We would need one SCSI host template for each target to adjust
  1210. * max_sectors on the fly, therefore warn only. */
  1211. if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS &&
  1212. (sbp2_max_sectors * 512) > (128 * 1024))
  1213. SBP2_INFO("Node " NODE_BUS_FMT ": Bridge only supports 128KB "
  1214. "max transfer size. WARNING: Current max_sectors "
  1215. "setting is larger than 128KB (%d sectors)",
  1216. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1217. sbp2_max_sectors);
  1218. /* If this is a logical unit directory entry, process the parent
  1219. * to get the values. */
  1220. if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) {
  1221. struct unit_directory *parent_ud = container_of(
  1222. ud->device.parent, struct unit_directory, device);
  1223. sbp2_parse_unit_directory(lu, parent_ud);
  1224. } else {
  1225. lu->management_agent_addr = management_agent_addr;
  1226. lu->workarounds = workarounds;
  1227. if (ud->flags & UNIT_DIRECTORY_HAS_LUN)
  1228. lu->lun = ORB_SET_LUN(ud->lun);
  1229. }
  1230. }
  1231. #define SBP2_PAYLOAD_TO_BYTES(p) (1 << ((p) + 2))
  1232. /*
  1233. * This function is called in order to determine the max speed and packet
  1234. * size we can use in our ORBs. Note, that we (the driver and host) only
  1235. * initiate the transaction. The SBP-2 device actually transfers the data
  1236. * (by reading from the DMA area we tell it). This means that the SBP-2
  1237. * device decides the actual maximum data it can transfer. We just tell it
  1238. * the speed that it needs to use, and the max_rec the host supports, and
  1239. * it takes care of the rest.
  1240. */
  1241. static int sbp2_max_speed_and_size(struct sbp2_lu *lu)
  1242. {
  1243. struct sbp2_fwhost_info *hi = lu->hi;
  1244. u8 payload;
  1245. lu->speed_code = hi->host->speed[NODEID_TO_NODE(lu->ne->nodeid)];
  1246. if (lu->speed_code > sbp2_max_speed) {
  1247. lu->speed_code = sbp2_max_speed;
  1248. SBP2_INFO("Reducing speed to %s",
  1249. hpsb_speedto_str[sbp2_max_speed]);
  1250. }
  1251. /* Payload size is the lesser of what our speed supports and what
  1252. * our host supports. */
  1253. payload = min(sbp2_speedto_max_payload[lu->speed_code],
  1254. (u8) (hi->host->csr.max_rec - 1));
  1255. /* If physical DMA is off, work around limitation in ohci1394:
  1256. * packet size must not exceed PAGE_SIZE */
  1257. if (lu->ne->host->low_addr_space < (1ULL << 32))
  1258. while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE &&
  1259. payload)
  1260. payload--;
  1261. SBP2_INFO("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]",
  1262. NODE_BUS_ARGS(hi->host, lu->ne->nodeid),
  1263. hpsb_speedto_str[lu->speed_code],
  1264. SBP2_PAYLOAD_TO_BYTES(payload));
  1265. lu->max_payload_size = payload;
  1266. return 0;
  1267. }
  1268. static int sbp2_agent_reset(struct sbp2_lu *lu, int wait)
  1269. {
  1270. quadlet_t data;
  1271. u64 addr;
  1272. int retval;
  1273. unsigned long flags;
  1274. /* flush lu->protocol_work */
  1275. if (wait)
  1276. flush_scheduled_work();
  1277. data = ntohl(SBP2_AGENT_RESET_DATA);
  1278. addr = lu->command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
  1279. if (wait)
  1280. retval = hpsb_node_write(lu->ne, addr, &data, 4);
  1281. else
  1282. retval = sbp2util_node_write_no_wait(lu->ne, addr, &data, 4);
  1283. if (retval < 0) {
  1284. SBP2_ERR("hpsb_node_write failed.\n");
  1285. return -EIO;
  1286. }
  1287. /* make sure that the ORB_POINTER is written on next command */
  1288. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1289. lu->last_orb = NULL;
  1290. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1291. return 0;
  1292. }
  1293. static int sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
  1294. struct sbp2_fwhost_info *hi,
  1295. struct sbp2_command_info *cmd,
  1296. unsigned int sg_count,
  1297. struct scatterlist *sg,
  1298. u32 orb_direction,
  1299. enum dma_data_direction dma_dir)
  1300. {
  1301. struct device *dmadev = hi->host->device.parent;
  1302. struct sbp2_unrestricted_page_table *pt;
  1303. int i, n;
  1304. n = dma_map_sg(dmadev, sg, sg_count, dma_dir);
  1305. if (n == 0)
  1306. return -ENOMEM;
  1307. orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1308. orb->misc |= ORB_SET_DIRECTION(orb_direction);
  1309. /* special case if only one element (and less than 64KB in size) */
  1310. if (n == 1) {
  1311. orb->misc |= ORB_SET_DATA_SIZE(sg_dma_len(sg));
  1312. orb->data_descriptor_lo = sg_dma_address(sg);
  1313. } else {
  1314. pt = &cmd->scatter_gather_element[0];
  1315. dma_sync_single_for_cpu(dmadev, cmd->sge_dma,
  1316. sizeof(cmd->scatter_gather_element),
  1317. DMA_TO_DEVICE);
  1318. for_each_sg(sg, sg, n, i) {
  1319. pt[i].high = cpu_to_be32(sg_dma_len(sg) << 16);
  1320. pt[i].low = cpu_to_be32(sg_dma_address(sg));
  1321. }
  1322. orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1) |
  1323. ORB_SET_DATA_SIZE(n);
  1324. orb->data_descriptor_lo = cmd->sge_dma;
  1325. dma_sync_single_for_device(dmadev, cmd->sge_dma,
  1326. sizeof(cmd->scatter_gather_element),
  1327. DMA_TO_DEVICE);
  1328. }
  1329. return 0;
  1330. }
  1331. static int sbp2_create_command_orb(struct sbp2_lu *lu,
  1332. struct sbp2_command_info *cmd,
  1333. struct scsi_cmnd *SCpnt)
  1334. {
  1335. struct device *dmadev = lu->hi->host->device.parent;
  1336. struct sbp2_command_orb *orb = &cmd->command_orb;
  1337. unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
  1338. enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
  1339. u32 orb_direction;
  1340. int ret;
  1341. dma_sync_single_for_cpu(dmadev, cmd->command_orb_dma,
  1342. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  1343. /*
  1344. * Set-up our command ORB.
  1345. *
  1346. * NOTE: We're doing unrestricted page tables (s/g), as this is
  1347. * best performance (at least with the devices I have). This means
  1348. * that data_size becomes the number of s/g elements, and
  1349. * page_size should be zero (for unrestricted).
  1350. */
  1351. orb->next_ORB_hi = ORB_SET_NULL_PTR(1);
  1352. orb->next_ORB_lo = 0x0;
  1353. orb->misc = ORB_SET_MAX_PAYLOAD(lu->max_payload_size);
  1354. orb->misc |= ORB_SET_SPEED(lu->speed_code);
  1355. orb->misc |= ORB_SET_NOTIFY(1);
  1356. if (dma_dir == DMA_NONE)
  1357. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1358. else if (dma_dir == DMA_TO_DEVICE && scsi_request_bufflen)
  1359. orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA;
  1360. else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen)
  1361. orb_direction = ORB_DIRECTION_READ_FROM_MEDIA;
  1362. else {
  1363. SBP2_INFO("Falling back to DMA_NONE");
  1364. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1365. }
  1366. /* set up our page table stuff */
  1367. if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
  1368. orb->data_descriptor_hi = 0x0;
  1369. orb->data_descriptor_lo = 0x0;
  1370. orb->misc |= ORB_SET_DIRECTION(1);
  1371. ret = 0;
  1372. } else {
  1373. ret = sbp2_prep_command_orb_sg(orb, lu->hi, cmd,
  1374. scsi_sg_count(SCpnt),
  1375. scsi_sglist(SCpnt),
  1376. orb_direction, dma_dir);
  1377. }
  1378. sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
  1379. memset(orb->cdb, 0, sizeof(orb->cdb));
  1380. memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
  1381. dma_sync_single_for_device(dmadev, cmd->command_orb_dma,
  1382. sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
  1383. return ret;
  1384. }
  1385. static void sbp2_link_orb_command(struct sbp2_lu *lu,
  1386. struct sbp2_command_info *cmd)
  1387. {
  1388. struct sbp2_fwhost_info *hi = lu->hi;
  1389. struct sbp2_command_orb *last_orb;
  1390. dma_addr_t last_orb_dma;
  1391. u64 addr = lu->command_block_agent_addr;
  1392. quadlet_t data[2];
  1393. size_t length;
  1394. unsigned long flags;
  1395. /* check to see if there are any previous orbs to use */
  1396. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1397. last_orb = lu->last_orb;
  1398. last_orb_dma = lu->last_orb_dma;
  1399. if (!last_orb) {
  1400. /*
  1401. * last_orb == NULL means: We know that the target's fetch agent
  1402. * is not active right now.
  1403. */
  1404. addr += SBP2_ORB_POINTER_OFFSET;
  1405. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1406. data[1] = cmd->command_orb_dma;
  1407. sbp2util_cpu_to_be32_buffer(data, 8);
  1408. length = 8;
  1409. } else {
  1410. /*
  1411. * last_orb != NULL means: We know that the target's fetch agent
  1412. * is (very probably) not dead or in reset state right now.
  1413. * We have an ORB already sent that we can append a new one to.
  1414. * The target's fetch agent may or may not have read this
  1415. * previous ORB yet.
  1416. */
  1417. dma_sync_single_for_cpu(hi->host->device.parent, last_orb_dma,
  1418. sizeof(struct sbp2_command_orb),
  1419. DMA_TO_DEVICE);
  1420. last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma);
  1421. wmb();
  1422. /* Tells hardware that this pointer is valid */
  1423. last_orb->next_ORB_hi = 0;
  1424. dma_sync_single_for_device(hi->host->device.parent,
  1425. last_orb_dma,
  1426. sizeof(struct sbp2_command_orb),
  1427. DMA_TO_DEVICE);
  1428. addr += SBP2_DOORBELL_OFFSET;
  1429. data[0] = 0;
  1430. length = 4;
  1431. }
  1432. lu->last_orb = &cmd->command_orb;
  1433. lu->last_orb_dma = cmd->command_orb_dma;
  1434. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1435. if (sbp2util_node_write_no_wait(lu->ne, addr, data, length)) {
  1436. /*
  1437. * sbp2util_node_write_no_wait failed. We certainly ran out
  1438. * of transaction labels, perhaps just because there were no
  1439. * context switches which gave khpsbpkt a chance to collect
  1440. * free tlabels. Try again in non-atomic context. If necessary,
  1441. * the workqueue job will sleep to guaranteedly get a tlabel.
  1442. * We do not accept new commands until the job is over.
  1443. */
  1444. scsi_block_requests(lu->shost);
  1445. PREPARE_WORK(&lu->protocol_work,
  1446. last_orb ? sbp2util_write_doorbell:
  1447. sbp2util_write_orb_pointer);
  1448. schedule_work(&lu->protocol_work);
  1449. }
  1450. }
  1451. static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
  1452. void (*done)(struct scsi_cmnd *))
  1453. {
  1454. struct sbp2_command_info *cmd;
  1455. cmd = sbp2util_allocate_command_orb(lu, SCpnt, done);
  1456. if (!cmd)
  1457. return -EIO;
  1458. if (sbp2_create_command_orb(lu, cmd, SCpnt))
  1459. return -ENOMEM;
  1460. sbp2_link_orb_command(lu, cmd);
  1461. return 0;
  1462. }
  1463. /*
  1464. * Translates SBP-2 status into SCSI sense data for check conditions
  1465. */
  1466. static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status,
  1467. unchar *sense_data)
  1468. {
  1469. /* OK, it's pretty ugly... ;-) */
  1470. sense_data[0] = 0x70;
  1471. sense_data[1] = 0x0;
  1472. sense_data[2] = sbp2_status[9];
  1473. sense_data[3] = sbp2_status[12];
  1474. sense_data[4] = sbp2_status[13];
  1475. sense_data[5] = sbp2_status[14];
  1476. sense_data[6] = sbp2_status[15];
  1477. sense_data[7] = 10;
  1478. sense_data[8] = sbp2_status[16];
  1479. sense_data[9] = sbp2_status[17];
  1480. sense_data[10] = sbp2_status[18];
  1481. sense_data[11] = sbp2_status[19];
  1482. sense_data[12] = sbp2_status[10];
  1483. sense_data[13] = sbp2_status[11];
  1484. sense_data[14] = sbp2_status[20];
  1485. sense_data[15] = sbp2_status[21];
  1486. return sbp2_status[8] & 0x3f;
  1487. }
  1488. static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
  1489. int destid, quadlet_t *data, u64 addr,
  1490. size_t length, u16 fl)
  1491. {
  1492. struct sbp2_fwhost_info *hi;
  1493. struct sbp2_lu *lu = NULL, *lu_tmp;
  1494. struct scsi_cmnd *SCpnt = NULL;
  1495. struct sbp2_status_block *sb;
  1496. u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
  1497. struct sbp2_command_info *cmd;
  1498. unsigned long flags;
  1499. if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) {
  1500. SBP2_ERR("Wrong size of status block");
  1501. return RCODE_ADDRESS_ERROR;
  1502. }
  1503. if (unlikely(!host)) {
  1504. SBP2_ERR("host is NULL - this is bad!");
  1505. return RCODE_ADDRESS_ERROR;
  1506. }
  1507. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  1508. if (unlikely(!hi)) {
  1509. SBP2_ERR("host info is NULL - this is bad!");
  1510. return RCODE_ADDRESS_ERROR;
  1511. }
  1512. /* Find the unit which wrote the status. */
  1513. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  1514. list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) {
  1515. if (lu_tmp->ne->nodeid == nodeid &&
  1516. lu_tmp->status_fifo_addr == addr) {
  1517. lu = lu_tmp;
  1518. break;
  1519. }
  1520. }
  1521. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  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. /* Grab SCSI command pointers and check status. */
  1541. /*
  1542. * FIXME: If the src field in the status is 1, the ORB DMA must
  1543. * not be reused until status for a subsequent ORB is received.
  1544. */
  1545. SCpnt = cmd->Current_SCpnt;
  1546. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1547. sbp2util_mark_command_completed(lu, cmd);
  1548. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1549. if (SCpnt) {
  1550. u32 h = sb->ORB_offset_hi_misc;
  1551. u32 r = STATUS_GET_RESP(h);
  1552. if (r != RESP_STATUS_REQUEST_COMPLETE) {
  1553. SBP2_INFO("resp 0x%x, sbp_status 0x%x",
  1554. r, STATUS_GET_SBP_STATUS(h));
  1555. scsi_status =
  1556. r == RESP_STATUS_TRANSPORT_FAILURE ?
  1557. SBP2_SCSI_STATUS_BUSY :
  1558. SBP2_SCSI_STATUS_COMMAND_TERMINATED;
  1559. }
  1560. if (STATUS_GET_LEN(h) > 1)
  1561. scsi_status = sbp2_status_to_sense_data(
  1562. (unchar *)sb, SCpnt->sense_buffer);
  1563. if (STATUS_TEST_DEAD(h))
  1564. sbp2_agent_reset(lu, 0);
  1565. }
  1566. /* Check here to see if there are no commands in-use. If there
  1567. * are none, we know that the fetch agent left the active state
  1568. * _and_ that we did not reactivate it yet. Therefore clear
  1569. * last_orb so that next time we write directly to the
  1570. * ORB_POINTER register. That way the fetch agent does not need
  1571. * to refetch the next_ORB. */
  1572. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1573. if (list_empty(&lu->cmd_orb_inuse))
  1574. lu->last_orb = NULL;
  1575. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1576. } else {
  1577. /* It's probably status after a management request. */
  1578. if ((sb->ORB_offset_lo == lu->reconnect_orb_dma) ||
  1579. (sb->ORB_offset_lo == lu->login_orb_dma) ||
  1580. (sb->ORB_offset_lo == lu->query_logins_orb_dma) ||
  1581. (sb->ORB_offset_lo == lu->logout_orb_dma)) {
  1582. lu->access_complete = 1;
  1583. wake_up_interruptible(&sbp2_access_wq);
  1584. }
  1585. }
  1586. if (SCpnt)
  1587. sbp2scsi_complete_command(lu, scsi_status, SCpnt,
  1588. cmd->Current_done);
  1589. return RCODE_COMPLETE;
  1590. }
  1591. /**************************************
  1592. * SCSI interface related section
  1593. **************************************/
  1594. static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
  1595. void (*done)(struct scsi_cmnd *))
  1596. {
  1597. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1598. struct sbp2_fwhost_info *hi;
  1599. int result = DID_NO_CONNECT << 16;
  1600. if (unlikely(!sbp2util_node_is_available(lu)))
  1601. goto done;
  1602. hi = lu->hi;
  1603. if (unlikely(!hi)) {
  1604. SBP2_ERR("sbp2_fwhost_info is NULL - this is bad!");
  1605. goto done;
  1606. }
  1607. /* Multiple units are currently represented to the SCSI core as separate
  1608. * targets, not as one target with multiple LUs. Therefore return
  1609. * selection time-out to any IO directed at non-zero LUNs. */
  1610. if (unlikely(SCpnt->device->lun))
  1611. goto done;
  1612. if (unlikely(!hpsb_node_entry_valid(lu->ne))) {
  1613. SBP2_ERR("Bus reset in progress - rejecting command");
  1614. result = DID_BUS_BUSY << 16;
  1615. goto done;
  1616. }
  1617. /* Bidirectional commands are not yet implemented,
  1618. * and unknown transfer direction not handled. */
  1619. if (unlikely(SCpnt->sc_data_direction == DMA_BIDIRECTIONAL)) {
  1620. SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command");
  1621. result = DID_ERROR << 16;
  1622. goto done;
  1623. }
  1624. if (sbp2_send_command(lu, SCpnt, done)) {
  1625. SBP2_ERR("Error sending SCSI command");
  1626. sbp2scsi_complete_command(lu,
  1627. SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
  1628. SCpnt, done);
  1629. }
  1630. return 0;
  1631. done:
  1632. SCpnt->result = result;
  1633. done(SCpnt);
  1634. return 0;
  1635. }
  1636. static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
  1637. {
  1638. struct list_head *lh;
  1639. struct sbp2_command_info *cmd;
  1640. unsigned long flags;
  1641. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1642. while (!list_empty(&lu->cmd_orb_inuse)) {
  1643. lh = lu->cmd_orb_inuse.next;
  1644. cmd = list_entry(lh, struct sbp2_command_info, list);
  1645. sbp2util_mark_command_completed(lu, cmd);
  1646. if (cmd->Current_SCpnt) {
  1647. cmd->Current_SCpnt->result = status << 16;
  1648. cmd->Current_done(cmd->Current_SCpnt);
  1649. }
  1650. }
  1651. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1652. return;
  1653. }
  1654. /*
  1655. * Complete a regular SCSI command. Can be called in atomic context.
  1656. */
  1657. static void sbp2scsi_complete_command(struct sbp2_lu *lu, u32 scsi_status,
  1658. struct scsi_cmnd *SCpnt,
  1659. void (*done)(struct scsi_cmnd *))
  1660. {
  1661. if (!SCpnt) {
  1662. SBP2_ERR("SCpnt is NULL");
  1663. return;
  1664. }
  1665. switch (scsi_status) {
  1666. case SBP2_SCSI_STATUS_GOOD:
  1667. SCpnt->result = DID_OK << 16;
  1668. break;
  1669. case SBP2_SCSI_STATUS_BUSY:
  1670. SBP2_ERR("SBP2_SCSI_STATUS_BUSY");
  1671. SCpnt->result = DID_BUS_BUSY << 16;
  1672. break;
  1673. case SBP2_SCSI_STATUS_CHECK_CONDITION:
  1674. SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16;
  1675. break;
  1676. case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
  1677. SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT");
  1678. SCpnt->result = DID_NO_CONNECT << 16;
  1679. scsi_print_command(SCpnt);
  1680. break;
  1681. case SBP2_SCSI_STATUS_CONDITION_MET:
  1682. case SBP2_SCSI_STATUS_RESERVATION_CONFLICT:
  1683. case SBP2_SCSI_STATUS_COMMAND_TERMINATED:
  1684. SBP2_ERR("Bad SCSI status = %x", scsi_status);
  1685. SCpnt->result = DID_ERROR << 16;
  1686. scsi_print_command(SCpnt);
  1687. break;
  1688. default:
  1689. SBP2_ERR("Unsupported SCSI status = %x", scsi_status);
  1690. SCpnt->result = DID_ERROR << 16;
  1691. }
  1692. /* If a bus reset is in progress and there was an error, complete
  1693. * the command as busy so that it will get retried. */
  1694. if (!hpsb_node_entry_valid(lu->ne)
  1695. && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
  1696. SBP2_ERR("Completing command with busy (bus reset)");
  1697. SCpnt->result = DID_BUS_BUSY << 16;
  1698. }
  1699. /* Tell the SCSI stack that we're done with this command. */
  1700. done(SCpnt);
  1701. }
  1702. static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
  1703. {
  1704. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1705. if (sdev->lun != 0 || sdev->id != lu->ud->id || sdev->channel != 0)
  1706. return -ENODEV;
  1707. lu->sdev = sdev;
  1708. sdev->allow_restart = 1;
  1709. /* SBP-2 requires quadlet alignment of the data buffers. */
  1710. blk_queue_update_dma_alignment(sdev->request_queue, 4 - 1);
  1711. if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36)
  1712. sdev->inquiry_len = 36;
  1713. return 0;
  1714. }
  1715. static int sbp2scsi_slave_configure(struct scsi_device *sdev)
  1716. {
  1717. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1718. sdev->use_10_for_rw = 1;
  1719. if (sbp2_exclusive_login)
  1720. sdev->manage_start_stop = 1;
  1721. if (sdev->type == TYPE_ROM)
  1722. sdev->use_10_for_ms = 1;
  1723. if (sdev->type == TYPE_DISK &&
  1724. lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
  1725. sdev->skip_ms_page_8 = 1;
  1726. if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
  1727. sdev->fix_capacity = 1;
  1728. if (lu->workarounds & SBP2_WORKAROUND_POWER_CONDITION)
  1729. sdev->start_stop_pwr_cond = 1;
  1730. if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
  1731. blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
  1732. blk_queue_max_segment_size(sdev->request_queue, SBP2_MAX_SEG_SIZE);
  1733. return 0;
  1734. }
  1735. static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
  1736. {
  1737. ((struct sbp2_lu *)sdev->host->hostdata[0])->sdev = NULL;
  1738. return;
  1739. }
  1740. /*
  1741. * Called by scsi stack when something has really gone wrong.
  1742. * Usually called when a command has timed-out for some reason.
  1743. */
  1744. static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
  1745. {
  1746. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1747. struct sbp2_command_info *cmd;
  1748. unsigned long flags;
  1749. SBP2_INFO("aborting sbp2 command");
  1750. scsi_print_command(SCpnt);
  1751. if (sbp2util_node_is_available(lu)) {
  1752. sbp2_agent_reset(lu, 1);
  1753. /* Return a matching command structure to the free pool. */
  1754. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1755. cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt);
  1756. if (cmd) {
  1757. sbp2util_mark_command_completed(lu, cmd);
  1758. if (cmd->Current_SCpnt) {
  1759. cmd->Current_SCpnt->result = DID_ABORT << 16;
  1760. cmd->Current_done(cmd->Current_SCpnt);
  1761. }
  1762. }
  1763. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1764. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  1765. }
  1766. return SUCCESS;
  1767. }
  1768. /*
  1769. * Called by scsi stack when something has really gone wrong.
  1770. */
  1771. static int sbp2scsi_reset(struct scsi_cmnd *SCpnt)
  1772. {
  1773. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1774. SBP2_INFO("reset requested");
  1775. if (sbp2util_node_is_available(lu)) {
  1776. SBP2_INFO("generating sbp2 fetch agent reset");
  1777. sbp2_agent_reset(lu, 1);
  1778. }
  1779. return SUCCESS;
  1780. }
  1781. static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,
  1782. struct device_attribute *attr,
  1783. char *buf)
  1784. {
  1785. struct scsi_device *sdev;
  1786. struct sbp2_lu *lu;
  1787. if (!(sdev = to_scsi_device(dev)))
  1788. return 0;
  1789. if (!(lu = (struct sbp2_lu *)sdev->host->hostdata[0]))
  1790. return 0;
  1791. if (sbp2_long_sysfs_ieee1394_id)
  1792. return sprintf(buf, "%016Lx:%06x:%04x\n",
  1793. (unsigned long long)lu->ne->guid,
  1794. lu->ud->directory_id, ORB_SET_LUN(lu->lun));
  1795. else
  1796. return sprintf(buf, "%016Lx:%d:%d\n",
  1797. (unsigned long long)lu->ne->guid,
  1798. lu->ud->id, ORB_SET_LUN(lu->lun));
  1799. }
  1800. MODULE_AUTHOR("Ben Collins <bcollins@debian.org>");
  1801. MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
  1802. MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
  1803. MODULE_LICENSE("GPL");
  1804. static int sbp2_module_init(void)
  1805. {
  1806. int ret;
  1807. if (sbp2_serialize_io) {
  1808. sbp2_shost_template.can_queue = 1;
  1809. sbp2_shost_template.cmd_per_lun = 1;
  1810. }
  1811. sbp2_shost_template.max_sectors = sbp2_max_sectors;
  1812. hpsb_register_highlevel(&sbp2_highlevel);
  1813. ret = hpsb_register_protocol(&sbp2_driver);
  1814. if (ret) {
  1815. SBP2_ERR("Failed to register protocol");
  1816. hpsb_unregister_highlevel(&sbp2_highlevel);
  1817. return ret;
  1818. }
  1819. return 0;
  1820. }
  1821. static void __exit sbp2_module_exit(void)
  1822. {
  1823. hpsb_unregister_protocol(&sbp2_driver);
  1824. hpsb_unregister_highlevel(&sbp2_highlevel);
  1825. }
  1826. module_init(sbp2_module_init);
  1827. module_exit(sbp2_module_exit);