aic79xx_proc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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/aic79xx_proc.c#19 $
  41. */
  42. #include "aic79xx_osm.h"
  43. #include "aic79xx_inline.h"
  44. static void copy_mem_info(struct info_str *info, char *data, int len);
  45. static int copy_info(struct info_str *info, char *fmt, ...);
  46. static void ahd_dump_target_state(struct ahd_softc *ahd,
  47. struct info_str *info,
  48. u_int our_id, char channel,
  49. u_int target_id);
  50. static void ahd_dump_device_state(struct info_str *info,
  51. struct scsi_device *sdev);
  52. static int ahd_proc_write_seeprom(struct ahd_softc *ahd,
  53. char *buffer, int length);
  54. /*
  55. * Table of syncrates that don't follow the "divisible by 4"
  56. * rule. This table will be expanded in future SCSI specs.
  57. */
  58. static const struct {
  59. u_int period_factor;
  60. u_int period; /* in 100ths of ns */
  61. } scsi_syncrates[] = {
  62. { 0x08, 625 }, /* FAST-160 */
  63. { 0x09, 1250 }, /* FAST-80 */
  64. { 0x0a, 2500 }, /* FAST-40 40MHz */
  65. { 0x0b, 3030 }, /* FAST-40 33MHz */
  66. { 0x0c, 5000 } /* FAST-20 */
  67. };
  68. /*
  69. * Return the frequency in kHz corresponding to the given
  70. * sync period factor.
  71. */
  72. static u_int
  73. ahd_calc_syncsrate(u_int period_factor)
  74. {
  75. int i;
  76. /* See if the period is in the "exception" table */
  77. for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
  78. if (period_factor == scsi_syncrates[i].period_factor) {
  79. /* Period in kHz */
  80. return (100000000 / scsi_syncrates[i].period);
  81. }
  82. }
  83. /*
  84. * Wasn't in the table, so use the standard
  85. * 4 times conversion.
  86. */
  87. return (10000000 / (period_factor * 4 * 10));
  88. }
  89. static void
  90. copy_mem_info(struct info_str *info, char *data, int len)
  91. {
  92. if (info->pos + len > info->offset + info->length)
  93. len = info->offset + info->length - info->pos;
  94. if (info->pos + len < info->offset) {
  95. info->pos += len;
  96. return;
  97. }
  98. if (info->pos < info->offset) {
  99. off_t partial;
  100. partial = info->offset - info->pos;
  101. data += partial;
  102. info->pos += partial;
  103. len -= partial;
  104. }
  105. if (len > 0) {
  106. memcpy(info->buffer, data, len);
  107. info->pos += len;
  108. info->buffer += len;
  109. }
  110. }
  111. static int
  112. copy_info(struct info_str *info, char *fmt, ...)
  113. {
  114. va_list args;
  115. char buf[256];
  116. int len;
  117. va_start(args, fmt);
  118. len = vsprintf(buf, fmt, args);
  119. va_end(args);
  120. copy_mem_info(info, buf, len);
  121. return (len);
  122. }
  123. static void
  124. ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
  125. {
  126. u_int speed;
  127. u_int freq;
  128. u_int mb;
  129. if (tinfo->period == AHD_PERIOD_UNKNOWN) {
  130. copy_info(info, "Renegotiation Pending\n");
  131. return;
  132. }
  133. speed = 3300;
  134. freq = 0;
  135. if (tinfo->offset != 0) {
  136. freq = ahd_calc_syncsrate(tinfo->period);
  137. speed = freq;
  138. }
  139. speed *= (0x01 << tinfo->width);
  140. mb = speed / 1000;
  141. if (mb > 0)
  142. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  143. else
  144. copy_info(info, "%dKB/s transfers", speed);
  145. if (freq != 0) {
  146. int printed_options;
  147. printed_options = 0;
  148. copy_info(info, " (%d.%03dMHz", freq / 1000, freq % 1000);
  149. if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
  150. copy_info(info, " RDSTRM");
  151. printed_options++;
  152. }
  153. if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
  154. copy_info(info, "%s", printed_options ? "|DT" : " DT");
  155. printed_options++;
  156. }
  157. if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  158. copy_info(info, "%s", printed_options ? "|IU" : " IU");
  159. printed_options++;
  160. }
  161. if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
  162. copy_info(info, "%s",
  163. printed_options ? "|RTI" : " RTI");
  164. printed_options++;
  165. }
  166. if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
  167. copy_info(info, "%s",
  168. printed_options ? "|QAS" : " QAS");
  169. printed_options++;
  170. }
  171. }
  172. if (tinfo->width > 0) {
  173. if (freq != 0) {
  174. copy_info(info, ", ");
  175. } else {
  176. copy_info(info, " (");
  177. }
  178. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  179. } else if (freq != 0) {
  180. copy_info(info, ")");
  181. }
  182. copy_info(info, "\n");
  183. }
  184. static void
  185. ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
  186. u_int our_id, char channel, u_int target_id)
  187. {
  188. struct scsi_target *starget;
  189. struct ahd_initiator_tinfo *tinfo;
  190. struct ahd_tmode_tstate *tstate;
  191. int lun;
  192. tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
  193. target_id, &tstate);
  194. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  195. copy_info(info, "\tUser: ");
  196. ahd_format_transinfo(info, &tinfo->user);
  197. starget = ahd->platform_data->starget[target_id];
  198. if (starget == NULL)
  199. return;
  200. copy_info(info, "\tGoal: ");
  201. ahd_format_transinfo(info, &tinfo->goal);
  202. copy_info(info, "\tCurr: ");
  203. ahd_format_transinfo(info, &tinfo->curr);
  204. for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
  205. struct scsi_device *dev;
  206. dev = scsi_device_lookup_by_target(starget, lun);
  207. if (dev == NULL)
  208. continue;
  209. ahd_dump_device_state(info, dev);
  210. }
  211. }
  212. static void
  213. ahd_dump_device_state(struct info_str *info, struct scsi_device *sdev)
  214. {
  215. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  216. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  217. sdev->sdev_target->channel + 'A',
  218. sdev->sdev_target->id, sdev->lun);
  219. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  220. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  221. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  222. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  223. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  224. }
  225. static int
  226. ahd_proc_write_seeprom(struct ahd_softc *ahd, char *buffer, int length)
  227. {
  228. ahd_mode_state saved_modes;
  229. int have_seeprom;
  230. u_long s;
  231. int paused;
  232. int written;
  233. /* Default to failure. */
  234. written = -EINVAL;
  235. ahd_lock(ahd, &s);
  236. paused = ahd_is_paused(ahd);
  237. if (!paused)
  238. ahd_pause(ahd);
  239. saved_modes = ahd_save_modes(ahd);
  240. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  241. if (length != sizeof(struct seeprom_config)) {
  242. printk("ahd_proc_write_seeprom: incorrect buffer size\n");
  243. goto done;
  244. }
  245. have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
  246. if (have_seeprom == 0) {
  247. printk("ahd_proc_write_seeprom: cksum verification failed\n");
  248. goto done;
  249. }
  250. have_seeprom = ahd_acquire_seeprom(ahd);
  251. if (!have_seeprom) {
  252. printk("ahd_proc_write_seeprom: No Serial EEPROM\n");
  253. goto done;
  254. } else {
  255. u_int start_addr;
  256. if (ahd->seep_config == NULL) {
  257. ahd->seep_config = kmalloc(sizeof(*ahd->seep_config), GFP_ATOMIC);
  258. if (ahd->seep_config == NULL) {
  259. printk("aic79xx: Unable to allocate serial "
  260. "eeprom buffer. Write failing\n");
  261. goto done;
  262. }
  263. }
  264. printk("aic79xx: Writing Serial EEPROM\n");
  265. start_addr = 32 * (ahd->channel - 'A');
  266. ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
  267. sizeof(struct seeprom_config)/2);
  268. ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
  269. start_addr, sizeof(struct seeprom_config)/2,
  270. /*ByteStream*/FALSE);
  271. ahd_release_seeprom(ahd);
  272. written = length;
  273. }
  274. done:
  275. ahd_restore_modes(ahd, saved_modes);
  276. if (!paused)
  277. ahd_unpause(ahd);
  278. ahd_unlock(ahd, &s);
  279. return (written);
  280. }
  281. /*
  282. * Return information to handle /proc support for the driver.
  283. */
  284. int
  285. ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  286. off_t offset, int length, int inout)
  287. {
  288. struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
  289. struct info_str info;
  290. char ahd_info[256];
  291. u_int max_targ;
  292. u_int i;
  293. int retval;
  294. /* Has data been written to the file? */
  295. if (inout == TRUE) {
  296. retval = ahd_proc_write_seeprom(ahd, buffer, length);
  297. goto done;
  298. }
  299. if (start)
  300. *start = buffer;
  301. info.buffer = buffer;
  302. info.length = length;
  303. info.offset = offset;
  304. info.pos = 0;
  305. copy_info(&info, "Adaptec AIC79xx driver version: %s\n",
  306. AIC79XX_DRIVER_VERSION);
  307. copy_info(&info, "%s\n", ahd->description);
  308. ahd_controller_info(ahd, ahd_info);
  309. copy_info(&info, "%s\n", ahd_info);
  310. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  311. ahd->scb_data.numscbs, AHD_NSEG);
  312. max_targ = 16;
  313. if (ahd->seep_config == NULL)
  314. copy_info(&info, "No Serial EEPROM\n");
  315. else {
  316. copy_info(&info, "Serial EEPROM:\n");
  317. for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
  318. if (((i % 8) == 0) && (i != 0)) {
  319. copy_info(&info, "\n");
  320. }
  321. copy_info(&info, "0x%.4x ",
  322. ((uint16_t*)ahd->seep_config)[i]);
  323. }
  324. copy_info(&info, "\n");
  325. }
  326. copy_info(&info, "\n");
  327. if ((ahd->features & AHD_WIDE) == 0)
  328. max_targ = 8;
  329. for (i = 0; i < max_targ; i++) {
  330. ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
  331. /*target_id*/i);
  332. }
  333. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  334. done:
  335. return (retval);
  336. }