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