aic79xx_proc.c 8.8 KB

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