aic7xxx_proc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * Copyright (c) 2000-2001 Adaptec Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions, and the following disclaimer,
  10. * without modification.
  11. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  12. * substantially similar to the "NO WARRANTY" disclaimer below
  13. * ("Disclaimer") and any redistribution must be conditioned upon
  14. * including a substantially similar Disclaimer requirement for further
  15. * binary redistribution.
  16. * 3. Neither the names of the above-listed copyright holders nor the names
  17. * of any contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * NO WARRANTY
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  34. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGES.
  36. *
  37. * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
  38. * sym driver.
  39. *
  40. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#29 $
  41. */
  42. #include "aic7xxx_osm.h"
  43. #include "aic7xxx_inline.h"
  44. #include "aic7xxx_93cx6.h"
  45. static void copy_mem_info(struct info_str *info, char *data, int len);
  46. static int copy_info(struct info_str *info, char *fmt, ...);
  47. static void ahc_dump_target_state(struct ahc_softc *ahc,
  48. struct info_str *info,
  49. u_int our_id, char channel,
  50. u_int target_id, u_int target_offset);
  51. static void ahc_dump_device_state(struct info_str *info,
  52. struct scsi_device *dev);
  53. static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
  54. char *buffer, int length);
  55. /*
  56. * Table of syncrates that don't follow the "divisible by 4"
  57. * rule. This table will be expanded in future SCSI specs.
  58. */
  59. static const struct {
  60. u_int period_factor;
  61. u_int period; /* in 100ths of ns */
  62. } scsi_syncrates[] = {
  63. { 0x08, 625 }, /* FAST-160 */
  64. { 0x09, 1250 }, /* FAST-80 */
  65. { 0x0a, 2500 }, /* FAST-40 40MHz */
  66. { 0x0b, 3030 }, /* FAST-40 33MHz */
  67. { 0x0c, 5000 } /* FAST-20 */
  68. };
  69. /*
  70. * Return the frequency in kHz corresponding to the given
  71. * sync period factor.
  72. */
  73. static u_int
  74. ahc_calc_syncsrate(u_int period_factor)
  75. {
  76. int i;
  77. /* See if the period is in the "exception" table */
  78. for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
  79. if (period_factor == scsi_syncrates[i].period_factor) {
  80. /* Period in kHz */
  81. return (100000000 / scsi_syncrates[i].period);
  82. }
  83. }
  84. /*
  85. * Wasn't in the table, so use the standard
  86. * 4 times conversion.
  87. */
  88. return (10000000 / (period_factor * 4 * 10));
  89. }
  90. static void
  91. copy_mem_info(struct info_str *info, char *data, int len)
  92. {
  93. if (info->pos + len > info->offset + info->length)
  94. len = info->offset + info->length - info->pos;
  95. if (info->pos + len < info->offset) {
  96. info->pos += len;
  97. return;
  98. }
  99. if (info->pos < info->offset) {
  100. off_t partial;
  101. partial = info->offset - info->pos;
  102. data += partial;
  103. info->pos += partial;
  104. len -= partial;
  105. }
  106. if (len > 0) {
  107. memcpy(info->buffer, data, len);
  108. info->pos += len;
  109. info->buffer += len;
  110. }
  111. }
  112. static int
  113. copy_info(struct info_str *info, char *fmt, ...)
  114. {
  115. va_list args;
  116. char buf[256];
  117. int len;
  118. va_start(args, fmt);
  119. len = vsprintf(buf, fmt, args);
  120. va_end(args);
  121. copy_mem_info(info, buf, len);
  122. return (len);
  123. }
  124. static void
  125. ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
  126. {
  127. u_int speed;
  128. u_int freq;
  129. u_int mb;
  130. speed = 3300;
  131. freq = 0;
  132. if (tinfo->offset != 0) {
  133. freq = ahc_calc_syncsrate(tinfo->period);
  134. speed = freq;
  135. }
  136. speed *= (0x01 << tinfo->width);
  137. mb = speed / 1000;
  138. if (mb > 0)
  139. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  140. else
  141. copy_info(info, "%dKB/s transfers", speed);
  142. if (freq != 0) {
  143. copy_info(info, " (%d.%03dMHz%s, offset %d",
  144. freq / 1000, freq % 1000,
  145. (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
  146. ? " DT" : "", tinfo->offset);
  147. }
  148. if (tinfo->width > 0) {
  149. if (freq != 0) {
  150. copy_info(info, ", ");
  151. } else {
  152. copy_info(info, " (");
  153. }
  154. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  155. } else if (freq != 0) {
  156. copy_info(info, ")");
  157. }
  158. copy_info(info, "\n");
  159. }
  160. static void
  161. ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
  162. u_int our_id, char channel, u_int target_id,
  163. u_int target_offset)
  164. {
  165. struct scsi_target *starget;
  166. struct ahc_initiator_tinfo *tinfo;
  167. struct ahc_tmode_tstate *tstate;
  168. int lun;
  169. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  170. target_id, &tstate);
  171. if ((ahc->features & AHC_TWIN) != 0)
  172. copy_info(info, "Channel %c ", channel);
  173. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  174. copy_info(info, "\tUser: ");
  175. ahc_format_transinfo(info, &tinfo->user);
  176. starget = ahc->platform_data->starget[target_offset];
  177. if (!starget)
  178. return;
  179. copy_info(info, "\tGoal: ");
  180. ahc_format_transinfo(info, &tinfo->goal);
  181. copy_info(info, "\tCurr: ");
  182. ahc_format_transinfo(info, &tinfo->curr);
  183. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  184. struct scsi_device *sdev;
  185. sdev = scsi_device_lookup_by_target(starget, lun);
  186. if (sdev == NULL)
  187. continue;
  188. ahc_dump_device_state(info, sdev);
  189. }
  190. }
  191. static void
  192. ahc_dump_device_state(struct info_str *info, struct scsi_device *sdev)
  193. {
  194. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  195. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  196. sdev->sdev_target->channel + 'A',
  197. sdev->sdev_target->id, sdev->lun);
  198. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  199. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  200. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  201. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  202. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  203. }
  204. static int
  205. ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
  206. {
  207. struct seeprom_descriptor sd;
  208. int have_seeprom;
  209. u_long s;
  210. int paused;
  211. int written;
  212. /* Default to failure. */
  213. written = -EINVAL;
  214. ahc_lock(ahc, &s);
  215. paused = ahc_is_paused(ahc);
  216. if (!paused)
  217. ahc_pause(ahc);
  218. if (length != sizeof(struct seeprom_config)) {
  219. printk("ahc_proc_write_seeprom: incorrect buffer size\n");
  220. goto done;
  221. }
  222. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  223. if (have_seeprom == 0) {
  224. printk("ahc_proc_write_seeprom: cksum verification failed\n");
  225. goto done;
  226. }
  227. sd.sd_ahc = ahc;
  228. #if AHC_PCI_CONFIG > 0
  229. if ((ahc->chip & AHC_PCI) != 0) {
  230. sd.sd_control_offset = SEECTL;
  231. sd.sd_status_offset = SEECTL;
  232. sd.sd_dataout_offset = SEECTL;
  233. if (ahc->flags & AHC_LARGE_SEEPROM)
  234. sd.sd_chip = C56_66;
  235. else
  236. sd.sd_chip = C46;
  237. sd.sd_MS = SEEMS;
  238. sd.sd_RDY = SEERDY;
  239. sd.sd_CS = SEECS;
  240. sd.sd_CK = SEECK;
  241. sd.sd_DO = SEEDO;
  242. sd.sd_DI = SEEDI;
  243. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  244. } else
  245. #endif
  246. if ((ahc->chip & AHC_VL) != 0) {
  247. sd.sd_control_offset = SEECTL_2840;
  248. sd.sd_status_offset = STATUS_2840;
  249. sd.sd_dataout_offset = STATUS_2840;
  250. sd.sd_chip = C46;
  251. sd.sd_MS = 0;
  252. sd.sd_RDY = EEPROM_TF;
  253. sd.sd_CS = CS_2840;
  254. sd.sd_CK = CK_2840;
  255. sd.sd_DO = DO_2840;
  256. sd.sd_DI = DI_2840;
  257. have_seeprom = TRUE;
  258. } else {
  259. printk("ahc_proc_write_seeprom: unsupported adapter type\n");
  260. goto done;
  261. }
  262. if (!have_seeprom) {
  263. printk("ahc_proc_write_seeprom: No Serial EEPROM\n");
  264. goto done;
  265. } else {
  266. u_int start_addr;
  267. if (ahc->seep_config == NULL) {
  268. ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC);
  269. if (ahc->seep_config == NULL) {
  270. printk("aic7xxx: Unable to allocate serial "
  271. "eeprom buffer. Write failing\n");
  272. goto done;
  273. }
  274. }
  275. printk("aic7xxx: Writing Serial EEPROM\n");
  276. start_addr = 32 * (ahc->channel - 'A');
  277. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  278. sizeof(struct seeprom_config)/2);
  279. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  280. start_addr, sizeof(struct seeprom_config)/2);
  281. #if AHC_PCI_CONFIG > 0
  282. if ((ahc->chip & AHC_VL) == 0)
  283. ahc_release_seeprom(&sd);
  284. #endif
  285. written = length;
  286. }
  287. done:
  288. if (!paused)
  289. ahc_unpause(ahc);
  290. ahc_unlock(ahc, &s);
  291. return (written);
  292. }
  293. /*
  294. * Return information to handle /proc support for the driver.
  295. */
  296. int
  297. ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  298. off_t offset, int length, int inout)
  299. {
  300. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  301. struct info_str info;
  302. char ahc_info[256];
  303. u_int max_targ;
  304. u_int i;
  305. int retval;
  306. /* Has data been written to the file? */
  307. if (inout == TRUE) {
  308. retval = ahc_proc_write_seeprom(ahc, buffer, length);
  309. goto done;
  310. }
  311. if (start)
  312. *start = buffer;
  313. info.buffer = buffer;
  314. info.length = length;
  315. info.offset = offset;
  316. info.pos = 0;
  317. copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
  318. AIC7XXX_DRIVER_VERSION);
  319. copy_info(&info, "%s\n", ahc->description);
  320. ahc_controller_info(ahc, ahc_info);
  321. copy_info(&info, "%s\n", ahc_info);
  322. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  323. ahc->scb_data->numscbs, AHC_NSEG);
  324. if (ahc->seep_config == NULL)
  325. copy_info(&info, "No Serial EEPROM\n");
  326. else {
  327. copy_info(&info, "Serial EEPROM:\n");
  328. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  329. if (((i % 8) == 0) && (i != 0)) {
  330. copy_info(&info, "\n");
  331. }
  332. copy_info(&info, "0x%.4x ",
  333. ((uint16_t*)ahc->seep_config)[i]);
  334. }
  335. copy_info(&info, "\n");
  336. }
  337. copy_info(&info, "\n");
  338. max_targ = 16;
  339. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  340. max_targ = 8;
  341. for (i = 0; i < max_targ; i++) {
  342. u_int our_id;
  343. u_int target_id;
  344. char channel;
  345. channel = 'A';
  346. our_id = ahc->our_id;
  347. target_id = i;
  348. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  349. channel = 'B';
  350. our_id = ahc->our_id_b;
  351. target_id = i % 8;
  352. }
  353. ahc_dump_target_state(ahc, &info, our_id,
  354. channel, target_id, i);
  355. }
  356. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  357. done:
  358. return (retval);
  359. }