aic7xxx_proc.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 ahc_dump_target_state(struct ahc_softc *ahc,
  46. struct seq_file *m,
  47. u_int our_id, char channel,
  48. u_int target_id, u_int target_offset);
  49. static void ahc_dump_device_state(struct seq_file *m,
  50. struct scsi_device *dev);
  51. /*
  52. * Table of syncrates that don't follow the "divisible by 4"
  53. * rule. This table will be expanded in future SCSI specs.
  54. */
  55. static const struct {
  56. u_int period_factor;
  57. u_int period; /* in 100ths of ns */
  58. } scsi_syncrates[] = {
  59. { 0x08, 625 }, /* FAST-160 */
  60. { 0x09, 1250 }, /* FAST-80 */
  61. { 0x0a, 2500 }, /* FAST-40 40MHz */
  62. { 0x0b, 3030 }, /* FAST-40 33MHz */
  63. { 0x0c, 5000 } /* FAST-20 */
  64. };
  65. /*
  66. * Return the frequency in kHz corresponding to the given
  67. * sync period factor.
  68. */
  69. static u_int
  70. ahc_calc_syncsrate(u_int period_factor)
  71. {
  72. int i;
  73. /* See if the period is in the "exception" table */
  74. for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
  75. if (period_factor == scsi_syncrates[i].period_factor) {
  76. /* Period in kHz */
  77. return (100000000 / scsi_syncrates[i].period);
  78. }
  79. }
  80. /*
  81. * Wasn't in the table, so use the standard
  82. * 4 times conversion.
  83. */
  84. return (10000000 / (period_factor * 4 * 10));
  85. }
  86. static void
  87. ahc_format_transinfo(struct seq_file *m, struct ahc_transinfo *tinfo)
  88. {
  89. u_int speed;
  90. u_int freq;
  91. u_int mb;
  92. speed = 3300;
  93. freq = 0;
  94. if (tinfo->offset != 0) {
  95. freq = ahc_calc_syncsrate(tinfo->period);
  96. speed = freq;
  97. }
  98. speed *= (0x01 << tinfo->width);
  99. mb = speed / 1000;
  100. if (mb > 0)
  101. seq_printf(m, "%d.%03dMB/s transfers", mb, speed % 1000);
  102. else
  103. seq_printf(m, "%dKB/s transfers", speed);
  104. if (freq != 0) {
  105. seq_printf(m, " (%d.%03dMHz%s, offset %d",
  106. freq / 1000, freq % 1000,
  107. (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
  108. ? " DT" : "", tinfo->offset);
  109. }
  110. if (tinfo->width > 0) {
  111. if (freq != 0) {
  112. seq_puts(m, ", ");
  113. } else {
  114. seq_puts(m, " (");
  115. }
  116. seq_printf(m, "%dbit)", 8 * (0x01 << tinfo->width));
  117. } else if (freq != 0) {
  118. seq_putc(m, ')');
  119. }
  120. seq_putc(m, '\n');
  121. }
  122. static void
  123. ahc_dump_target_state(struct ahc_softc *ahc, struct seq_file *m,
  124. u_int our_id, char channel, u_int target_id,
  125. u_int target_offset)
  126. {
  127. struct scsi_target *starget;
  128. struct ahc_initiator_tinfo *tinfo;
  129. struct ahc_tmode_tstate *tstate;
  130. int lun;
  131. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  132. target_id, &tstate);
  133. if ((ahc->features & AHC_TWIN) != 0)
  134. seq_printf(m, "Channel %c ", channel);
  135. seq_printf(m, "Target %d Negotiation Settings\n", target_id);
  136. seq_puts(m, "\tUser: ");
  137. ahc_format_transinfo(m, &tinfo->user);
  138. starget = ahc->platform_data->starget[target_offset];
  139. if (!starget)
  140. return;
  141. seq_puts(m, "\tGoal: ");
  142. ahc_format_transinfo(m, &tinfo->goal);
  143. seq_puts(m, "\tCurr: ");
  144. ahc_format_transinfo(m, &tinfo->curr);
  145. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  146. struct scsi_device *sdev;
  147. sdev = scsi_device_lookup_by_target(starget, lun);
  148. if (sdev == NULL)
  149. continue;
  150. ahc_dump_device_state(m, sdev);
  151. }
  152. }
  153. static void
  154. ahc_dump_device_state(struct seq_file *m, struct scsi_device *sdev)
  155. {
  156. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  157. seq_printf(m, "\tChannel %c Target %d Lun %d Settings\n",
  158. sdev->sdev_target->channel + 'A',
  159. sdev->sdev_target->id, (u8)sdev->lun);
  160. seq_printf(m, "\t\tCommands Queued %ld\n", dev->commands_issued);
  161. seq_printf(m, "\t\tCommands Active %d\n", dev->active);
  162. seq_printf(m, "\t\tCommand Openings %d\n", dev->openings);
  163. seq_printf(m, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  164. seq_printf(m, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  165. }
  166. int
  167. ahc_proc_write_seeprom(struct Scsi_Host *shost, char *buffer, int length)
  168. {
  169. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  170. struct seeprom_descriptor sd;
  171. int have_seeprom;
  172. u_long s;
  173. int paused;
  174. int written;
  175. /* Default to failure. */
  176. written = -EINVAL;
  177. ahc_lock(ahc, &s);
  178. paused = ahc_is_paused(ahc);
  179. if (!paused)
  180. ahc_pause(ahc);
  181. if (length != sizeof(struct seeprom_config)) {
  182. printk("ahc_proc_write_seeprom: incorrect buffer size\n");
  183. goto done;
  184. }
  185. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  186. if (have_seeprom == 0) {
  187. printk("ahc_proc_write_seeprom: cksum verification failed\n");
  188. goto done;
  189. }
  190. sd.sd_ahc = ahc;
  191. #if AHC_PCI_CONFIG > 0
  192. if ((ahc->chip & AHC_PCI) != 0) {
  193. sd.sd_control_offset = SEECTL;
  194. sd.sd_status_offset = SEECTL;
  195. sd.sd_dataout_offset = SEECTL;
  196. if (ahc->flags & AHC_LARGE_SEEPROM)
  197. sd.sd_chip = C56_66;
  198. else
  199. sd.sd_chip = C46;
  200. sd.sd_MS = SEEMS;
  201. sd.sd_RDY = SEERDY;
  202. sd.sd_CS = SEECS;
  203. sd.sd_CK = SEECK;
  204. sd.sd_DO = SEEDO;
  205. sd.sd_DI = SEEDI;
  206. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  207. } else
  208. #endif
  209. if ((ahc->chip & AHC_VL) != 0) {
  210. sd.sd_control_offset = SEECTL_2840;
  211. sd.sd_status_offset = STATUS_2840;
  212. sd.sd_dataout_offset = STATUS_2840;
  213. sd.sd_chip = C46;
  214. sd.sd_MS = 0;
  215. sd.sd_RDY = EEPROM_TF;
  216. sd.sd_CS = CS_2840;
  217. sd.sd_CK = CK_2840;
  218. sd.sd_DO = DO_2840;
  219. sd.sd_DI = DI_2840;
  220. have_seeprom = TRUE;
  221. } else {
  222. printk("ahc_proc_write_seeprom: unsupported adapter type\n");
  223. goto done;
  224. }
  225. if (!have_seeprom) {
  226. printk("ahc_proc_write_seeprom: No Serial EEPROM\n");
  227. goto done;
  228. } else {
  229. u_int start_addr;
  230. if (ahc->seep_config == NULL) {
  231. ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC);
  232. if (ahc->seep_config == NULL) {
  233. printk("aic7xxx: Unable to allocate serial "
  234. "eeprom buffer. Write failing\n");
  235. goto done;
  236. }
  237. }
  238. printk("aic7xxx: Writing Serial EEPROM\n");
  239. start_addr = 32 * (ahc->channel - 'A');
  240. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  241. sizeof(struct seeprom_config)/2);
  242. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  243. start_addr, sizeof(struct seeprom_config)/2);
  244. #if AHC_PCI_CONFIG > 0
  245. if ((ahc->chip & AHC_VL) == 0)
  246. ahc_release_seeprom(&sd);
  247. #endif
  248. written = length;
  249. }
  250. done:
  251. if (!paused)
  252. ahc_unpause(ahc);
  253. ahc_unlock(ahc, &s);
  254. return (written);
  255. }
  256. /*
  257. * Return information to handle /proc support for the driver.
  258. */
  259. int
  260. ahc_linux_show_info(struct seq_file *m, struct Scsi_Host *shost)
  261. {
  262. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  263. char ahc_info[256];
  264. u_int max_targ;
  265. u_int i;
  266. seq_printf(m, "Adaptec AIC7xxx driver version: %s\n",
  267. AIC7XXX_DRIVER_VERSION);
  268. seq_printf(m, "%s\n", ahc->description);
  269. ahc_controller_info(ahc, ahc_info);
  270. seq_printf(m, "%s\n", ahc_info);
  271. seq_printf(m, "Allocated SCBs: %d, SG List Length: %d\n\n",
  272. ahc->scb_data->numscbs, AHC_NSEG);
  273. if (ahc->seep_config == NULL)
  274. seq_puts(m, "No Serial EEPROM\n");
  275. else {
  276. seq_puts(m, "Serial EEPROM:\n");
  277. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  278. if (((i % 8) == 0) && (i != 0)) {
  279. seq_putc(m, '\n');
  280. }
  281. seq_printf(m, "0x%.4x ",
  282. ((uint16_t*)ahc->seep_config)[i]);
  283. }
  284. seq_putc(m, '\n');
  285. }
  286. seq_putc(m, '\n');
  287. max_targ = 16;
  288. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  289. max_targ = 8;
  290. for (i = 0; i < max_targ; i++) {
  291. u_int our_id;
  292. u_int target_id;
  293. char channel;
  294. channel = 'A';
  295. our_id = ahc->our_id;
  296. target_id = i;
  297. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  298. channel = 'B';
  299. our_id = ahc->our_id_b;
  300. target_id = i % 8;
  301. }
  302. ahc_dump_target_state(ahc, m, our_id,
  303. channel, target_id, i);
  304. }
  305. return 0;
  306. }