aic7xxx_proc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:11k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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#19 $
  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 u_int scsi_calc_syncsrate(u_int period_factor);
  48. static void ahc_dump_target_state(struct ahc_softc *ahc,
  49.       struct info_str *info,
  50.       u_int our_id, char channel,
  51.       u_int target_id, u_int target_offset);
  52. static void ahc_dump_device_state(struct info_str *info,
  53.       struct ahc_linux_device *dev);
  54. static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
  55.        char *buffer, int length);
  56.        
  57. int
  58. ahc_acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
  59. {
  60. int wait;
  61. if ((ahc->features & AHC_SPIOCAP) != 0
  62.  && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
  63. return (0);
  64. /*
  65.  * Request access of the memory port.  When access is
  66.  * granted, SEERDY will go high.  We use a 1 second
  67.  * timeout which should be near 1 second more than
  68.  * is needed.  Reason: after the chip reset, there
  69.  * should be no contention.
  70.  */
  71. SEEPROM_OUTB(sd, sd->sd_MS);
  72. wait = 1000;  /* 1 second timeout in msec */
  73. while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
  74. ahc_delay(1000);  /* delay 1 msec */
  75. }
  76. if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
  77. SEEPROM_OUTB(sd, 0); 
  78. return (0);
  79. }
  80. return(1);
  81. }
  82. void
  83. ahc_release_seeprom(struct seeprom_descriptor *sd)
  84. {
  85. /* Release access to the memory port and the serial EEPROM. */
  86. SEEPROM_OUTB(sd, 0);
  87. }
  88. static void
  89. copy_mem_info(struct info_str *info, char *data, int len)
  90. {
  91. if (info->pos + len > info->offset + info->length)
  92. len = info->offset + info->length - info->pos;
  93. if (info->pos + len < info->offset) {
  94. info->pos += len;
  95. return;
  96. }
  97. if (info->pos < info->offset) {
  98. off_t partial;
  99. partial = info->offset - info->pos;
  100. data += partial;
  101. info->pos += partial;
  102. len  -= partial;
  103. }
  104. if (len > 0) {
  105. memcpy(info->buffer, data, len);
  106. info->pos += len;
  107. info->buffer += len;
  108. }
  109. }
  110. static int
  111. copy_info(struct info_str *info, char *fmt, ...)
  112. {
  113. va_list args;
  114. char buf[256];
  115. int len;
  116. va_start(args, fmt);
  117. len = vsprintf(buf, fmt, args);
  118. va_end(args);
  119. copy_mem_info(info, buf, len);
  120. return (len);
  121. }
  122. /*
  123.  * Table of syncrates that don't follow the "divisible by 4"
  124.  * rule. This table will be expanded in future SCSI specs.
  125.  */
  126. static struct {
  127. u_int period_factor;
  128. u_int period; /* in 10ths of ns */
  129. } scsi_syncrates[] = {
  130. { 0x09, 125 }, /* FAST-80 */
  131. { 0x0a, 250 }, /* FAST-40 40MHz */
  132. { 0x0b, 303 }, /* FAST-40 33MHz */
  133. { 0x0c, 500 } /* FAST-20 */
  134. };
  135.  
  136. /*
  137.  * Return the frequency in kHz corresponding to the given
  138.  * sync period factor.
  139.  */
  140. static u_int
  141. scsi_calc_syncsrate(u_int period_factor)
  142. {
  143. int i; 
  144. int num_syncrates;
  145.  
  146. num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
  147. /* See if the period is in the "exception" table */
  148. for (i = 0; i < num_syncrates; i++) {
  149. if (period_factor == scsi_syncrates[i].period_factor) {
  150.         /* Period in kHz */
  151. return (10000000 / scsi_syncrates[i].period);
  152. }
  153. }
  154. /*
  155.  * Wasn't in the table, so use the standard
  156.  * 4 times conversion.
  157.  */
  158. return (10000000 / (period_factor * 4 * 10));
  159. }
  160. void
  161. ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
  162. {
  163. u_int speed;
  164. u_int freq;
  165. u_int mb;
  166.         speed = 3300;
  167.         freq = 0;
  168. if (tinfo->offset != 0) {
  169. freq = scsi_calc_syncsrate(tinfo->period);
  170. speed = freq;
  171. }
  172. speed *= (0x01 << tinfo->width);
  173.         mb = speed / 1000;
  174.         if (mb > 0)
  175. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  176.         else
  177. copy_info(info, "%dKB/s transfers", speed);
  178. if (freq != 0) {
  179. copy_info(info, " (%d.%03dMHz%s, offset %d",
  180.  freq / 1000, freq % 1000,
  181.  (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
  182.  ? " DT" : "", tinfo->offset);
  183. }
  184. if (tinfo->width > 0) {
  185. if (freq != 0) {
  186. copy_info(info, ", ");
  187. } else {
  188. copy_info(info, " (");
  189. }
  190. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  191. } else if (freq != 0) {
  192. copy_info(info, ")");
  193. }
  194. copy_info(info, "n");
  195. }
  196. static void
  197. ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
  198.       u_int our_id, char channel, u_int target_id,
  199.       u_int target_offset)
  200. {
  201. struct ahc_linux_target *targ;
  202. struct ahc_initiator_tinfo *tinfo;
  203. struct ahc_tmode_tstate *tstate;
  204. int lun;
  205. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  206.     target_id, &tstate);
  207. copy_info(info, "Channel %c Target %d Negotiation Settingsn",
  208.   channel, target_id);
  209. copy_info(info, "tUser: ");
  210. ahc_format_transinfo(info, &tinfo->user);
  211. targ = ahc->platform_data->targets[target_offset];
  212. if (targ == NULL)
  213. return;
  214. copy_info(info, "tGoal: ");
  215. ahc_format_transinfo(info, &tinfo->goal);
  216. copy_info(info, "tCurr: ");
  217. ahc_format_transinfo(info, &tinfo->curr);
  218. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  219. struct ahc_linux_device *dev;
  220. dev = targ->devices[lun];
  221. if (dev == NULL)
  222. continue;
  223. ahc_dump_device_state(info, dev);
  224. }
  225. }
  226. static void
  227. ahc_dump_device_state(struct info_str *info, struct ahc_linux_device *dev)
  228. {
  229. copy_info(info, "tChannel %c Target %d Lun %d Settingsn",
  230.   dev->target->channel + 'A', dev->target->target, dev->lun);
  231. copy_info(info, "ttCommands Queued %ldn", dev->commands_issued);
  232. copy_info(info, "ttCommands Active %dn", dev->active);
  233. copy_info(info, "ttCommand Openings %dn", dev->openings);
  234. copy_info(info, "ttMax Tagged Openings %dn", dev->maxtags);
  235. copy_info(info, "ttDevice Queue Frozen Count %dn", dev->qfrozen);
  236. }
  237. static int
  238. ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
  239. {
  240. struct seeprom_descriptor sd;
  241. int have_seeprom;
  242. u_long s;
  243. int paused;
  244. int written;
  245. /* Default to failure. */
  246. written = -EINVAL;
  247. ahc_lock(ahc, &s);
  248. paused = ahc_is_paused(ahc);
  249. if (!paused)
  250. ahc_pause(ahc);
  251. if (length != sizeof(struct seeprom_config)) {
  252. printf("ahc_proc_write_seeprom: incorrect buffer sizen");
  253. goto done;
  254. }
  255. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  256. if (have_seeprom == 0) {
  257. printf("ahc_proc_write_seeprom: cksum verification failedn");
  258. goto done;
  259. }
  260. sd.sd_ahc = ahc;
  261. if ((ahc->chip & AHC_VL) != 0) {
  262. sd.sd_control_offset = SEECTL_2840;
  263. sd.sd_status_offset = STATUS_2840;
  264. sd.sd_dataout_offset = STATUS_2840;
  265. sd.sd_chip = C46;
  266. sd.sd_MS = 0;
  267. sd.sd_RDY = EEPROM_TF;
  268. sd.sd_CS = CS_2840;
  269. sd.sd_CK = CK_2840;
  270. sd.sd_DO = DO_2840;
  271. sd.sd_DI = DI_2840;
  272. have_seeprom = TRUE;
  273. } else {
  274. sd.sd_control_offset = SEECTL;
  275. sd.sd_status_offset = SEECTL;
  276. sd.sd_dataout_offset = SEECTL;
  277. if (ahc->flags & AHC_LARGE_SEEPROM)
  278. sd.sd_chip = C56_66;
  279. else
  280. sd.sd_chip = C46;
  281. sd.sd_MS = SEEMS;
  282. sd.sd_RDY = SEERDY;
  283. sd.sd_CS = SEECS;
  284. sd.sd_CK = SEECK;
  285. sd.sd_DO = SEEDO;
  286. sd.sd_DI = SEEDI;
  287. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  288. }
  289. if (!have_seeprom) {
  290. printf("ahc_proc_write_seeprom: No Serial EEPROMn");
  291. goto done;
  292. } else {
  293. u_int start_addr;
  294. if (ahc->seep_config == NULL) {
  295. ahc->seep_config = malloc(sizeof(*ahc->seep_config),
  296.   M_DEVBUF, M_NOWAIT);
  297. if (ahc->seep_config == NULL) {
  298. printf("aic7xxx: Unable to allocate serial "
  299.        "eeprom buffer.  Write failingn");
  300. goto done;
  301. }
  302. }
  303. printf("aic7xxx: Writing Serial EEPROMn");
  304. start_addr = 32 * (ahc->channel - 'A');
  305. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  306.   sizeof(struct seeprom_config)/2);
  307. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  308.  start_addr, sizeof(struct seeprom_config)/2);
  309. if ((ahc->chip & AHC_VL) == 0)
  310. ahc_release_seeprom(&sd);
  311. written = length;
  312. }
  313. done:
  314. if (!paused)
  315. ahc_unpause(ahc);
  316. ahc_unlock(ahc, &s);
  317. return (written);
  318. }
  319. /*
  320.  * Return information to handle /proc support for the driver.
  321.  */
  322. int
  323. ahc_linux_proc_info(char *buffer, char **start, off_t offset,
  324.   int length, int hostno, int inout)
  325. {
  326. struct ahc_softc *ahc;
  327. struct info_str info;
  328. char ahc_info[256];
  329. u_long s;
  330. u_int max_targ;
  331. u_int i;
  332. int retval;
  333. retval = -EINVAL;
  334. ahc_list_lock(&s);
  335. TAILQ_FOREACH(ahc, &ahc_tailq, links) {
  336. if (ahc->platform_data->host->host_no == hostno)
  337. break;
  338. }
  339. if (ahc == NULL)
  340. goto done;
  341.  /* Has data been written to the file? */ 
  342. if (inout == TRUE) {
  343. retval = ahc_proc_write_seeprom(ahc, buffer, length);
  344. goto done;
  345. }
  346. if (start)
  347. *start = buffer;
  348. info.buffer = buffer;
  349. info.length = length;
  350. info.offset = offset;
  351. info.pos = 0;
  352. copy_info(&info, "Adaptec AIC7xxx driver version: %sn",
  353.   AIC7XXX_DRIVER_VERSION);
  354. ahc_controller_info(ahc, ahc_info);
  355. copy_info(&info, "%snn", ahc_info);
  356. if (ahc->seep_config == NULL)
  357. copy_info(&info, "No Serial EEPROMn");
  358. else {
  359. copy_info(&info, "Serial EEPROM:n");
  360. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  361. if (((i % 8) == 0) && (i != 0)) {
  362. copy_info(&info, "n");
  363. }
  364. copy_info(&info, "0x%.4x ",
  365.   ((uint16_t*)ahc->seep_config)[i]);
  366. }
  367. copy_info(&info, "n");
  368. }
  369. copy_info(&info, "n");
  370. max_targ = 15;
  371. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  372. max_targ = 7;
  373. for (i = 0; i <= max_targ; i++) {
  374. u_int our_id;
  375. u_int target_id;
  376. char channel;
  377. channel = 'A';
  378. our_id = ahc->our_id;
  379. target_id = i;
  380. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  381. channel = 'B';
  382. our_id = ahc->our_id_b;
  383. target_id = i % 8;
  384. }
  385. ahc_dump_target_state(ahc, &info, our_id,
  386.       channel, target_id, i);
  387. }
  388. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  389. done:
  390. ahc_list_unlock(&s);
  391. return (retval);
  392. }