esas2r_main.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. /*
  2. * linux/drivers/scsi/esas2r/esas2r_main.c
  3. * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
  4. *
  5. * Copyright (c) 2001-2013 ATTO Technology, Inc.
  6. * (mailto:linuxdrivers@attotech.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. *
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, write to the Free Software
  40. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  41. * USA.
  42. */
  43. #include "esas2r.h"
  44. MODULE_DESCRIPTION(ESAS2R_DRVR_NAME ": " ESAS2R_LONGNAME " driver");
  45. MODULE_AUTHOR("ATTO Technology, Inc.");
  46. MODULE_LICENSE("GPL");
  47. MODULE_VERSION(ESAS2R_VERSION_STR);
  48. /* global definitions */
  49. static int found_adapters;
  50. struct esas2r_adapter *esas2r_adapters[MAX_ADAPTERS];
  51. #define ESAS2R_VDA_EVENT_PORT1 54414
  52. #define ESAS2R_VDA_EVENT_PORT2 54415
  53. #define ESAS2R_VDA_EVENT_SOCK_COUNT 2
  54. static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
  55. {
  56. struct device *dev = container_of(kobj, struct device, kobj);
  57. struct Scsi_Host *host = class_to_shost(dev);
  58. return (struct esas2r_adapter *)host->hostdata;
  59. }
  60. static ssize_t read_fw(struct file *file, struct kobject *kobj,
  61. struct bin_attribute *attr,
  62. char *buf, loff_t off, size_t count)
  63. {
  64. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  65. return esas2r_read_fw(a, buf, off, count);
  66. }
  67. static ssize_t write_fw(struct file *file, struct kobject *kobj,
  68. struct bin_attribute *attr,
  69. char *buf, loff_t off, size_t count)
  70. {
  71. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  72. return esas2r_write_fw(a, buf, off, count);
  73. }
  74. static ssize_t read_fs(struct file *file, struct kobject *kobj,
  75. struct bin_attribute *attr,
  76. char *buf, loff_t off, size_t count)
  77. {
  78. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  79. return esas2r_read_fs(a, buf, off, count);
  80. }
  81. static ssize_t write_fs(struct file *file, struct kobject *kobj,
  82. struct bin_attribute *attr,
  83. char *buf, loff_t off, size_t count)
  84. {
  85. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  86. int length = min(sizeof(struct esas2r_ioctl_fs), count);
  87. int result = 0;
  88. result = esas2r_write_fs(a, buf, off, count);
  89. if (result < 0)
  90. result = 0;
  91. return length;
  92. }
  93. static ssize_t read_vda(struct file *file, struct kobject *kobj,
  94. struct bin_attribute *attr,
  95. char *buf, loff_t off, size_t count)
  96. {
  97. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  98. return esas2r_read_vda(a, buf, off, count);
  99. }
  100. static ssize_t write_vda(struct file *file, struct kobject *kobj,
  101. struct bin_attribute *attr,
  102. char *buf, loff_t off, size_t count)
  103. {
  104. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  105. return esas2r_write_vda(a, buf, off, count);
  106. }
  107. static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
  108. struct bin_attribute *attr,
  109. char *buf, loff_t off, size_t count)
  110. {
  111. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  112. int length = min_t(size_t, sizeof(struct esas2r_sas_nvram), PAGE_SIZE);
  113. memcpy(buf, a->nvram, length);
  114. return length;
  115. }
  116. static ssize_t write_live_nvram(struct file *file, struct kobject *kobj,
  117. struct bin_attribute *attr,
  118. char *buf, loff_t off, size_t count)
  119. {
  120. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  121. struct esas2r_request *rq;
  122. int result = -EFAULT;
  123. rq = esas2r_alloc_request(a);
  124. if (rq == NULL)
  125. return -ENOMEM;
  126. if (esas2r_write_params(a, rq, (struct esas2r_sas_nvram *)buf))
  127. result = count;
  128. esas2r_free_request(a, rq);
  129. return result;
  130. }
  131. static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
  132. struct bin_attribute *attr,
  133. char *buf, loff_t off, size_t count)
  134. {
  135. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  136. esas2r_nvram_get_defaults(a, (struct esas2r_sas_nvram *)buf);
  137. return sizeof(struct esas2r_sas_nvram);
  138. }
  139. static ssize_t read_hw(struct file *file, struct kobject *kobj,
  140. struct bin_attribute *attr,
  141. char *buf, loff_t off, size_t count)
  142. {
  143. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  144. int length = min_t(size_t, sizeof(struct atto_ioctl), PAGE_SIZE);
  145. if (!a->local_atto_ioctl)
  146. return -ENOMEM;
  147. if (handle_hba_ioctl(a, a->local_atto_ioctl) != IOCTL_SUCCESS)
  148. return -ENOMEM;
  149. memcpy(buf, a->local_atto_ioctl, length);
  150. return length;
  151. }
  152. static ssize_t write_hw(struct file *file, struct kobject *kobj,
  153. struct bin_attribute *attr,
  154. char *buf, loff_t off, size_t count)
  155. {
  156. struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
  157. int length = min(sizeof(struct atto_ioctl), count);
  158. if (!a->local_atto_ioctl) {
  159. a->local_atto_ioctl = kmalloc(sizeof(struct atto_ioctl),
  160. GFP_KERNEL);
  161. if (a->local_atto_ioctl == NULL) {
  162. esas2r_log(ESAS2R_LOG_WARN,
  163. "write_hw kzalloc failed for %zu bytes",
  164. sizeof(struct atto_ioctl));
  165. return -ENOMEM;
  166. }
  167. }
  168. memset(a->local_atto_ioctl, 0, sizeof(struct atto_ioctl));
  169. memcpy(a->local_atto_ioctl, buf, length);
  170. return length;
  171. }
  172. #define ESAS2R_RW_BIN_ATTR(_name) \
  173. struct bin_attribute bin_attr_ ## _name = { \
  174. .attr = \
  175. { .name = __stringify(_name), .mode = S_IRUSR | S_IWUSR }, \
  176. .size = 0, \
  177. .read = read_ ## _name, \
  178. .write = write_ ## _name }
  179. ESAS2R_RW_BIN_ATTR(fw);
  180. ESAS2R_RW_BIN_ATTR(fs);
  181. ESAS2R_RW_BIN_ATTR(vda);
  182. ESAS2R_RW_BIN_ATTR(hw);
  183. ESAS2R_RW_BIN_ATTR(live_nvram);
  184. struct bin_attribute bin_attr_default_nvram = {
  185. .attr = { .name = "default_nvram", .mode = S_IRUGO },
  186. .size = 0,
  187. .read = read_default_nvram,
  188. .write = NULL
  189. };
  190. static struct scsi_host_template driver_template = {
  191. .module = THIS_MODULE,
  192. .show_info = esas2r_show_info,
  193. .name = ESAS2R_LONGNAME,
  194. .info = esas2r_info,
  195. .ioctl = esas2r_ioctl,
  196. .queuecommand = esas2r_queuecommand,
  197. .eh_abort_handler = esas2r_eh_abort,
  198. .eh_device_reset_handler = esas2r_device_reset,
  199. .eh_bus_reset_handler = esas2r_bus_reset,
  200. .eh_host_reset_handler = esas2r_host_reset,
  201. .eh_target_reset_handler = esas2r_target_reset,
  202. .can_queue = 128,
  203. .this_id = -1,
  204. .sg_tablesize = SG_CHUNK_SIZE,
  205. .cmd_per_lun =
  206. ESAS2R_DEFAULT_CMD_PER_LUN,
  207. .present = 0,
  208. .unchecked_isa_dma = 0,
  209. .use_clustering = ENABLE_CLUSTERING,
  210. .emulated = 0,
  211. .proc_name = ESAS2R_DRVR_NAME,
  212. .change_queue_depth = scsi_change_queue_depth,
  213. .max_sectors = 0xFFFF,
  214. };
  215. int sgl_page_size = 512;
  216. module_param(sgl_page_size, int, 0);
  217. MODULE_PARM_DESC(sgl_page_size,
  218. "Scatter/gather list (SGL) page size in number of S/G "
  219. "entries. If your application is doing a lot of very large "
  220. "transfers, you may want to increase the SGL page size. "
  221. "Default 512.");
  222. int num_sg_lists = 1024;
  223. module_param(num_sg_lists, int, 0);
  224. MODULE_PARM_DESC(num_sg_lists,
  225. "Number of scatter/gather lists. Default 1024.");
  226. int sg_tablesize = SG_CHUNK_SIZE;
  227. module_param(sg_tablesize, int, 0);
  228. MODULE_PARM_DESC(sg_tablesize,
  229. "Maximum number of entries in a scatter/gather table.");
  230. int num_requests = 256;
  231. module_param(num_requests, int, 0);
  232. MODULE_PARM_DESC(num_requests,
  233. "Number of requests. Default 256.");
  234. int num_ae_requests = 4;
  235. module_param(num_ae_requests, int, 0);
  236. MODULE_PARM_DESC(num_ae_requests,
  237. "Number of VDA asynchronous event requests. Default 4.");
  238. int cmd_per_lun = ESAS2R_DEFAULT_CMD_PER_LUN;
  239. module_param(cmd_per_lun, int, 0);
  240. MODULE_PARM_DESC(cmd_per_lun,
  241. "Maximum number of commands per LUN. Default "
  242. DEFINED_NUM_TO_STR(ESAS2R_DEFAULT_CMD_PER_LUN) ".");
  243. int can_queue = 128;
  244. module_param(can_queue, int, 0);
  245. MODULE_PARM_DESC(can_queue,
  246. "Maximum number of commands per adapter. Default 128.");
  247. int esas2r_max_sectors = 0xFFFF;
  248. module_param(esas2r_max_sectors, int, 0);
  249. MODULE_PARM_DESC(esas2r_max_sectors,
  250. "Maximum number of disk sectors in a single data transfer. "
  251. "Default 65535 (largest possible setting).");
  252. int interrupt_mode = 1;
  253. module_param(interrupt_mode, int, 0);
  254. MODULE_PARM_DESC(interrupt_mode,
  255. "Defines the interrupt mode to use. 0 for legacy"
  256. ", 1 for MSI. Default is MSI (1).");
  257. static const struct pci_device_id
  258. esas2r_pci_table[] = {
  259. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x0049,
  260. 0,
  261. 0, 0 },
  262. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x004A,
  263. 0,
  264. 0, 0 },
  265. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x004B,
  266. 0,
  267. 0, 0 },
  268. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x004C,
  269. 0,
  270. 0, 0 },
  271. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x004D,
  272. 0,
  273. 0, 0 },
  274. { ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x004E,
  275. 0,
  276. 0, 0 },
  277. { 0, 0, 0, 0,
  278. 0,
  279. 0, 0 }
  280. };
  281. MODULE_DEVICE_TABLE(pci, esas2r_pci_table);
  282. static int
  283. esas2r_probe(struct pci_dev *pcid, const struct pci_device_id *id);
  284. static void
  285. esas2r_remove(struct pci_dev *pcid);
  286. static struct pci_driver
  287. esas2r_pci_driver = {
  288. .name = ESAS2R_DRVR_NAME,
  289. .id_table = esas2r_pci_table,
  290. .probe = esas2r_probe,
  291. .remove = esas2r_remove,
  292. .suspend = esas2r_suspend,
  293. .resume = esas2r_resume,
  294. };
  295. static int esas2r_probe(struct pci_dev *pcid,
  296. const struct pci_device_id *id)
  297. {
  298. struct Scsi_Host *host = NULL;
  299. struct esas2r_adapter *a;
  300. int err;
  301. size_t host_alloc_size = sizeof(struct esas2r_adapter)
  302. + ((num_requests) +
  303. 1) * sizeof(struct esas2r_request);
  304. esas2r_log_dev(ESAS2R_LOG_DEBG, &(pcid->dev),
  305. "esas2r_probe() 0x%02x 0x%02x 0x%02x 0x%02x",
  306. pcid->vendor,
  307. pcid->device,
  308. pcid->subsystem_vendor,
  309. pcid->subsystem_device);
  310. esas2r_log_dev(ESAS2R_LOG_INFO, &(pcid->dev),
  311. "before pci_enable_device() "
  312. "enable_cnt: %d",
  313. pcid->enable_cnt.counter);
  314. err = pci_enable_device(pcid);
  315. if (err != 0) {
  316. esas2r_log_dev(ESAS2R_LOG_CRIT, &(pcid->dev),
  317. "pci_enable_device() FAIL (%d)",
  318. err);
  319. return -ENODEV;
  320. }
  321. esas2r_log_dev(ESAS2R_LOG_INFO, &(pcid->dev),
  322. "pci_enable_device() OK");
  323. esas2r_log_dev(ESAS2R_LOG_INFO, &(pcid->dev),
  324. "after pci_enable_device() enable_cnt: %d",
  325. pcid->enable_cnt.counter);
  326. host = scsi_host_alloc(&driver_template, host_alloc_size);
  327. if (host == NULL) {
  328. esas2r_log(ESAS2R_LOG_CRIT, "scsi_host_alloc() FAIL");
  329. return -ENODEV;
  330. }
  331. memset(host->hostdata, 0, host_alloc_size);
  332. a = (struct esas2r_adapter *)host->hostdata;
  333. esas2r_log(ESAS2R_LOG_INFO, "scsi_host_alloc() OK host: %p", host);
  334. /* override max LUN and max target id */
  335. host->max_id = ESAS2R_MAX_ID + 1;
  336. host->max_lun = 255;
  337. /* we can handle 16-byte CDbs */
  338. host->max_cmd_len = 16;
  339. host->can_queue = can_queue;
  340. host->cmd_per_lun = cmd_per_lun;
  341. host->this_id = host->max_id + 1;
  342. host->max_channel = 0;
  343. host->unique_id = found_adapters;
  344. host->sg_tablesize = sg_tablesize;
  345. host->max_sectors = esas2r_max_sectors;
  346. /* set to bus master for BIOses that don't do it for us */
  347. esas2r_log(ESAS2R_LOG_INFO, "pci_set_master() called");
  348. pci_set_master(pcid);
  349. if (!esas2r_init_adapter(host, pcid, found_adapters)) {
  350. esas2r_log(ESAS2R_LOG_CRIT,
  351. "unable to initialize device at PCI bus %x:%x",
  352. pcid->bus->number,
  353. pcid->devfn);
  354. esas2r_log_dev(ESAS2R_LOG_INFO, &(host->shost_gendev),
  355. "scsi_host_put() called");
  356. scsi_host_put(host);
  357. return 0;
  358. }
  359. esas2r_log(ESAS2R_LOG_INFO, "pci_set_drvdata(%p, %p) called", pcid,
  360. host->hostdata);
  361. pci_set_drvdata(pcid, host);
  362. esas2r_log(ESAS2R_LOG_INFO, "scsi_add_host() called");
  363. err = scsi_add_host(host, &pcid->dev);
  364. if (err) {
  365. esas2r_log(ESAS2R_LOG_CRIT, "scsi_add_host returned %d", err);
  366. esas2r_log_dev(ESAS2R_LOG_CRIT, &(host->shost_gendev),
  367. "scsi_add_host() FAIL");
  368. esas2r_log_dev(ESAS2R_LOG_INFO, &(host->shost_gendev),
  369. "scsi_host_put() called");
  370. scsi_host_put(host);
  371. esas2r_log_dev(ESAS2R_LOG_INFO, &(host->shost_gendev),
  372. "pci_set_drvdata(%p, NULL) called",
  373. pcid);
  374. pci_set_drvdata(pcid, NULL);
  375. return -ENODEV;
  376. }
  377. esas2r_fw_event_on(a);
  378. esas2r_log_dev(ESAS2R_LOG_INFO, &(host->shost_gendev),
  379. "scsi_scan_host() called");
  380. scsi_scan_host(host);
  381. /* Add sysfs binary files */
  382. if (sysfs_create_bin_file(&host->shost_dev.kobj, &bin_attr_fw))
  383. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  384. "Failed to create sysfs binary file: fw");
  385. else
  386. a->sysfs_fw_created = 1;
  387. if (sysfs_create_bin_file(&host->shost_dev.kobj, &bin_attr_fs))
  388. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  389. "Failed to create sysfs binary file: fs");
  390. else
  391. a->sysfs_fs_created = 1;
  392. if (sysfs_create_bin_file(&host->shost_dev.kobj, &bin_attr_vda))
  393. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  394. "Failed to create sysfs binary file: vda");
  395. else
  396. a->sysfs_vda_created = 1;
  397. if (sysfs_create_bin_file(&host->shost_dev.kobj, &bin_attr_hw))
  398. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  399. "Failed to create sysfs binary file: hw");
  400. else
  401. a->sysfs_hw_created = 1;
  402. if (sysfs_create_bin_file(&host->shost_dev.kobj, &bin_attr_live_nvram))
  403. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  404. "Failed to create sysfs binary file: live_nvram");
  405. else
  406. a->sysfs_live_nvram_created = 1;
  407. if (sysfs_create_bin_file(&host->shost_dev.kobj,
  408. &bin_attr_default_nvram))
  409. esas2r_log_dev(ESAS2R_LOG_WARN, &(host->shost_gendev),
  410. "Failed to create sysfs binary file: default_nvram");
  411. else
  412. a->sysfs_default_nvram_created = 1;
  413. found_adapters++;
  414. return 0;
  415. }
  416. static void esas2r_remove(struct pci_dev *pdev)
  417. {
  418. struct Scsi_Host *host = pci_get_drvdata(pdev);
  419. struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
  420. esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
  421. "esas2r_remove(%p) called; "
  422. "host:%p", pdev,
  423. host);
  424. esas2r_kill_adapter(a->index);
  425. found_adapters--;
  426. }
  427. static int __init esas2r_init(void)
  428. {
  429. int i;
  430. esas2r_log(ESAS2R_LOG_INFO, "%s called", __func__);
  431. /* verify valid parameters */
  432. if (can_queue < 1) {
  433. esas2r_log(ESAS2R_LOG_WARN,
  434. "warning: can_queue must be at least 1, value "
  435. "forced.");
  436. can_queue = 1;
  437. } else if (can_queue > 2048) {
  438. esas2r_log(ESAS2R_LOG_WARN,
  439. "warning: can_queue must be no larger than 2048, "
  440. "value forced.");
  441. can_queue = 2048;
  442. }
  443. if (cmd_per_lun < 1) {
  444. esas2r_log(ESAS2R_LOG_WARN,
  445. "warning: cmd_per_lun must be at least 1, value "
  446. "forced.");
  447. cmd_per_lun = 1;
  448. } else if (cmd_per_lun > 2048) {
  449. esas2r_log(ESAS2R_LOG_WARN,
  450. "warning: cmd_per_lun must be no larger than "
  451. "2048, value forced.");
  452. cmd_per_lun = 2048;
  453. }
  454. if (sg_tablesize < 32) {
  455. esas2r_log(ESAS2R_LOG_WARN,
  456. "warning: sg_tablesize must be at least 32, "
  457. "value forced.");
  458. sg_tablesize = 32;
  459. }
  460. if (esas2r_max_sectors < 1) {
  461. esas2r_log(ESAS2R_LOG_WARN,
  462. "warning: esas2r_max_sectors must be at least "
  463. "1, value forced.");
  464. esas2r_max_sectors = 1;
  465. } else if (esas2r_max_sectors > 0xffff) {
  466. esas2r_log(ESAS2R_LOG_WARN,
  467. "warning: esas2r_max_sectors must be no larger "
  468. "than 0xffff, value forced.");
  469. esas2r_max_sectors = 0xffff;
  470. }
  471. sgl_page_size &= ~(ESAS2R_SGL_ALIGN - 1);
  472. if (sgl_page_size < SGL_PG_SZ_MIN)
  473. sgl_page_size = SGL_PG_SZ_MIN;
  474. else if (sgl_page_size > SGL_PG_SZ_MAX)
  475. sgl_page_size = SGL_PG_SZ_MAX;
  476. if (num_sg_lists < NUM_SGL_MIN)
  477. num_sg_lists = NUM_SGL_MIN;
  478. else if (num_sg_lists > NUM_SGL_MAX)
  479. num_sg_lists = NUM_SGL_MAX;
  480. if (num_requests < NUM_REQ_MIN)
  481. num_requests = NUM_REQ_MIN;
  482. else if (num_requests > NUM_REQ_MAX)
  483. num_requests = NUM_REQ_MAX;
  484. if (num_ae_requests < NUM_AE_MIN)
  485. num_ae_requests = NUM_AE_MIN;
  486. else if (num_ae_requests > NUM_AE_MAX)
  487. num_ae_requests = NUM_AE_MAX;
  488. /* set up other globals */
  489. for (i = 0; i < MAX_ADAPTERS; i++)
  490. esas2r_adapters[i] = NULL;
  491. return pci_register_driver(&esas2r_pci_driver);
  492. }
  493. /* Handle ioctl calls to "/proc/scsi/esas2r/ATTOnode" */
  494. static const struct file_operations esas2r_proc_fops = {
  495. .compat_ioctl = esas2r_proc_ioctl,
  496. .unlocked_ioctl = esas2r_proc_ioctl,
  497. };
  498. static struct Scsi_Host *esas2r_proc_host;
  499. static int esas2r_proc_major;
  500. long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  501. {
  502. return esas2r_ioctl_handler(esas2r_proc_host->hostdata,
  503. (int)cmd, (void __user *)arg);
  504. }
  505. static void __exit esas2r_exit(void)
  506. {
  507. esas2r_log(ESAS2R_LOG_INFO, "%s called", __func__);
  508. if (esas2r_proc_major > 0) {
  509. esas2r_log(ESAS2R_LOG_INFO, "unregister proc");
  510. remove_proc_entry(ATTONODE_NAME,
  511. esas2r_proc_host->hostt->proc_dir);
  512. unregister_chrdev(esas2r_proc_major, ESAS2R_DRVR_NAME);
  513. esas2r_proc_major = 0;
  514. }
  515. esas2r_log(ESAS2R_LOG_INFO, "pci_unregister_driver() called");
  516. pci_unregister_driver(&esas2r_pci_driver);
  517. }
  518. int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh)
  519. {
  520. struct esas2r_adapter *a = (struct esas2r_adapter *)sh->hostdata;
  521. struct esas2r_target *t;
  522. int dev_count = 0;
  523. esas2r_log(ESAS2R_LOG_DEBG, "esas2r_show_info (%p,%d)", m, sh->host_no);
  524. seq_printf(m, ESAS2R_LONGNAME "\n"
  525. "Driver version: "ESAS2R_VERSION_STR "\n"
  526. "Flash version: %s\n"
  527. "Firmware version: %s\n"
  528. "Copyright "ESAS2R_COPYRIGHT_YEARS "\n"
  529. "http://www.attotech.com\n"
  530. "\n",
  531. a->flash_rev,
  532. a->fw_rev[0] ? a->fw_rev : "(none)");
  533. seq_printf(m, "Adapter information:\n"
  534. "--------------------\n"
  535. "Model: %s\n"
  536. "SAS address: %02X%02X%02X%02X:%02X%02X%02X%02X\n",
  537. esas2r_get_model_name(a),
  538. a->nvram->sas_addr[0],
  539. a->nvram->sas_addr[1],
  540. a->nvram->sas_addr[2],
  541. a->nvram->sas_addr[3],
  542. a->nvram->sas_addr[4],
  543. a->nvram->sas_addr[5],
  544. a->nvram->sas_addr[6],
  545. a->nvram->sas_addr[7]);
  546. seq_puts(m, "\n"
  547. "Discovered devices:\n"
  548. "\n"
  549. " # Target ID\n"
  550. "---------------\n");
  551. for (t = a->targetdb; t < a->targetdb_end; t++)
  552. if (t->buffered_target_state == TS_PRESENT) {
  553. seq_printf(m, " %3d %3d\n",
  554. ++dev_count,
  555. (u16)(uintptr_t)(t - a->targetdb));
  556. }
  557. if (dev_count == 0)
  558. seq_puts(m, "none\n");
  559. seq_putc(m, '\n');
  560. return 0;
  561. }
  562. const char *esas2r_info(struct Scsi_Host *sh)
  563. {
  564. struct esas2r_adapter *a = (struct esas2r_adapter *)sh->hostdata;
  565. static char esas2r_info_str[512];
  566. esas2r_log_dev(ESAS2R_LOG_INFO, &(sh->shost_gendev),
  567. "esas2r_info() called");
  568. /*
  569. * if we haven't done so already, register as a char driver
  570. * and stick a node under "/proc/scsi/esas2r/ATTOnode"
  571. */
  572. if (esas2r_proc_major <= 0) {
  573. esas2r_proc_host = sh;
  574. esas2r_proc_major = register_chrdev(0, ESAS2R_DRVR_NAME,
  575. &esas2r_proc_fops);
  576. esas2r_log_dev(ESAS2R_LOG_DEBG, &(sh->shost_gendev),
  577. "register_chrdev (major %d)",
  578. esas2r_proc_major);
  579. if (esas2r_proc_major > 0) {
  580. struct proc_dir_entry *pde;
  581. pde = proc_create(ATTONODE_NAME, 0,
  582. sh->hostt->proc_dir,
  583. &esas2r_proc_fops);
  584. if (!pde) {
  585. esas2r_log_dev(ESAS2R_LOG_WARN,
  586. &(sh->shost_gendev),
  587. "failed to create_proc_entry");
  588. esas2r_proc_major = -1;
  589. }
  590. }
  591. }
  592. sprintf(esas2r_info_str,
  593. ESAS2R_LONGNAME " (bus 0x%02X, device 0x%02X, IRQ 0x%02X)"
  594. " driver version: "ESAS2R_VERSION_STR " firmware version: "
  595. "%s\n",
  596. a->pcid->bus->number, a->pcid->devfn, a->pcid->irq,
  597. a->fw_rev[0] ? a->fw_rev : "(none)");
  598. return esas2r_info_str;
  599. }
  600. /* Callback for building a request scatter/gather list */
  601. static u32 get_physaddr_from_sgc(struct esas2r_sg_context *sgc, u64 *addr)
  602. {
  603. u32 len;
  604. if (likely(sgc->cur_offset == sgc->exp_offset)) {
  605. /*
  606. * the normal case: caller used all bytes from previous call, so
  607. * expected offset is the same as the current offset.
  608. */
  609. if (sgc->sgel_count < sgc->num_sgel) {
  610. /* retrieve next segment, except for first time */
  611. if (sgc->exp_offset > (u8 *)0) {
  612. /* advance current segment */
  613. sgc->cur_sgel = sg_next(sgc->cur_sgel);
  614. ++(sgc->sgel_count);
  615. }
  616. len = sg_dma_len(sgc->cur_sgel);
  617. (*addr) = sg_dma_address(sgc->cur_sgel);
  618. /* save the total # bytes returned to caller so far */
  619. sgc->exp_offset += len;
  620. } else {
  621. len = 0;
  622. }
  623. } else if (sgc->cur_offset < sgc->exp_offset) {
  624. /*
  625. * caller did not use all bytes from previous call. need to
  626. * compute the address based on current segment.
  627. */
  628. len = sg_dma_len(sgc->cur_sgel);
  629. (*addr) = sg_dma_address(sgc->cur_sgel);
  630. sgc->exp_offset -= len;
  631. /* calculate PA based on prev segment address and offsets */
  632. *addr = *addr +
  633. (sgc->cur_offset - sgc->exp_offset);
  634. sgc->exp_offset += len;
  635. /* re-calculate length based on offset */
  636. len = lower_32_bits(
  637. sgc->exp_offset - sgc->cur_offset);
  638. } else { /* if ( sgc->cur_offset > sgc->exp_offset ) */
  639. /*
  640. * we don't expect the caller to skip ahead.
  641. * cur_offset will never exceed the len we return
  642. */
  643. len = 0;
  644. }
  645. return len;
  646. }
  647. int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  648. {
  649. struct esas2r_adapter *a =
  650. (struct esas2r_adapter *)cmd->device->host->hostdata;
  651. struct esas2r_request *rq;
  652. struct esas2r_sg_context sgc;
  653. unsigned bufflen;
  654. /* Assume success, if it fails we will fix the result later. */
  655. cmd->result = DID_OK << 16;
  656. if (unlikely(test_bit(AF_DEGRADED_MODE, &a->flags))) {
  657. cmd->result = DID_NO_CONNECT << 16;
  658. cmd->scsi_done(cmd);
  659. return 0;
  660. }
  661. rq = esas2r_alloc_request(a);
  662. if (unlikely(rq == NULL)) {
  663. esas2r_debug("esas2r_alloc_request failed");
  664. return SCSI_MLQUEUE_HOST_BUSY;
  665. }
  666. rq->cmd = cmd;
  667. bufflen = scsi_bufflen(cmd);
  668. if (likely(bufflen != 0)) {
  669. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  670. rq->vrq->scsi.flags |= cpu_to_le32(FCP_CMND_WRD);
  671. else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
  672. rq->vrq->scsi.flags |= cpu_to_le32(FCP_CMND_RDD);
  673. }
  674. memcpy(rq->vrq->scsi.cdb, cmd->cmnd, cmd->cmd_len);
  675. rq->vrq->scsi.length = cpu_to_le32(bufflen);
  676. rq->target_id = cmd->device->id;
  677. rq->vrq->scsi.flags |= cpu_to_le32(cmd->device->lun);
  678. rq->sense_buf = cmd->sense_buffer;
  679. rq->sense_len = SCSI_SENSE_BUFFERSIZE;
  680. esas2r_sgc_init(&sgc, a, rq, NULL);
  681. sgc.length = bufflen;
  682. sgc.cur_offset = NULL;
  683. sgc.cur_sgel = scsi_sglist(cmd);
  684. sgc.exp_offset = NULL;
  685. sgc.num_sgel = scsi_dma_map(cmd);
  686. sgc.sgel_count = 0;
  687. if (unlikely(sgc.num_sgel < 0)) {
  688. esas2r_free_request(a, rq);
  689. return SCSI_MLQUEUE_HOST_BUSY;
  690. }
  691. sgc.get_phys_addr = (PGETPHYSADDR)get_physaddr_from_sgc;
  692. if (unlikely(!esas2r_build_sg_list(a, rq, &sgc))) {
  693. scsi_dma_unmap(cmd);
  694. esas2r_free_request(a, rq);
  695. return SCSI_MLQUEUE_HOST_BUSY;
  696. }
  697. esas2r_debug("start request %p to %d:%d\n", rq, (int)cmd->device->id,
  698. (int)cmd->device->lun);
  699. esas2r_start_request(a, rq);
  700. return 0;
  701. }
  702. static void complete_task_management_request(struct esas2r_adapter *a,
  703. struct esas2r_request *rq)
  704. {
  705. (*rq->task_management_status_ptr) = rq->req_stat;
  706. esas2r_free_request(a, rq);
  707. }
  708. /**
  709. * Searches the specified queue for the specified queue for the command
  710. * to abort.
  711. *
  712. * @param [in] a
  713. * @param [in] abort_request
  714. * @param [in] cmd
  715. * t
  716. * @return 0 on failure, 1 if command was not found, 2 if command was found
  717. */
  718. static int esas2r_check_active_queue(struct esas2r_adapter *a,
  719. struct esas2r_request **abort_request,
  720. struct scsi_cmnd *cmd,
  721. struct list_head *queue)
  722. {
  723. bool found = false;
  724. struct esas2r_request *ar = *abort_request;
  725. struct esas2r_request *rq;
  726. struct list_head *element, *next;
  727. list_for_each_safe(element, next, queue) {
  728. rq = list_entry(element, struct esas2r_request, req_list);
  729. if (rq->cmd == cmd) {
  730. /* Found the request. See what to do with it. */
  731. if (queue == &a->active_list) {
  732. /*
  733. * We are searching the active queue, which
  734. * means that we need to send an abort request
  735. * to the firmware.
  736. */
  737. ar = esas2r_alloc_request(a);
  738. if (ar == NULL) {
  739. esas2r_log_dev(ESAS2R_LOG_WARN,
  740. &(a->host->shost_gendev),
  741. "unable to allocate an abort request for cmd %p",
  742. cmd);
  743. return 0; /* Failure */
  744. }
  745. /*
  746. * Task management request must be formatted
  747. * with a lock held.
  748. */
  749. ar->sense_len = 0;
  750. ar->vrq->scsi.length = 0;
  751. ar->target_id = rq->target_id;
  752. ar->vrq->scsi.flags |= cpu_to_le32(
  753. (u8)le32_to_cpu(rq->vrq->scsi.flags));
  754. memset(ar->vrq->scsi.cdb, 0,
  755. sizeof(ar->vrq->scsi.cdb));
  756. ar->vrq->scsi.flags |= cpu_to_le32(
  757. FCP_CMND_TRM);
  758. ar->vrq->scsi.u.abort_handle =
  759. rq->vrq->scsi.handle;
  760. } else {
  761. /*
  762. * The request is pending but not active on
  763. * the firmware. Just free it now and we'll
  764. * report the successful abort below.
  765. */
  766. list_del_init(&rq->req_list);
  767. esas2r_free_request(a, rq);
  768. }
  769. found = true;
  770. break;
  771. }
  772. }
  773. if (!found)
  774. return 1; /* Not found */
  775. return 2; /* found */
  776. }
  777. int esas2r_eh_abort(struct scsi_cmnd *cmd)
  778. {
  779. struct esas2r_adapter *a =
  780. (struct esas2r_adapter *)cmd->device->host->hostdata;
  781. struct esas2r_request *abort_request = NULL;
  782. unsigned long flags;
  783. struct list_head *queue;
  784. int result;
  785. esas2r_log(ESAS2R_LOG_INFO, "eh_abort (%p)", cmd);
  786. if (test_bit(AF_DEGRADED_MODE, &a->flags)) {
  787. cmd->result = DID_ABORT << 16;
  788. scsi_set_resid(cmd, 0);
  789. cmd->scsi_done(cmd);
  790. return SUCCESS;
  791. }
  792. spin_lock_irqsave(&a->queue_lock, flags);
  793. /*
  794. * Run through the defer and active queues looking for the request
  795. * to abort.
  796. */
  797. queue = &a->defer_list;
  798. check_active_queue:
  799. result = esas2r_check_active_queue(a, &abort_request, cmd, queue);
  800. if (!result) {
  801. spin_unlock_irqrestore(&a->queue_lock, flags);
  802. return FAILED;
  803. } else if (result == 2 && (queue == &a->defer_list)) {
  804. queue = &a->active_list;
  805. goto check_active_queue;
  806. }
  807. spin_unlock_irqrestore(&a->queue_lock, flags);
  808. if (abort_request) {
  809. u8 task_management_status = RS_PENDING;
  810. /*
  811. * the request is already active, so we need to tell
  812. * the firmware to abort it and wait for the response.
  813. */
  814. abort_request->comp_cb = complete_task_management_request;
  815. abort_request->task_management_status_ptr =
  816. &task_management_status;
  817. esas2r_start_request(a, abort_request);
  818. if (atomic_read(&a->disable_cnt) == 0)
  819. esas2r_do_deferred_processes(a);
  820. while (task_management_status == RS_PENDING)
  821. msleep(10);
  822. /*
  823. * Once we get here, the original request will have been
  824. * completed by the firmware and the abort request will have
  825. * been cleaned up. we're done!
  826. */
  827. return SUCCESS;
  828. }
  829. /*
  830. * If we get here, either we found the inactive request and
  831. * freed it, or we didn't find it at all. Either way, success!
  832. */
  833. cmd->result = DID_ABORT << 16;
  834. scsi_set_resid(cmd, 0);
  835. cmd->scsi_done(cmd);
  836. return SUCCESS;
  837. }
  838. static int esas2r_host_bus_reset(struct scsi_cmnd *cmd, bool host_reset)
  839. {
  840. struct esas2r_adapter *a =
  841. (struct esas2r_adapter *)cmd->device->host->hostdata;
  842. if (test_bit(AF_DEGRADED_MODE, &a->flags))
  843. return FAILED;
  844. if (host_reset)
  845. esas2r_reset_adapter(a);
  846. else
  847. esas2r_reset_bus(a);
  848. /* above call sets the AF_OS_RESET flag. wait for it to clear. */
  849. while (test_bit(AF_OS_RESET, &a->flags)) {
  850. msleep(10);
  851. if (test_bit(AF_DEGRADED_MODE, &a->flags))
  852. return FAILED;
  853. }
  854. if (test_bit(AF_DEGRADED_MODE, &a->flags))
  855. return FAILED;
  856. return SUCCESS;
  857. }
  858. int esas2r_host_reset(struct scsi_cmnd *cmd)
  859. {
  860. esas2r_log(ESAS2R_LOG_INFO, "host_reset (%p)", cmd);
  861. return esas2r_host_bus_reset(cmd, true);
  862. }
  863. int esas2r_bus_reset(struct scsi_cmnd *cmd)
  864. {
  865. esas2r_log(ESAS2R_LOG_INFO, "bus_reset (%p)", cmd);
  866. return esas2r_host_bus_reset(cmd, false);
  867. }
  868. static int esas2r_dev_targ_reset(struct scsi_cmnd *cmd, bool target_reset)
  869. {
  870. struct esas2r_adapter *a =
  871. (struct esas2r_adapter *)cmd->device->host->hostdata;
  872. struct esas2r_request *rq;
  873. u8 task_management_status = RS_PENDING;
  874. bool completed;
  875. if (test_bit(AF_DEGRADED_MODE, &a->flags))
  876. return FAILED;
  877. retry:
  878. rq = esas2r_alloc_request(a);
  879. if (rq == NULL) {
  880. if (target_reset) {
  881. esas2r_log(ESAS2R_LOG_CRIT,
  882. "unable to allocate a request for a "
  883. "target reset (%d)!",
  884. cmd->device->id);
  885. } else {
  886. esas2r_log(ESAS2R_LOG_CRIT,
  887. "unable to allocate a request for a "
  888. "device reset (%d:%llu)!",
  889. cmd->device->id,
  890. cmd->device->lun);
  891. }
  892. return FAILED;
  893. }
  894. rq->target_id = cmd->device->id;
  895. rq->vrq->scsi.flags |= cpu_to_le32(cmd->device->lun);
  896. rq->req_stat = RS_PENDING;
  897. rq->comp_cb = complete_task_management_request;
  898. rq->task_management_status_ptr = &task_management_status;
  899. if (target_reset) {
  900. esas2r_debug("issuing target reset (%p) to id %d", rq,
  901. cmd->device->id);
  902. completed = esas2r_send_task_mgmt(a, rq, 0x20);
  903. } else {
  904. esas2r_debug("issuing device reset (%p) to id %d lun %d", rq,
  905. cmd->device->id, cmd->device->lun);
  906. completed = esas2r_send_task_mgmt(a, rq, 0x10);
  907. }
  908. if (completed) {
  909. /* Task management cmd completed right away, need to free it. */
  910. esas2r_free_request(a, rq);
  911. } else {
  912. /*
  913. * Wait for firmware to complete the request. Completion
  914. * callback will free it.
  915. */
  916. while (task_management_status == RS_PENDING)
  917. msleep(10);
  918. }
  919. if (test_bit(AF_DEGRADED_MODE, &a->flags))
  920. return FAILED;
  921. if (task_management_status == RS_BUSY) {
  922. /*
  923. * Busy, probably because we are flashing. Wait a bit and
  924. * try again.
  925. */
  926. msleep(100);
  927. goto retry;
  928. }
  929. return SUCCESS;
  930. }
  931. int esas2r_device_reset(struct scsi_cmnd *cmd)
  932. {
  933. esas2r_log(ESAS2R_LOG_INFO, "device_reset (%p)", cmd);
  934. return esas2r_dev_targ_reset(cmd, false);
  935. }
  936. int esas2r_target_reset(struct scsi_cmnd *cmd)
  937. {
  938. esas2r_log(ESAS2R_LOG_INFO, "target_reset (%p)", cmd);
  939. return esas2r_dev_targ_reset(cmd, true);
  940. }
  941. void esas2r_log_request_failure(struct esas2r_adapter *a,
  942. struct esas2r_request *rq)
  943. {
  944. u8 reqstatus = rq->req_stat;
  945. if (reqstatus == RS_SUCCESS)
  946. return;
  947. if (rq->vrq->scsi.function == VDA_FUNC_SCSI) {
  948. if (reqstatus == RS_SCSI_ERROR) {
  949. if (rq->func_rsp.scsi_rsp.sense_len >= 13) {
  950. esas2r_log(ESAS2R_LOG_WARN,
  951. "request failure - SCSI error %x ASC:%x ASCQ:%x CDB:%x",
  952. rq->sense_buf[2], rq->sense_buf[12],
  953. rq->sense_buf[13],
  954. rq->vrq->scsi.cdb[0]);
  955. } else {
  956. esas2r_log(ESAS2R_LOG_WARN,
  957. "request failure - SCSI error CDB:%x\n",
  958. rq->vrq->scsi.cdb[0]);
  959. }
  960. } else if ((rq->vrq->scsi.cdb[0] != INQUIRY
  961. && rq->vrq->scsi.cdb[0] != REPORT_LUNS)
  962. || (reqstatus != RS_SEL
  963. && reqstatus != RS_SEL2)) {
  964. if ((reqstatus == RS_UNDERRUN) &&
  965. (rq->vrq->scsi.cdb[0] == INQUIRY)) {
  966. /* Don't log inquiry underruns */
  967. } else {
  968. esas2r_log(ESAS2R_LOG_WARN,
  969. "request failure - cdb:%x reqstatus:%d target:%d",
  970. rq->vrq->scsi.cdb[0], reqstatus,
  971. rq->target_id);
  972. }
  973. }
  974. }
  975. }
  976. void esas2r_wait_request(struct esas2r_adapter *a, struct esas2r_request *rq)
  977. {
  978. u32 starttime;
  979. u32 timeout;
  980. starttime = jiffies_to_msecs(jiffies);
  981. timeout = rq->timeout ? rq->timeout : 5000;
  982. while (true) {
  983. esas2r_polled_interrupt(a);
  984. if (rq->req_stat != RS_STARTED)
  985. break;
  986. schedule_timeout_interruptible(msecs_to_jiffies(100));
  987. if ((jiffies_to_msecs(jiffies) - starttime) > timeout) {
  988. esas2r_hdebug("request TMO");
  989. esas2r_bugon();
  990. rq->req_stat = RS_TIMEOUT;
  991. esas2r_local_reset_adapter(a);
  992. return;
  993. }
  994. }
  995. }
  996. u32 esas2r_map_data_window(struct esas2r_adapter *a, u32 addr_lo)
  997. {
  998. u32 offset = addr_lo & (MW_DATA_WINDOW_SIZE - 1);
  999. u32 base = addr_lo & -(signed int)MW_DATA_WINDOW_SIZE;
  1000. if (a->window_base != base) {
  1001. esas2r_write_register_dword(a, MVR_PCI_WIN1_REMAP,
  1002. base | MVRPW1R_ENABLE);
  1003. esas2r_flush_register_dword(a, MVR_PCI_WIN1_REMAP);
  1004. a->window_base = base;
  1005. }
  1006. return offset;
  1007. }
  1008. /* Read a block of data from chip memory */
  1009. bool esas2r_read_mem_block(struct esas2r_adapter *a,
  1010. void *to,
  1011. u32 from,
  1012. u32 size)
  1013. {
  1014. u8 *end = (u8 *)to;
  1015. while (size) {
  1016. u32 len;
  1017. u32 offset;
  1018. u32 iatvr;
  1019. iatvr = (from & -(signed int)MW_DATA_WINDOW_SIZE);
  1020. esas2r_map_data_window(a, iatvr);
  1021. offset = from & (MW_DATA_WINDOW_SIZE - 1);
  1022. len = size;
  1023. if (len > MW_DATA_WINDOW_SIZE - offset)
  1024. len = MW_DATA_WINDOW_SIZE - offset;
  1025. from += len;
  1026. size -= len;
  1027. while (len--) {
  1028. *end++ = esas2r_read_data_byte(a, offset);
  1029. offset++;
  1030. }
  1031. }
  1032. return true;
  1033. }
  1034. void esas2r_nuxi_mgt_data(u8 function, void *data)
  1035. {
  1036. struct atto_vda_grp_info *g;
  1037. struct atto_vda_devinfo *d;
  1038. struct atto_vdapart_info *p;
  1039. struct atto_vda_dh_info *h;
  1040. struct atto_vda_metrics_info *m;
  1041. struct atto_vda_schedule_info *s;
  1042. struct atto_vda_buzzer_info *b;
  1043. u8 i;
  1044. switch (function) {
  1045. case VDAMGT_BUZZER_INFO:
  1046. case VDAMGT_BUZZER_SET:
  1047. b = (struct atto_vda_buzzer_info *)data;
  1048. b->duration = le32_to_cpu(b->duration);
  1049. break;
  1050. case VDAMGT_SCHEDULE_INFO:
  1051. case VDAMGT_SCHEDULE_EVENT:
  1052. s = (struct atto_vda_schedule_info *)data;
  1053. s->id = le32_to_cpu(s->id);
  1054. break;
  1055. case VDAMGT_DEV_INFO:
  1056. case VDAMGT_DEV_CLEAN:
  1057. case VDAMGT_DEV_PT_INFO:
  1058. case VDAMGT_DEV_FEATURES:
  1059. case VDAMGT_DEV_PT_FEATURES:
  1060. case VDAMGT_DEV_OPERATION:
  1061. d = (struct atto_vda_devinfo *)data;
  1062. d->capacity = le64_to_cpu(d->capacity);
  1063. d->block_size = le32_to_cpu(d->block_size);
  1064. d->ses_dev_index = le16_to_cpu(d->ses_dev_index);
  1065. d->target_id = le16_to_cpu(d->target_id);
  1066. d->lun = le16_to_cpu(d->lun);
  1067. d->features = le16_to_cpu(d->features);
  1068. break;
  1069. case VDAMGT_GRP_INFO:
  1070. case VDAMGT_GRP_CREATE:
  1071. case VDAMGT_GRP_DELETE:
  1072. case VDAMGT_ADD_STORAGE:
  1073. case VDAMGT_MEMBER_ADD:
  1074. case VDAMGT_GRP_COMMIT:
  1075. case VDAMGT_GRP_REBUILD:
  1076. case VDAMGT_GRP_COMMIT_INIT:
  1077. case VDAMGT_QUICK_RAID:
  1078. case VDAMGT_GRP_FEATURES:
  1079. case VDAMGT_GRP_COMMIT_INIT_AUTOMAP:
  1080. case VDAMGT_QUICK_RAID_INIT_AUTOMAP:
  1081. case VDAMGT_SPARE_LIST:
  1082. case VDAMGT_SPARE_ADD:
  1083. case VDAMGT_SPARE_REMOVE:
  1084. case VDAMGT_LOCAL_SPARE_ADD:
  1085. case VDAMGT_GRP_OPERATION:
  1086. g = (struct atto_vda_grp_info *)data;
  1087. g->capacity = le64_to_cpu(g->capacity);
  1088. g->block_size = le32_to_cpu(g->block_size);
  1089. g->interleave = le32_to_cpu(g->interleave);
  1090. g->features = le16_to_cpu(g->features);
  1091. for (i = 0; i < 32; i++)
  1092. g->members[i] = le16_to_cpu(g->members[i]);
  1093. break;
  1094. case VDAMGT_PART_INFO:
  1095. case VDAMGT_PART_MAP:
  1096. case VDAMGT_PART_UNMAP:
  1097. case VDAMGT_PART_AUTOMAP:
  1098. case VDAMGT_PART_SPLIT:
  1099. case VDAMGT_PART_MERGE:
  1100. p = (struct atto_vdapart_info *)data;
  1101. p->part_size = le64_to_cpu(p->part_size);
  1102. p->start_lba = le32_to_cpu(p->start_lba);
  1103. p->block_size = le32_to_cpu(p->block_size);
  1104. p->target_id = le16_to_cpu(p->target_id);
  1105. break;
  1106. case VDAMGT_DEV_HEALTH_REQ:
  1107. h = (struct atto_vda_dh_info *)data;
  1108. h->med_defect_cnt = le32_to_cpu(h->med_defect_cnt);
  1109. h->info_exc_cnt = le32_to_cpu(h->info_exc_cnt);
  1110. break;
  1111. case VDAMGT_DEV_METRICS:
  1112. m = (struct atto_vda_metrics_info *)data;
  1113. for (i = 0; i < 32; i++)
  1114. m->dev_indexes[i] = le16_to_cpu(m->dev_indexes[i]);
  1115. break;
  1116. default:
  1117. break;
  1118. }
  1119. }
  1120. void esas2r_nuxi_cfg_data(u8 function, void *data)
  1121. {
  1122. struct atto_vda_cfg_init *ci;
  1123. switch (function) {
  1124. case VDA_CFG_INIT:
  1125. case VDA_CFG_GET_INIT:
  1126. case VDA_CFG_GET_INIT2:
  1127. ci = (struct atto_vda_cfg_init *)data;
  1128. ci->date_time.year = le16_to_cpu(ci->date_time.year);
  1129. ci->sgl_page_size = le32_to_cpu(ci->sgl_page_size);
  1130. ci->vda_version = le32_to_cpu(ci->vda_version);
  1131. ci->epoch_time = le32_to_cpu(ci->epoch_time);
  1132. ci->ioctl_tunnel = le32_to_cpu(ci->ioctl_tunnel);
  1133. ci->num_targets_backend = le32_to_cpu(ci->num_targets_backend);
  1134. break;
  1135. default:
  1136. break;
  1137. }
  1138. }
  1139. void esas2r_nuxi_ae_data(union atto_vda_ae *ae)
  1140. {
  1141. struct atto_vda_ae_raid *r = &ae->raid;
  1142. struct atto_vda_ae_lu *l = &ae->lu;
  1143. switch (ae->hdr.bytype) {
  1144. case VDAAE_HDR_TYPE_RAID:
  1145. r->dwflags = le32_to_cpu(r->dwflags);
  1146. break;
  1147. case VDAAE_HDR_TYPE_LU:
  1148. l->dwevent = le32_to_cpu(l->dwevent);
  1149. l->wphys_target_id = le16_to_cpu(l->wphys_target_id);
  1150. l->id.tgtlun.wtarget_id = le16_to_cpu(l->id.tgtlun.wtarget_id);
  1151. if (l->hdr.bylength >= offsetof(struct atto_vda_ae_lu, id)
  1152. + sizeof(struct atto_vda_ae_lu_tgt_lun_raid)) {
  1153. l->id.tgtlun_raid.dwinterleave
  1154. = le32_to_cpu(l->id.tgtlun_raid.dwinterleave);
  1155. l->id.tgtlun_raid.dwblock_size
  1156. = le32_to_cpu(l->id.tgtlun_raid.dwblock_size);
  1157. }
  1158. break;
  1159. case VDAAE_HDR_TYPE_DISK:
  1160. default:
  1161. break;
  1162. }
  1163. }
  1164. void esas2r_free_request(struct esas2r_adapter *a, struct esas2r_request *rq)
  1165. {
  1166. unsigned long flags;
  1167. esas2r_rq_destroy_request(rq, a);
  1168. spin_lock_irqsave(&a->request_lock, flags);
  1169. list_add(&rq->comp_list, &a->avail_request);
  1170. spin_unlock_irqrestore(&a->request_lock, flags);
  1171. }
  1172. struct esas2r_request *esas2r_alloc_request(struct esas2r_adapter *a)
  1173. {
  1174. struct esas2r_request *rq;
  1175. unsigned long flags;
  1176. spin_lock_irqsave(&a->request_lock, flags);
  1177. if (unlikely(list_empty(&a->avail_request))) {
  1178. spin_unlock_irqrestore(&a->request_lock, flags);
  1179. return NULL;
  1180. }
  1181. rq = list_first_entry(&a->avail_request, struct esas2r_request,
  1182. comp_list);
  1183. list_del(&rq->comp_list);
  1184. spin_unlock_irqrestore(&a->request_lock, flags);
  1185. esas2r_rq_init_request(rq, a);
  1186. return rq;
  1187. }
  1188. void esas2r_complete_request_cb(struct esas2r_adapter *a,
  1189. struct esas2r_request *rq)
  1190. {
  1191. esas2r_debug("completing request %p\n", rq);
  1192. scsi_dma_unmap(rq->cmd);
  1193. if (unlikely(rq->req_stat != RS_SUCCESS)) {
  1194. esas2r_debug("[%x STATUS %x:%x (%x)]", rq->target_id,
  1195. rq->req_stat,
  1196. rq->func_rsp.scsi_rsp.scsi_stat,
  1197. rq->cmd);
  1198. rq->cmd->result =
  1199. ((esas2r_req_status_to_error(rq->req_stat) << 16)
  1200. | (rq->func_rsp.scsi_rsp.scsi_stat & STATUS_MASK));
  1201. if (rq->req_stat == RS_UNDERRUN)
  1202. scsi_set_resid(rq->cmd,
  1203. le32_to_cpu(rq->func_rsp.scsi_rsp.
  1204. residual_length));
  1205. else
  1206. scsi_set_resid(rq->cmd, 0);
  1207. }
  1208. rq->cmd->scsi_done(rq->cmd);
  1209. esas2r_free_request(a, rq);
  1210. }
  1211. /* Run tasklet to handle stuff outside of interrupt context. */
  1212. void esas2r_adapter_tasklet(unsigned long context)
  1213. {
  1214. struct esas2r_adapter *a = (struct esas2r_adapter *)context;
  1215. if (unlikely(test_bit(AF2_TIMER_TICK, &a->flags2))) {
  1216. clear_bit(AF2_TIMER_TICK, &a->flags2);
  1217. esas2r_timer_tick(a);
  1218. }
  1219. if (likely(test_bit(AF2_INT_PENDING, &a->flags2))) {
  1220. clear_bit(AF2_INT_PENDING, &a->flags2);
  1221. esas2r_adapter_interrupt(a);
  1222. }
  1223. if (esas2r_is_tasklet_pending(a))
  1224. esas2r_do_tasklet_tasks(a);
  1225. if (esas2r_is_tasklet_pending(a)
  1226. || (test_bit(AF2_INT_PENDING, &a->flags2))
  1227. || (test_bit(AF2_TIMER_TICK, &a->flags2))) {
  1228. clear_bit(AF_TASKLET_SCHEDULED, &a->flags);
  1229. esas2r_schedule_tasklet(a);
  1230. } else {
  1231. clear_bit(AF_TASKLET_SCHEDULED, &a->flags);
  1232. }
  1233. }
  1234. static void esas2r_timer_callback(struct timer_list *t);
  1235. void esas2r_kickoff_timer(struct esas2r_adapter *a)
  1236. {
  1237. timer_setup(&a->timer, esas2r_timer_callback, 0);
  1238. a->timer.expires = jiffies +
  1239. msecs_to_jiffies(100);
  1240. add_timer(&a->timer);
  1241. }
  1242. static void esas2r_timer_callback(struct timer_list *t)
  1243. {
  1244. struct esas2r_adapter *a = from_timer(a, t, timer);
  1245. set_bit(AF2_TIMER_TICK, &a->flags2);
  1246. esas2r_schedule_tasklet(a);
  1247. esas2r_kickoff_timer(a);
  1248. }
  1249. /*
  1250. * Firmware events need to be handled outside of interrupt context
  1251. * so we schedule a delayed_work to handle them.
  1252. */
  1253. static void
  1254. esas2r_free_fw_event(struct esas2r_fw_event_work *fw_event)
  1255. {
  1256. unsigned long flags;
  1257. struct esas2r_adapter *a = fw_event->a;
  1258. spin_lock_irqsave(&a->fw_event_lock, flags);
  1259. list_del(&fw_event->list);
  1260. kfree(fw_event);
  1261. spin_unlock_irqrestore(&a->fw_event_lock, flags);
  1262. }
  1263. void
  1264. esas2r_fw_event_off(struct esas2r_adapter *a)
  1265. {
  1266. unsigned long flags;
  1267. spin_lock_irqsave(&a->fw_event_lock, flags);
  1268. a->fw_events_off = 1;
  1269. spin_unlock_irqrestore(&a->fw_event_lock, flags);
  1270. }
  1271. void
  1272. esas2r_fw_event_on(struct esas2r_adapter *a)
  1273. {
  1274. unsigned long flags;
  1275. spin_lock_irqsave(&a->fw_event_lock, flags);
  1276. a->fw_events_off = 0;
  1277. spin_unlock_irqrestore(&a->fw_event_lock, flags);
  1278. }
  1279. static void esas2r_add_device(struct esas2r_adapter *a, u16 target_id)
  1280. {
  1281. int ret;
  1282. struct scsi_device *scsi_dev;
  1283. scsi_dev = scsi_device_lookup(a->host, 0, target_id, 0);
  1284. if (scsi_dev) {
  1285. esas2r_log_dev(
  1286. ESAS2R_LOG_WARN,
  1287. &(scsi_dev->
  1288. sdev_gendev),
  1289. "scsi device already exists at id %d", target_id);
  1290. scsi_device_put(scsi_dev);
  1291. } else {
  1292. esas2r_log_dev(
  1293. ESAS2R_LOG_INFO,
  1294. &(a->host->
  1295. shost_gendev),
  1296. "scsi_add_device() called for 0:%d:0",
  1297. target_id);
  1298. ret = scsi_add_device(a->host, 0, target_id, 0);
  1299. if (ret) {
  1300. esas2r_log_dev(
  1301. ESAS2R_LOG_CRIT,
  1302. &(a->host->
  1303. shost_gendev),
  1304. "scsi_add_device failed with %d for id %d",
  1305. ret, target_id);
  1306. }
  1307. }
  1308. }
  1309. static void esas2r_remove_device(struct esas2r_adapter *a, u16 target_id)
  1310. {
  1311. struct scsi_device *scsi_dev;
  1312. scsi_dev = scsi_device_lookup(a->host, 0, target_id, 0);
  1313. if (scsi_dev) {
  1314. scsi_device_set_state(scsi_dev, SDEV_OFFLINE);
  1315. esas2r_log_dev(
  1316. ESAS2R_LOG_INFO,
  1317. &(scsi_dev->
  1318. sdev_gendev),
  1319. "scsi_remove_device() called for 0:%d:0",
  1320. target_id);
  1321. scsi_remove_device(scsi_dev);
  1322. esas2r_log_dev(
  1323. ESAS2R_LOG_INFO,
  1324. &(scsi_dev->
  1325. sdev_gendev),
  1326. "scsi_device_put() called");
  1327. scsi_device_put(scsi_dev);
  1328. } else {
  1329. esas2r_log_dev(
  1330. ESAS2R_LOG_WARN,
  1331. &(a->host->shost_gendev),
  1332. "no target found at id %d",
  1333. target_id);
  1334. }
  1335. }
  1336. /*
  1337. * Sends a firmware asynchronous event to anyone who happens to be
  1338. * listening on the defined ATTO VDA event ports.
  1339. */
  1340. static void esas2r_send_ae_event(struct esas2r_fw_event_work *fw_event)
  1341. {
  1342. struct esas2r_vda_ae *ae = (struct esas2r_vda_ae *)fw_event->data;
  1343. char *type;
  1344. switch (ae->vda_ae.hdr.bytype) {
  1345. case VDAAE_HDR_TYPE_RAID:
  1346. type = "RAID group state change";
  1347. break;
  1348. case VDAAE_HDR_TYPE_LU:
  1349. type = "Mapped destination LU change";
  1350. break;
  1351. case VDAAE_HDR_TYPE_DISK:
  1352. type = "Physical disk inventory change";
  1353. break;
  1354. case VDAAE_HDR_TYPE_RESET:
  1355. type = "Firmware reset";
  1356. break;
  1357. case VDAAE_HDR_TYPE_LOG_INFO:
  1358. type = "Event Log message (INFO level)";
  1359. break;
  1360. case VDAAE_HDR_TYPE_LOG_WARN:
  1361. type = "Event Log message (WARN level)";
  1362. break;
  1363. case VDAAE_HDR_TYPE_LOG_CRIT:
  1364. type = "Event Log message (CRIT level)";
  1365. break;
  1366. case VDAAE_HDR_TYPE_LOG_FAIL:
  1367. type = "Event Log message (FAIL level)";
  1368. break;
  1369. case VDAAE_HDR_TYPE_NVC:
  1370. type = "NVCache change";
  1371. break;
  1372. case VDAAE_HDR_TYPE_TLG_INFO:
  1373. type = "Time stamped log message (INFO level)";
  1374. break;
  1375. case VDAAE_HDR_TYPE_TLG_WARN:
  1376. type = "Time stamped log message (WARN level)";
  1377. break;
  1378. case VDAAE_HDR_TYPE_TLG_CRIT:
  1379. type = "Time stamped log message (CRIT level)";
  1380. break;
  1381. case VDAAE_HDR_TYPE_PWRMGT:
  1382. type = "Power management";
  1383. break;
  1384. case VDAAE_HDR_TYPE_MUTE:
  1385. type = "Mute button pressed";
  1386. break;
  1387. case VDAAE_HDR_TYPE_DEV:
  1388. type = "Device attribute change";
  1389. break;
  1390. default:
  1391. type = "Unknown";
  1392. break;
  1393. }
  1394. esas2r_log(ESAS2R_LOG_WARN,
  1395. "An async event of type \"%s\" was received from the firmware. The event contents are:",
  1396. type);
  1397. esas2r_log_hexdump(ESAS2R_LOG_WARN, &ae->vda_ae,
  1398. ae->vda_ae.hdr.bylength);
  1399. }
  1400. static void
  1401. esas2r_firmware_event_work(struct work_struct *work)
  1402. {
  1403. struct esas2r_fw_event_work *fw_event =
  1404. container_of(work, struct esas2r_fw_event_work, work.work);
  1405. struct esas2r_adapter *a = fw_event->a;
  1406. u16 target_id = *(u16 *)&fw_event->data[0];
  1407. if (a->fw_events_off)
  1408. goto done;
  1409. switch (fw_event->type) {
  1410. case fw_event_null:
  1411. break; /* do nothing */
  1412. case fw_event_lun_change:
  1413. esas2r_remove_device(a, target_id);
  1414. esas2r_add_device(a, target_id);
  1415. break;
  1416. case fw_event_present:
  1417. esas2r_add_device(a, target_id);
  1418. break;
  1419. case fw_event_not_present:
  1420. esas2r_remove_device(a, target_id);
  1421. break;
  1422. case fw_event_vda_ae:
  1423. esas2r_send_ae_event(fw_event);
  1424. break;
  1425. }
  1426. done:
  1427. esas2r_free_fw_event(fw_event);
  1428. }
  1429. void esas2r_queue_fw_event(struct esas2r_adapter *a,
  1430. enum fw_event_type type,
  1431. void *data,
  1432. int data_sz)
  1433. {
  1434. struct esas2r_fw_event_work *fw_event;
  1435. unsigned long flags;
  1436. fw_event = kzalloc(sizeof(struct esas2r_fw_event_work), GFP_ATOMIC);
  1437. if (!fw_event) {
  1438. esas2r_log(ESAS2R_LOG_WARN,
  1439. "esas2r_queue_fw_event failed to alloc");
  1440. return;
  1441. }
  1442. if (type == fw_event_vda_ae) {
  1443. struct esas2r_vda_ae *ae =
  1444. (struct esas2r_vda_ae *)fw_event->data;
  1445. ae->signature = ESAS2R_VDA_EVENT_SIG;
  1446. ae->bus_number = a->pcid->bus->number;
  1447. ae->devfn = a->pcid->devfn;
  1448. memcpy(&ae->vda_ae, data, sizeof(ae->vda_ae));
  1449. } else {
  1450. memcpy(fw_event->data, data, data_sz);
  1451. }
  1452. fw_event->type = type;
  1453. fw_event->a = a;
  1454. spin_lock_irqsave(&a->fw_event_lock, flags);
  1455. list_add_tail(&fw_event->list, &a->fw_event_list);
  1456. INIT_DELAYED_WORK(&fw_event->work, esas2r_firmware_event_work);
  1457. queue_delayed_work_on(
  1458. smp_processor_id(), a->fw_event_q, &fw_event->work,
  1459. msecs_to_jiffies(1));
  1460. spin_unlock_irqrestore(&a->fw_event_lock, flags);
  1461. }
  1462. void esas2r_target_state_changed(struct esas2r_adapter *a, u16 targ_id,
  1463. u8 state)
  1464. {
  1465. if (state == TS_LUN_CHANGE)
  1466. esas2r_queue_fw_event(a, fw_event_lun_change, &targ_id,
  1467. sizeof(targ_id));
  1468. else if (state == TS_PRESENT)
  1469. esas2r_queue_fw_event(a, fw_event_present, &targ_id,
  1470. sizeof(targ_id));
  1471. else if (state == TS_NOT_PRESENT)
  1472. esas2r_queue_fw_event(a, fw_event_not_present, &targ_id,
  1473. sizeof(targ_id));
  1474. }
  1475. /* Translate status to a Linux SCSI mid-layer error code */
  1476. int esas2r_req_status_to_error(u8 req_stat)
  1477. {
  1478. switch (req_stat) {
  1479. case RS_OVERRUN:
  1480. case RS_UNDERRUN:
  1481. case RS_SUCCESS:
  1482. /*
  1483. * NOTE: SCSI mid-layer wants a good status for a SCSI error, because
  1484. * it will check the scsi_stat value in the completion anyway.
  1485. */
  1486. case RS_SCSI_ERROR:
  1487. return DID_OK;
  1488. case RS_SEL:
  1489. case RS_SEL2:
  1490. return DID_NO_CONNECT;
  1491. case RS_RESET:
  1492. return DID_RESET;
  1493. case RS_ABORTED:
  1494. return DID_ABORT;
  1495. case RS_BUSY:
  1496. return DID_BUS_BUSY;
  1497. }
  1498. /* everything else is just an error. */
  1499. return DID_ERROR;
  1500. }
  1501. module_init(esas2r_init);
  1502. module_exit(esas2r_exit);