sbp2.c 63 KB

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